46
46
import org .springframework .security .web .webauthn .registration .PublicKeyCredentialCreationOptionsFilter ;
47
47
import org .springframework .security .web .webauthn .registration .PublicKeyCredentialCreationOptionsRepository ;
48
48
import org .springframework .security .web .webauthn .registration .WebAuthnRegistrationFilter ;
49
+ import org .springframework .util .Assert ;
49
50
50
51
/**
51
52
* Configures WebAuthn for Spring Security applications
@@ -75,6 +76,7 @@ public class WebAuthnConfigurer<H extends HttpSecurityBuilder<H>>
75
76
* @return the {@link WebAuthnConfigurer} for further customization
76
77
*/
77
78
public WebAuthnConfigurer <H > rpId (String rpId ) {
79
+ Assert .hasText (rpId , "rpId be null or empty" );
78
80
this .rpId = rpId ;
79
81
return this ;
80
82
}
@@ -85,6 +87,7 @@ public WebAuthnConfigurer<H> rpId(String rpId) {
85
87
* @return the {@link WebAuthnConfigurer} for further customization
86
88
*/
87
89
public WebAuthnConfigurer <H > rpName (String rpName ) {
90
+ Assert .hasText (rpName , "rpName can't be null or empty" );
88
91
this .rpName = rpName ;
89
92
return this ;
90
93
}
@@ -106,6 +109,7 @@ public WebAuthnConfigurer<H> allowedOrigins(String... allowedOrigins) {
106
109
* @see #allowedOrigins(String...)
107
110
*/
108
111
public WebAuthnConfigurer <H > allowedOrigins (Set <String > allowedOrigins ) {
112
+ Assert .notNull (allowedOrigins , "allowedOrigins can't be null" );
109
113
this .allowedOrigins = allowedOrigins ;
110
114
return this ;
111
115
}
@@ -129,6 +133,7 @@ public WebAuthnConfigurer<H> disableDefaultRegistrationPage(boolean disable) {
129
133
* @return the {@link WebAuthnConfigurer} for further customization
130
134
*/
131
135
public WebAuthnConfigurer <H > messageConverter (HttpMessageConverter <Object > converter ) {
136
+ Assert .notNull (converter , "converter can't be null" );
132
137
this .converter = converter ;
133
138
return this ;
134
139
}
@@ -140,15 +145,15 @@ public WebAuthnConfigurer<H> messageConverter(HttpMessageConverter<Object> conve
140
145
*/
141
146
public WebAuthnConfigurer <H > creationOptionsRepository (
142
147
PublicKeyCredentialCreationOptionsRepository creationOptionsRepository ) {
148
+ Assert .notNull (creationOptionsRepository , "creationOptionsRepository can't be null" );
143
149
this .creationOptionsRepository = creationOptionsRepository ;
144
150
return this ;
145
151
}
146
152
147
153
@ Override
148
154
public void configure (H http ) throws Exception {
149
- UserDetailsService userDetailsService = getSharedOrBean (http , UserDetailsService .class ).orElseGet (() -> {
150
- throw new IllegalStateException ("Missing UserDetailsService Bean" );
151
- });
155
+ UserDetailsService userDetailsService = getSharedOrBean (http , UserDetailsService .class )
156
+ .orElseThrow (() -> new IllegalStateException ("Missing UserDetailsService Bean" ));
152
157
PublicKeyCredentialUserEntityRepository userEntities = getSharedOrBean (http ,
153
158
PublicKeyCredentialUserEntityRepository .class )
154
159
.orElse (userEntityRepository ());
@@ -238,12 +243,9 @@ private WebAuthnRelyingPartyOperations webAuthnRelyingPartyOperations(
238
243
PublicKeyCredentialUserEntityRepository userEntities , UserCredentialRepository userCredentials ) {
239
244
Optional <WebAuthnRelyingPartyOperations > webauthnOperationsBean = getBeanOrNull (
240
245
WebAuthnRelyingPartyOperations .class );
241
- if (webauthnOperationsBean .isPresent ()) {
242
- return webauthnOperationsBean .get ();
243
- }
244
- Webauthn4JRelyingPartyOperations result = new Webauthn4JRelyingPartyOperations (userEntities , userCredentials ,
245
- PublicKeyCredentialRpEntity .builder ().id (this .rpId ).name (this .rpName ).build (), this .allowedOrigins );
246
- return result ;
246
+ return webauthnOperationsBean .orElseGet (() -> new Webauthn4JRelyingPartyOperations (userEntities ,
247
+ userCredentials , PublicKeyCredentialRpEntity .builder ().id (this .rpId ).name (this .rpName ).build (),
248
+ this .allowedOrigins ));
247
249
}
248
250
249
251
}
0 commit comments