Search in sources :

Example 1 with TokenProvider

use of org.apache.cxf.sts.token.provider.TokenProvider in project OpenAM by OpenRock.

the class TokenIssueOperationProvider method get.

public IssueOperation get() {
    //TODO: migrate to throwing providers
    try {
        TokenIssueOperation tokenIssueOperation = new TokenIssueOperation();
        /*
            The STS will not encrypt the issued tokens - the TokenGenerationService already offers functionality to
            encrypt issued SAML assertions.
             */
        tokenIssueOperation.setEncryptIssuedToken(false);
        tokenIssueOperation.setStsProperties(stsPropertiesMBean);
        tokenIssueOperation.setTokenStore(tokenStore);
        /*
            Set the tokenValidators which will be called to validate the tokens presented as ActAs or OnBehalfOf
            elements
             */
        tokenIssueOperation.setTokenValidators(getDelegationTokenValidators());
        /*
            Set the TokenDelegationHandlers (either empty if this sts instance will not process ActAs or OnBehalfOf elements,
            or with the DefaultTokenDelegationHandler, or with user-specified custom handlers.
             */
        tokenIssueOperation.setDelegationHandlers(tokenDelegationHandlers);
        List<TokenProvider> tokenProviders = new ArrayList<TokenProvider>();
        for (TokenType tokenType : issueTokenTypes) {
            tokenProviders.add(operationFactory.getTokenProvider(tokenType));
        }
        tokenIssueOperation.setTokenProviders(tokenProviders);
        return new TokenIssueOperationWrapper(tokenIssueOperation, threadLocalAMTokenCache);
    } catch (STSInitializationException e) {
        logger.error("Exception caught initializing a IssueOperation: " + e, e);
        throw new RuntimeException(e);
    }
}
Also used : TokenProvider(org.apache.cxf.sts.token.provider.TokenProvider) TokenType(org.forgerock.openam.sts.TokenType) RequestSecurityTokenType(org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType) TokenIssueOperation(org.apache.cxf.sts.operation.TokenIssueOperation) ArrayList(java.util.ArrayList) STSInitializationException(org.forgerock.openam.sts.STSInitializationException)

Example 2 with TokenProvider

use of org.apache.cxf.sts.token.provider.TokenProvider in project OpenAM by OpenRock.

the class TokenIssueOperationProviderTest method testExceptionInitialization.

@Test(expectedExceptions = RuntimeException.class)
public void testExceptionInitialization() throws STSInitializationException {
    TokenOperationFactory mockOperationFactory = mock(TokenOperationFactory.class);
    TokenProvider mockProvider = mock(TokenProvider.class);
    when(mockOperationFactory.getTokenProvider(any(TokenType.class))).thenThrow(STSInitializationException.class);
    TokenIssueOperationProvider issueOperationProvider = Guice.createInjector(new MyModule(mockOperationFactory)).getInstance(TokenIssueOperationProvider.class);
    issueOperationProvider.get();
}
Also used : TokenProvider(org.apache.cxf.sts.token.provider.TokenProvider) TokenType(org.forgerock.openam.sts.TokenType) Test(org.testng.annotations.Test)

Example 3 with TokenProvider

use of org.apache.cxf.sts.token.provider.TokenProvider in project OpenAM by OpenRock.

the class TokenIssueOperationProviderTest method testDelegate.

@Test
public void testDelegate() throws STSInitializationException {
    TokenOperationFactory mockOperationFactory = mock(TokenOperationFactory.class);
    TokenProvider mockProvider = mock(TokenProvider.class);
    when(mockOperationFactory.getTokenProvider(any(TokenType.class))).thenReturn(mockProvider);
    TokenIssueOperationProvider issueOperationProvider = Guice.createInjector(new MyModule(mockOperationFactory)).getInstance(TokenIssueOperationProvider.class);
    assertTrue(issueOperationProvider.get() instanceof TokenIssueOperationProvider.TokenIssueOperationWrapper);
}
Also used : TokenProvider(org.apache.cxf.sts.token.provider.TokenProvider) TokenType(org.forgerock.openam.sts.TokenType) Test(org.testng.annotations.Test)

Aggregations

TokenProvider (org.apache.cxf.sts.token.provider.TokenProvider)3 TokenType (org.forgerock.openam.sts.TokenType)3 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 TokenIssueOperation (org.apache.cxf.sts.operation.TokenIssueOperation)1 RequestSecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType)1 STSInitializationException (org.forgerock.openam.sts.STSInitializationException)1