Skip to content

Commit adb014e

Browse files
committed
Implement W3C WebAuthentication specification
spec: https://www.w3.org/TR/webauthn-1/
1 parent f5859e9 commit adb014e

File tree

121 files changed

+9165
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+9165
-0
lines changed

gradle/dependency-management.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ dependencyManagement {
1919
dependencies {
2020
dependency 'cglib:cglib-nodep:3.2.12'
2121
dependency 'com.squareup.okhttp3:mockwebserver:3.14.2'
22+
dependency 'com.webauthn4j:webauthn4j-test:0.9.7.RELEASE'
2223
dependency 'opensymphony:sitemesh:2.4.2'
2324
dependency 'org.gebish:geb-spock:0.10.0'
2425
dependency 'org.jasig.cas:cas-server-webapp:4.2.7'
@@ -61,6 +62,7 @@ dependencyManagement {
6162
dependency 'com.sun.xml.bind:jaxb-core:2.3.0.1'
6263
dependency 'com.sun.xml.bind:jaxb-impl:2.3.2'
6364
dependency 'com.unboundid:unboundid-ldapsdk:4.0.11'
65+
dependency 'com.webauthn4j:webauthn4j-core:0.9.7.RELEASE'
6466
dependency 'com.vaadin.external.google:android-json:0.0.20131108.vaadin1'
6567
dependency 'commons-cli:commons-cli:1.4'
6668
dependency 'commons-codec:commons-codec:1.12'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'io.spring.convention.spring-module'
2+
3+
dependencies {
4+
compile project(':spring-security-core')
5+
compile project(':spring-security-config')
6+
compile project(':spring-security-web')
7+
compile springCoreDependency
8+
compile("org.springframework:spring-core")
9+
compile("org.springframework:spring-context")
10+
compile("org.springframework:spring-aop")
11+
compile("org.springframework:spring-jdbc")
12+
compile("org.springframework:spring-web")
13+
14+
compile("com.webauthn4j:webauthn4j-core")
15+
16+
provided 'javax.servlet:javax.servlet-api'
17+
18+
compile project(':spring-security-test')
19+
testCompile("com.webauthn4j:webauthn4j-test")
20+
testCompile("org.skyscreamer:jsonassert")
21+
testCompile("org.springframework:spring-webmvc")
22+
testCompile('junit:junit')
23+
testCompile('org.mockito:mockito-core')
24+
testCompile('org.assertj:assertj-core')
25+
26+
27+
testRuntime 'org.hsqldb:hsqldb'
28+
}
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2002-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.security.webauthn;
18+
19+
import org.springframework.security.authentication.AbstractAuthenticationToken;
20+
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
21+
import org.springframework.security.core.Authentication;
22+
import org.springframework.security.webauthn.request.WebAuthnAuthenticationRequest;
23+
24+
/**
25+
* An {@link Authentication} implementation for representing WebAuthn assertion like
26+
* {@link UsernamePasswordAuthenticationToken} for password authentication
27+
*
28+
* @author Yoshikazu Nojima
29+
*/
30+
public class WebAuthnAssertionAuthenticationToken extends AbstractAuthenticationToken {
31+
32+
// ~ Instance fields
33+
// ================================================================================================
34+
private WebAuthnAuthenticationRequest credentials;
35+
36+
37+
// ~ Constructor
38+
// ========================================================================================================
39+
40+
/**
41+
* This constructor can be safely used by any code that wishes to create a
42+
* <code>WebAuthnAssertionAuthenticationToken</code>, as the {@link #isAuthenticated()}
43+
* will return <code>false</code>.
44+
*
45+
* @param credentials credential
46+
*/
47+
public WebAuthnAssertionAuthenticationToken(WebAuthnAuthenticationRequest credentials) {
48+
super(null);
49+
this.credentials = credentials;
50+
setAuthenticated(false);
51+
}
52+
53+
// ~ Methods
54+
// ========================================================================================================
55+
56+
/**
57+
* Always null
58+
*
59+
* @return null
60+
*/
61+
@Override
62+
public String getPrincipal() {
63+
return null;
64+
}
65+
66+
/**
67+
* @return the stored WebAuthn authentication context
68+
*/
69+
@Override
70+
public WebAuthnAuthenticationRequest getCredentials() {
71+
return credentials;
72+
}
73+
74+
/**
75+
* This object can never be authenticated, call with true result in exception.
76+
*
77+
* @param isAuthenticated only false value allowed
78+
* @throws IllegalArgumentException if isAuthenticated is true
79+
*/
80+
@Override
81+
public void setAuthenticated(boolean isAuthenticated) {
82+
if (isAuthenticated) {
83+
throw new IllegalArgumentException(
84+
"Cannot set this authenticator to trusted");
85+
}
86+
87+
super.setAuthenticated(false);
88+
}
89+
90+
/**
91+
* {@inheritDoc}
92+
*/
93+
@Override
94+
public void eraseCredentials() {
95+
super.eraseCredentials();
96+
credentials = null;
97+
}
98+
99+
/**
100+
* {@inheritDoc}
101+
*/
102+
@Override
103+
public boolean equals(Object o) {
104+
if (this == o) return true;
105+
if (!(o instanceof WebAuthnAssertionAuthenticationToken)) return false;
106+
if (!super.equals(o)) return false;
107+
108+
WebAuthnAssertionAuthenticationToken that = (WebAuthnAssertionAuthenticationToken) o;
109+
110+
return credentials != null ? credentials.equals(that.credentials) : that.credentials == null;
111+
}
112+
113+
/**
114+
* {@inheritDoc}
115+
*/
116+
@Override
117+
public int hashCode() {
118+
int result = super.hashCode();
119+
result = 31 * result + (credentials != null ? credentials.hashCode() : 0);
120+
return result;
121+
}
122+
}

0 commit comments

Comments
 (0)