List of usage examples for org.springframework.security.oauth2.provider OAuth2Authentication OAuth2Authentication
public OAuth2Authentication(OAuth2Request storedRequest, Authentication userAuthentication)
From source file:com.cedac.security.oauth2.provider.code.AuthorizationCodeServicesBaseTests.java
@Test public void testCreateAuthorizationCode() { OAuth2Request storedOAuth2Request = RequestTokenFactory.createOAuth2Request("id", false); OAuth2Authentication expectedAuthentication = new OAuth2Authentication(storedOAuth2Request, new TestAuthentication("test2", false)); String code = getAuthorizationCodeServices().createAuthorizationCode(expectedAuthentication); assertNotNull(code);/* w w w . j a va2s . c o m*/ OAuth2Authentication actualAuthentication = getAuthorizationCodeServices().consumeAuthorizationCode(code); assertEquals(expectedAuthentication, actualAuthentication); }
From source file:org.cloudfoundry.identity.uaa.password.event.PasswordChangeEventPublisherTests.java
@Before public void init() { subject.setApplicationEventPublisher(publisher); Authentication authentication = new OAuth2Authentication( new DefaultAuthorizationRequest("client", Arrays.asList("read")), UaaPasswordTestFactory.getAuthentication("ID", "joe", "joe@test.org")); SecurityContextHolder.getContext().setAuthentication(authentication); }
From source file:org.cloudfoundry.identity.uaa.openid.UserInfoEndpointTests.java
@Test public void testSunnyDay() { UaaUser user = userDatabase.retrieveUserByName("olds"); UaaAuthentication authentication = UaaAuthenticationTestFactory.getAuthentication(user.getId(), "olds", "olds@vmware.com"); Map<String, String> map = endpoint.loginInfo(new OAuth2Authentication(null, authentication)); assertEquals("olds", map.get("user_name")); assertEquals("Dale Olds", map.get("name")); assertEquals("olds@vmware.com", map.get("email")); }
From source file:org.zalando.stups.oauth2.spring.client.AccessTokenUtilsTest.java
@Test public void testMissingUserDetails() throws Exception { SecurityContextHolder.getContext()/*from w w w . j av a 2s .c om*/ .setAuthentication(new OAuth2Authentication(mock(OAuth2Request.class), mock(Authentication.class))); assertThat(getAccessTokenFromSecurityContext().isPresent()).isFalse(); }
From source file:com.example.oauth.Authentication.java
public OAuth2Authentication oauth2() { return new OAuth2Authentication(request(), resourceUserAuthentication); }
From source file:org.zalando.stups.oauth2.spring.client.SecurityContextTokenProviderTest.java
@Before public void setUp() throws Exception { tokenProvider = new SecurityContextTokenProvider(); final Authentication userAuthentication = mock(Authentication.class); when(userAuthentication.getDetails()).thenReturn(singletonMap(ACCESS_TOKEN, "1234567890")); SecurityContextHolder.getContext().setAuthentication( // new OAuth2Authentication(mock(OAuth2Request.class), userAuthentication)); }
From source file:org.zalando.stups.oauth2.spring.server.AbstractAuthenticationExtractor.java
@Override public OAuth2Authentication extractAuthentication(final Map<String, Object> map, final String clientId) { UsernamePasswordAuthenticationToken user = new UsernamePasswordAuthenticationToken(getPrincipal(map), "N/A", AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER")); user.setDetails(map);// www. j a v a 2 s. com // at the moment there is other way Set<String> scopes = resolveScopes(map); // OAuth2Request request = new OAuth2Request(null, clientId, null, true, scopes, null, null, null, null); return new OAuth2Authentication(request, user); }
From source file:components.OAuth2AuthenticationReadConverter.java
@Override public OAuth2Authentication convert(DBObject source) { DBObject storedRequest = (DBObject) source.get("storedRequest"); OAuth2Request oAuth2Request = new OAuth2Request( (Map<String, String>) storedRequest.get("requestParameters"), (String) storedRequest.get("clientId"), null, true, new HashSet((List) storedRequest.get("scope")), null, null, null, null);/*from ww w. j a va 2 s . com*/ DBObject userAuthorization = (DBObject) source.get("userAuthentication"); Object principal = getPrincipalObject(userAuthorization.get("principal")); Authentication userAuthentication = new UsernamePasswordAuthenticationToken(principal, (String) userAuthorization.get("credentials"), getAuthorities((List) userAuthorization.get("authorities"))); OAuth2Authentication authentication = new OAuth2Authentication(oAuth2Request, userAuthentication); return authentication; }
From source file:org.cloudfoundry.identity.uaa.oauth.JwtTokenEnhancerTests.java
@Test public void testEnhanceAccessToken() { OAuth2Authentication authentication = new OAuth2Authentication(new DefaultAuthorizationRequest("foo", null), userAuthentication);/*from w w w. jav a2 s . c om*/ OAuth2AccessToken token = tokenEnhancer.enhance(new DefaultOAuth2AccessToken("FOO"), authentication); assertNotNull(token.getValue()); assertEquals("FOO", token.getAdditionalInformation().get(JwtTokenEnhancer.TOKEN_ID)); String claims = JwtHelper.decode(token.getValue()).getClaims(); assertTrue("Wrong claims: " + claims, claims.contains("\"" + UserInfo.USER_ID + "\"")); assertTrue("Wrong claims: " + claims, claims.contains("\"" + JwtTokenEnhancer.TOKEN_ID + "\"")); }
From source file:org.cloudfoundry.identity.uaa.oauth.UaaAuthenticationKeyGeneratorTests.java
@Test public void testEmailChanges() { String key1 = generator.extractKey(new OAuth2Authentication(authorizationRequest, userAuthentication)); userAuthentication = UaaAuthenticationTestFactory.getAuthentication("FOO", "foo", "foo@none.org"); String key2 = generator.extractKey(new OAuth2Authentication(authorizationRequest, userAuthentication)); assertNotSame(key1, key2);//from w w w . jav a 2 s. co m }