@Test // http@jaas-api-provision public void configureWhenJaasApiIntegrationFilterAddedThenJaasSubjectObtained() throws Exception { LoginContext loginContext = mock(LoginContext.class); when(loginContext.getSubject()).thenReturn(new Subject()); JaasAuthenticationToken authenticationToken = mock(JaasAuthenticationToken.class); when(authenticationToken.isAuthenticated()).thenReturn(true); when(authenticationToken.getLoginContext()).thenReturn(loginContext); this.spring.register(JaasApiProvisionConfig.class).autowire(); this.mockMvc.perform(get("/").with(authentication(authenticationToken))); verify(loginContext, times(1)).getSubject(); }
@Test public void requestWhenAuthorizedClientFoundThenMethodArgumentResolved() throws Exception { String clientRegistrationId = "client1"; String principalName = "user1"; TestingAuthenticationToken authentication = new TestingAuthenticationToken(principalName, "password"); OAuth2AuthorizedClientRepository authorizedClientRepository = mock(OAuth2AuthorizedClientRepository.class); OAuth2AuthorizedClient authorizedClient = mock(OAuth2AuthorizedClient.class); when(authorizedClientRepository.loadAuthorizedClient( eq(clientRegistrationId), eq(authentication), any(HttpServletRequest.class))).thenReturn(authorizedClient); OAuth2AccessToken accessToken = mock(OAuth2AccessToken.class); when(authorizedClient.getAccessToken()).thenReturn(accessToken); OAuth2AuthorizedClientArgumentResolverConfig.AUTHORIZED_CLIENT_REPOSITORY = authorizedClientRepository; this.spring.register(OAuth2AuthorizedClientArgumentResolverConfig.class).autowire(); this.mockMvc.perform(get("/authorized-client").with(authentication(authentication))) .andExpect(status().isOk()) .andExpect(content().string("resolved")); }
@Test public void configureWhenEnableWebMvcThenAuthenticationPrincipalResolvable() throws Exception { this.spring.register(AuthenticationPrincipalConfig.class).autowire(); this.mockMvc.perform(get("/").with(authentication(new TestingAuthenticationToken("user1", "password")))) .andExpect(content().string("user1")); }
.param(OAuth2ParameterNames.CODE, "code") .param(OAuth2ParameterNames.STATE, "state") .with(authentication(authentication)) .session(session)) .andExpect(status().is3xxRedirection())