4646import org .springframework .security .web .webauthn .registration .PublicKeyCredentialCreationOptionsFilter ;
4747import org .springframework .security .web .webauthn .registration .PublicKeyCredentialCreationOptionsRepository ;
4848import org .springframework .security .web .webauthn .registration .WebAuthnRegistrationFilter ;
49+ import org .springframework .util .Assert ;
4950
5051/**
5152 * Configures WebAuthn for Spring Security applications
@@ -75,6 +76,7 @@ public class WebAuthnConfigurer<H extends HttpSecurityBuilder<H>>
7576 * @return the {@link WebAuthnConfigurer} for further customization
7677 */
7778 public WebAuthnConfigurer <H > rpId (String rpId ) {
79+ Assert .hasText (rpId , "rpId be null or empty" );
7880 this .rpId = rpId ;
7981 return this ;
8082 }
@@ -85,6 +87,7 @@ public WebAuthnConfigurer<H> rpId(String rpId) {
8587 * @return the {@link WebAuthnConfigurer} for further customization
8688 */
8789 public WebAuthnConfigurer <H > rpName (String rpName ) {
90+ Assert .hasText (rpName , "rpName can't be null or empty" );
8891 this .rpName = rpName ;
8992 return this ;
9093 }
@@ -106,6 +109,7 @@ public WebAuthnConfigurer<H> allowedOrigins(String... allowedOrigins) {
106109 * @see #allowedOrigins(String...)
107110 */
108111 public WebAuthnConfigurer <H > allowedOrigins (Set <String > allowedOrigins ) {
112+ Assert .notNull (allowedOrigins , "allowedOrigins can't be null" );
109113 this .allowedOrigins = allowedOrigins ;
110114 return this ;
111115 }
@@ -129,6 +133,7 @@ public WebAuthnConfigurer<H> disableDefaultRegistrationPage(boolean disable) {
129133 * @return the {@link WebAuthnConfigurer} for further customization
130134 */
131135 public WebAuthnConfigurer <H > messageConverter (HttpMessageConverter <Object > converter ) {
136+ Assert .notNull (converter , "converter can't be null" );
132137 this .converter = converter ;
133138 return this ;
134139 }
@@ -140,15 +145,15 @@ public WebAuthnConfigurer<H> messageConverter(HttpMessageConverter<Object> conve
140145 */
141146 public WebAuthnConfigurer <H > creationOptionsRepository (
142147 PublicKeyCredentialCreationOptionsRepository creationOptionsRepository ) {
148+ Assert .notNull (creationOptionsRepository , "creationOptionsRepository can't be null" );
143149 this .creationOptionsRepository = creationOptionsRepository ;
144150 return this ;
145151 }
146152
147153 @ Override
148154 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" ));
152157 PublicKeyCredentialUserEntityRepository userEntities = getSharedOrBean (http ,
153158 PublicKeyCredentialUserEntityRepository .class )
154159 .orElse (userEntityRepository ());
@@ -238,12 +243,9 @@ private WebAuthnRelyingPartyOperations webAuthnRelyingPartyOperations(
238243 PublicKeyCredentialUserEntityRepository userEntities , UserCredentialRepository userCredentials ) {
239244 Optional <WebAuthnRelyingPartyOperations > webauthnOperationsBean = getBeanOrNull (
240245 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 ));
247249 }
248250
249251}
0 commit comments