use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class ScopeVoterTests method testExceptionThrownIfWrongScopesPresent.
@Test(expected = AccessDeniedException.class)
public void testExceptionThrownIfWrongScopesPresent() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(oAuth2Authentication, null, Collections.<ConfigAttribute>singleton(new SecurityConfig("SCOPE_WRITE"))));
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class ScopeVoterTests method testAccessDeniedIfWrongScopesPresent.
@Test
public void testAccessDeniedIfWrongScopesPresent() throws Exception {
OAuth2Request clientAuthentication = RequestTokenFactory.createOAuth2Request("foo", false, Collections.singleton("read"));
Authentication userAuthentication = null;
OAuth2Authentication oAuth2Authentication = new OAuth2Authentication(clientAuthentication, userAuthentication);
voter.setThrowException(false);
assertEquals(AccessDecisionVoter.ACCESS_DENIED, voter.vote(oAuth2Authentication, null, Collections.<ConfigAttribute>singleton(new SecurityConfig("SCOPE_WRITE"))));
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class AbstractPersistentDefaultTokenServicesTests method testTokenEnhancerUpdatesStoredTokens.
@Test
public void testTokenEnhancerUpdatesStoredTokens() throws Exception {
final ExpiringOAuth2RefreshToken refreshToken = new DefaultExpiringOAuth2RefreshToken("testToken", new Date(System.currentTimeMillis() + 100000));
getTokenServices().setTokenEnhancer(new TokenEnhancer() {
public OAuth2AccessToken enhance(OAuth2AccessToken accessToken, OAuth2Authentication authentication) {
DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken);
result.setRefreshToken(refreshToken);
return result;
}
});
OAuth2Authentication authentication = createAuthentication();
OAuth2AccessToken original = getTokenServices().createAccessToken(authentication);
assertTrue(original.getRefreshToken().equals(refreshToken));
OAuth2AccessToken result = getTokenStore().getAccessToken(authentication);
assertEquals(original, result);
assertEquals(refreshToken, result.getRefreshToken());
assertEquals(refreshToken, getTokenStore().readRefreshToken(refreshToken.getValue()));
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class DefaultAccessTokenConverterTests method extractAuthenticationSingleScopeString.
// gh-745
@Test
public void extractAuthenticationSingleScopeString() {
String scope = "read";
Map<String, Object> tokenAttrs = new HashMap<String, Object>();
tokenAttrs.put(AccessTokenConverter.SCOPE, scope);
OAuth2Authentication authentication = converter.extractAuthentication(tokenAttrs);
assertEquals(Collections.singleton(scope), authentication.getOAuth2Request().getScope());
}
use of org.springframework.security.oauth2.provider.OAuth2Authentication in project spring-security-oauth by spring-projects.
the class DefaultAccessTokenConverterTests method extractAuthenticationFromClientTokenSingleValuedAudience.
@Test
public void extractAuthenticationFromClientTokenSingleValuedAudience() {
DefaultOAuth2AccessToken token = new DefaultOAuth2AccessToken("FOO");
OAuth2Authentication authentication = new OAuth2Authentication(request, null);
token.setScope(authentication.getOAuth2Request().getScope());
Map<String, Object> map = new LinkedHashMap<String, Object>(converter.convertAccessToken(token, authentication));
@SuppressWarnings("unchecked") Object aud = ((Collection<Object>) map.get(AccessTokenConverter.AUD)).iterator().next();
map.put(AccessTokenConverter.AUD, aud);
assertTrue(map.containsKey(AccessTokenConverter.AUD));
OAuth2Authentication extracted = converter.extractAuthentication(map);
assertEquals("[" + aud + "]", extracted.getOAuth2Request().getResourceIds().toString());
}
Aggregations