@Test public void decodeWhenRSAPublicKeyThenSuccess() throws Exception { byte[] bytes = Base64.getDecoder().decode("MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqL48v1clgFw+Evm145pmh8nRYiNt72Gupsshn7Qs8dxEydCRp1DPOV/PahPk1y2nvldBNIhfNL13JOAiJ6BTiF+2ICuICAhDArLMnTH61oL1Hepq8W1xpa9gxsnL1P51thvfmiiT4RTW57koy4xIWmIp8ZXXfYgdH2uHJ9R0CQBuYKe7nEOObjxCFWC8S30huOfW2cYtv0iB23h6w5z2fDLjddX6v/FXM7ktcokgpm3/XmvT/+bL6/GGwz9k6kJOyMTubecr+WT//le8ikY66zlplYXRQh6roFfFCL21Pt8xN5zrk+0AMZUnmi8F2S2ztSBmAVJ7H71ELXsURBVZpwIDAQAB"); RSAPublicKey publicKey = (RSAPublicKey) KeyFactory.getInstance("RSA") .generatePublic(new X509EncodedKeySpec(bytes)); this.decoder = new NimbusReactiveJwtDecoder(publicKey); String noKeyId = "eyJhbGciOiJSUzI1NiJ9.eyJzY29wZSI6IiIsImV4cCI6OTIyMzM3MjAwNjA5NjM3NX0.hNVuHSUkxdLZrDfqdmKcOi0ggmNaDuB4ZPxPtJl1gwBiXzIGN6Hwl24O2BfBZiHFKUTQDs4_RvzD71mEG3DvUrcKmdYWqIB1l8KNmxQLUDG-cAPIpJmRJgCh50tf8OhOE_Cb9E1HcsOUb47kT9iz-VayNBcmo6BmyZLdEGhsdGBrc3Mkz2dd_0PF38I2Hf_cuSjn9gBjFGtiPEXJvob3PEjVTSx_zvodT8D9p3An1R3YBZf5JSd1cQisrXgDX2k1Jmf7UKKWzgfyCgnEtRWWbsUdPqo3rSEY9GDC1iSQXsFTTC1FT_JJDkwzGf011fsU5O_Ko28TARibmKTCxAKNRQ"; assertThatCode(() -> this.decoder.decode(noKeyId).block()) .doesNotThrowAnyException(); }
public OAuth2Login assertClientRegistrationByName(String clientName) { assertThatCode(() -> findClientRegistrationByName(clientName)) .doesNotThrowAnyException(); return this; }
@Test public void authenticateWhenNoSubscriptionThenDoesNothing() { // we didn't do anything because it should cause a ClassCastException (as verified below) TestingAuthenticationToken token = new TestingAuthenticationToken("a", "b"); assertThatCode(()-> this.manager.authenticate(token)) .doesNotThrowAnyException(); assertThatThrownBy(() -> this.manager.authenticate(token).block()) .isInstanceOf(Throwable.class); }
@Test public void authenticateWhenNoSubscriptionThenDoesNothing() { // we didn't do anything because it should cause a ClassCastException (as verified below) TestingAuthenticationToken token = new TestingAuthenticationToken("a", "b"); assertThatCode(()-> this.manager.authenticate(token)) .doesNotThrowAnyException(); assertThatThrownBy(() -> this.manager.authenticate(token).block()) .isInstanceOf(Throwable.class); }
@Test public void decodeWhenIatClaimNullThenDoesNotThrowException() { assertThatCode(() -> this.jwtDecoder.decode(SIGNED_JWT)) .doesNotThrowAnyException(); }
@Test public void decodeWhenExpClaimNullThenDoesNotThrowException() { assertThatCode(() -> this.jwtDecoder.decode(EMPTY_EXP_CLAIM_JWT)) .doesNotThrowAnyException(); }
@Test public void setRealmNameWhenNullRealmNameThenNoExceptionThrown() { assertThatCode(() -> this.accessDeniedHandler.setRealmName(null)) .doesNotThrowAnyException(); }
@Test public void setRealmNameWhenNullRealmNameThenNoExceptionThrown() { assertThatCode(() -> this.authenticationEntryPoint.setRealmName(null)) .doesNotThrowAnyException(); }
@Test @WithMockUser public void methodSecurityWhenPrePostEnabledThenPreAuthorizes() { this.spring.register(PreAuthorizeConfig.class, MethodSecurityServiceConfig.class).autowire(); assertThatCode(() -> this.service.secured()) .doesNotThrowAnyException(); assertThatCode(() -> this.service.jsr250()) .doesNotThrowAnyException(); assertThatThrownBy(() -> this.service.preAuthorize()) .isInstanceOf(AccessDeniedException.class); }
@Test @WithMockUser public void methodSecurityWhenImportingGlobalMethodSecurityConfigurationSubclassThenAuthorizes() { this.spring.register(ImportSubclassGMSCConfig.class, MethodSecurityServiceConfig.class).autowire(); assertThatCode(() -> this.service.secured()) .doesNotThrowAnyException(); assertThatCode(() -> this.service.jsr250()) .doesNotThrowAnyException(); assertThatThrownBy(() -> this.service.preAuthorize()) .isInstanceOf(AccessDeniedException.class); }
@WithMockUser(authorities = "CUSTOM") @Test public void methodSecurityWhenNullifyingRolePrefixThenPassivityRestored() { this.spring.register(SecurityConfig.class).autowire(); assertThatCode(() -> service.doJsr250()) .doesNotThrowAnyException(); assertThatCode(() -> service.doPreAuthorize()) .doesNotThrowAnyException(); }
@Test @WithMockUser public void methodSecurityWhenUsingCustomPermissionEvaluatorThenPostAuthorizesAccordingly() { this.spring.register(CustomAccessDecisionManagerConfig.class, MethodSecurityServiceConfig.class).autowire(); assertThatCode(() -> this.service.postHasPermission("granted")) .doesNotThrowAnyException(); assertThatThrownBy(() -> this.service.postHasPermission("denied")) .isInstanceOf(AccessDeniedException.class); }
@Test @WithMockUser public void methodSecurityWhenUsingCustomPermissionEvaluatorThenPreAuthorizesAccordingly() { this.spring.register(CustomAccessDecisionManagerConfig.class, MethodSecurityServiceConfig.class).autowire(); assertThatCode(() -> this.service.hasPermission("granted")) .doesNotThrowAnyException(); assertThatThrownBy(() -> this.service.hasPermission("denied")) .isInstanceOf(AccessDeniedException.class); }
@Test public void buildErrorResponseWhenStateIsNullThenDoesNotThrowAnyException() { assertThatCode(() -> OAuth2AuthorizationResponse.error(ERROR_CODE) .redirectUri(REDIRECT_URI) .state(null) .build()).doesNotThrowAnyException(); }
@Test public void sendWhenConnectWithSameOriginDisabledThenCsrfTokenNotRequired() { this.spring.configLocations(xml("SyncSameOriginDisabledConfig")).autowire(); Message<?> message = message("/message", SimpMessageType.CONNECT); assertThatCode(send(message)).doesNotThrowAnyException(); }
@Test public void sendWhenAnonymousMessageWithSubscribeMessageTypeThenPermitted() { this.spring.configLocations(xml("NoIdConfig")).autowire(); Message<?> message = message("/permitAll", SimpMessageType.SUBSCRIBE); assertThatCode(send(message)).doesNotThrowAnyException(); }
@Test public void sendWhenAnonymousMessageWithConnectAckMessageTypeThenPermitted() { this.spring.configLocations(xml("NoIdConfig")).autowire(); Message<?> message = message("/permitAll", SimpMessageType.CONNECT_ACK); assertThatCode(send(message)).doesNotThrowAnyException(); }
@Test public void sendWhenAnonymousMessageWithUnsubscribeMessageTypeThenPermitted() { this.spring.configLocations(xml("NoIdConfig")).autowire(); Message<?> message = message("/permitAll", SimpMessageType.UNSUBSCRIBE); assertThatCode(send(message)).doesNotThrowAnyException(); }
@Test public void buildWhenStateIsNullThenDoesNotThrowAnyException() { assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode() .authorizationUri(AUTHORIZATION_URI) .clientId(CLIENT_ID) .redirectUri(REDIRECT_URI) .scopes(SCOPES) .state(null) .build()) .doesNotThrowAnyException(); }
@Test public void buildWhenRedirectUriIsNullForAuthorizationCodeThenDoesNotThrowAnyException() { assertThatCode(() -> OAuth2AuthorizationRequest.authorizationCode() .authorizationUri(AUTHORIZATION_URI) .clientId(CLIENT_ID) .redirectUri(null) .scopes(SCOPES) .state(STATE) .build()) .doesNotThrowAnyException(); }