Search in sources :

Example 1 with DefaultAuthoritiesExtractor

use of com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor in project cloud-security-xsuaa-integration by SAP.

the class TokenAuthenticationConverter method setLocalScopeAsAuthorities.

/**
 * This method allows to overwrite the default behavior of the
 * {@link Token#getAuthorities()} implementation.
 *
 * @param extractLocalScopesOnly
 *            true when {@link Token#getAuthorities()} should only extract local
 *            scopes. Local scopes means that non-application specific scopes
 *            are filtered out and scopes are returned without appId prefix,
 *            e.g. "Display". Creates a new converter with a new
 *            {@link LocalAuthoritiesExtractor}
 * @return the token authenticator itself
 */
public TokenAuthenticationConverter setLocalScopeAsAuthorities(boolean extractLocalScopesOnly) {
    if (extractLocalScopesOnly) {
        Assert.state(appId != null, "For local Scope extraction 'appId' must be provided to `TokenAuthenticationConverter`");
        authoritiesExtractor = new LocalAuthoritiesExtractor(appId);
    } else {
        authoritiesExtractor = new DefaultAuthoritiesExtractor();
    }
    return this;
}
Also used : DefaultAuthoritiesExtractor(com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor) LocalAuthoritiesExtractor(com.sap.cloud.security.xsuaa.extractor.LocalAuthoritiesExtractor)

Example 2 with DefaultAuthoritiesExtractor

use of com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor in project cloud-security-xsuaa-integration by SAP.

the class SpringXsuaaSecurityContextTest method setToken.

private static void setToken(Token token) {
    XsuaaJwtDecoder mockXsuaaJwtDecoder = Mockito.mock(XsuaaJwtDecoder.class);
    when(mockXsuaaJwtDecoder.decode(token.getTokenValue())).thenReturn(convertTokenToOAuthJwt(token.getTokenValue()));
    // initialize SpringSecurityContext with provided token
    init(token.getTokenValue(), mockXsuaaJwtDecoder, new DefaultAuthoritiesExtractor());
}
Also used : DefaultAuthoritiesExtractor(com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor) XsuaaJwtDecoder(com.sap.cloud.security.xsuaa.token.authentication.XsuaaJwtDecoder)

Example 3 with DefaultAuthoritiesExtractor

use of com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor in project cloud-security-xsuaa-integration by SAP.

the class SpringSecurityContextTest method initSecurityContextWithToken.

private static void initSecurityContextWithToken(Jwt token) throws InterruptedException {
    XsuaaJwtDecoder mockXsuaaJwtDecoder = Mockito.mock(XsuaaJwtDecoder.class);
    when(mockXsuaaJwtDecoder.decode(token.getTokenValue())).thenReturn(token);
    // initialize SpringSecurityContext with provided token
    SpringSecurityContext.init(token.getTokenValue(), mockXsuaaJwtDecoder, new DefaultAuthoritiesExtractor());
}
Also used : DefaultAuthoritiesExtractor(com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor) XsuaaJwtDecoder(com.sap.cloud.security.xsuaa.token.authentication.XsuaaJwtDecoder)

Example 4 with DefaultAuthoritiesExtractor

use of com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor in project cloud-security-xsuaa-integration by SAP.

the class OAuth2TokenAuthenticationConverterTest method setup.

@Before
public void setup() {
    OAuth2AuthenticationConverter tokenConverterOauth2 = new OAuth2AuthenticationConverter(new DefaultAuthoritiesExtractor());
    Jwt jwt = new JwtGenerator().addScopes(scopeAdmin, scopeRead, scopeOther).getToken();
    authenticationToken = tokenConverterOauth2.convert(jwt);
}
Also used : DefaultAuthoritiesExtractor(com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor) JwtGenerator(com.sap.cloud.security.xsuaa.test.JwtGenerator) Jwt(org.springframework.security.oauth2.jwt.Jwt) Before(org.junit.Before)

Aggregations

DefaultAuthoritiesExtractor (com.sap.cloud.security.xsuaa.extractor.DefaultAuthoritiesExtractor)4 XsuaaJwtDecoder (com.sap.cloud.security.xsuaa.token.authentication.XsuaaJwtDecoder)2 LocalAuthoritiesExtractor (com.sap.cloud.security.xsuaa.extractor.LocalAuthoritiesExtractor)1 JwtGenerator (com.sap.cloud.security.xsuaa.test.JwtGenerator)1 Before (org.junit.Before)1 Jwt (org.springframework.security.oauth2.jwt.Jwt)1