Search in sources :

Example 1 with TokenDelegationResponse

use of org.apache.cxf.sts.token.delegation.TokenDelegationResponse in project OpenAM by OpenRock.

the class DefaultTokenDelegationHandler method isDelegationAllowed.

@Override
public TokenDelegationResponse isDelegationAllowed(TokenDelegationParameters tokenParameters) {
    final TokenDelegationResponse tokenDelegationResponse = new TokenDelegationResponse();
    tokenDelegationResponse.setDelegationAllowed(tokenParameters.getTokenPrincipal() != null);
    return tokenDelegationResponse;
}
Also used : TokenDelegationResponse(org.apache.cxf.sts.token.delegation.TokenDelegationResponse)

Example 2 with TokenDelegationResponse

use of org.apache.cxf.sts.token.delegation.TokenDelegationResponse in project OpenAM by OpenRock.

the class CustomDelegationHandlerWrapper method isDelegationAllowed.

@Override
public TokenDelegationResponse isDelegationAllowed(TokenDelegationParameters tokenParameters) {
    final TokenDelegationResponse tokenDelegationResponse = customHandler.isDelegationAllowed(tokenParameters);
    if (tokenDelegationResponse.isDelegationAllowed()) {
        final Map<String, Object> additionalProperties = tokenDelegationResponse.getAdditionalProperties();
        if ((additionalProperties != null) && additionalProperties.get(AMSTSConstants.CUSTOM_DELEGATION_HANDLER_AM_SESSION_ID) instanceof String) {
            boolean invalidateInterimSession = true;
            Object invalidateSessionObject = additionalProperties.get(AMSTSConstants.CUSTOM_DELEGATION_HANDLER_INVALIDATE_AM_SESSION);
            if (invalidateSessionObject instanceof Boolean) {
                invalidateInterimSession = (Boolean) invalidateSessionObject;
            }
            try {
                threadLocalAMTokenCache.cacheSessionIdForContext(ValidationInvocationContext.SOAP_TOKEN_DELEGATION, (String) additionalProperties.get(AMSTSConstants.CUSTOM_DELEGATION_HANDLER_AM_SESSION_ID), invalidateInterimSession);
            } catch (TokenValidationException e) {
                throw new AMSTSRuntimeException(e.getCode(), e.getMessage(), e);
            }
        } else {
            if (!delegationValidatorsSpecified) {
                String message = "In a custom TokenDelegationHandler, the delegated token is allowed, no delegation " + "validators have been specified, and the AM Session Id was not specified in the " + "DelegationHandlerResponse#getAdditionalProperties keyed by " + AMSTSConstants.CUSTOM_DELEGATION_HANDLER_AM_SESSION_ID + ". This means the " + "TokenGenerationService cannot issue an assertion corresponding to the delegated token.";
                logger.error(message);
                throw new AMSTSRuntimeException(ResourceException.UNAVAILABLE, message);
            }
        }
    }
    return tokenDelegationResponse;
}
Also used : AMSTSRuntimeException(org.forgerock.openam.sts.AMSTSRuntimeException) TokenDelegationResponse(org.apache.cxf.sts.token.delegation.TokenDelegationResponse) TokenValidationException(org.forgerock.openam.sts.TokenValidationException)

Example 3 with TokenDelegationResponse

use of org.apache.cxf.sts.token.delegation.TokenDelegationResponse in project ddf by codice.

the class BSTDelegationHandler method isDelegationAllowed.

public TokenDelegationResponse isDelegationAllowed(TokenDelegationParameters tokenParameters) {
    TokenDelegationResponse response = new TokenDelegationResponse();
    ReceivedToken delegateTarget = tokenParameters.getToken();
    response.setToken(delegateTarget);
    Object token = delegateTarget.getToken();
    if (token instanceof BinarySecurityTokenType) {
        response.setDelegationAllowed(true);
    }
    return response;
}
Also used : BinarySecurityTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.BinarySecurityTokenType) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) TokenDelegationResponse(org.apache.cxf.sts.token.delegation.TokenDelegationResponse)

Example 4 with TokenDelegationResponse

use of org.apache.cxf.sts.token.delegation.TokenDelegationResponse in project ddf by codice.

the class TestBSTDelegationHandler method testDelegationNotAllowed.

@Test
public void testDelegationNotAllowed() {
    UsernameTokenType binarySecurityTokenType = new UsernameTokenType();
    ReceivedToken receivedToken = mock(ReceivedToken.class);
    when(receivedToken.getToken()).thenReturn(binarySecurityTokenType);
    TokenDelegationParameters tokenDelegationParameters = mock(TokenDelegationParameters.class);
    when(tokenDelegationParameters.getToken()).thenReturn(receivedToken);
    BSTDelegationHandler bstDelegationHandler = new BSTDelegationHandler();
    TokenDelegationResponse response = bstDelegationHandler.isDelegationAllowed(tokenDelegationParameters);
    assertEquals(false, response.isDelegationAllowed());
}
Also used : TokenDelegationParameters(org.apache.cxf.sts.token.delegation.TokenDelegationParameters) UsernameTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) TokenDelegationResponse(org.apache.cxf.sts.token.delegation.TokenDelegationResponse) Test(org.junit.Test)

Example 5 with TokenDelegationResponse

use of org.apache.cxf.sts.token.delegation.TokenDelegationResponse in project ddf by codice.

the class X509DelegationHandler method isDelegationAllowed.

public TokenDelegationResponse isDelegationAllowed(TokenDelegationParameters tokenParameters) {
    TokenDelegationResponse response = new TokenDelegationResponse();
    ReceivedToken delegateTarget = tokenParameters.getToken();
    response.setToken(delegateTarget);
    Object token = delegateTarget.getToken();
    if (token instanceof BinarySecurityTokenType) {
        response.setDelegationAllowed(true);
    }
    return response;
}
Also used : BinarySecurityTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.BinarySecurityTokenType) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) TokenDelegationResponse(org.apache.cxf.sts.token.delegation.TokenDelegationResponse)

Aggregations

TokenDelegationResponse (org.apache.cxf.sts.token.delegation.TokenDelegationResponse)8 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)4 TokenDelegationParameters (org.apache.cxf.sts.token.delegation.TokenDelegationParameters)3 BinarySecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.secext.BinarySecurityTokenType)3 Test (org.junit.Test)2 lombok.val (lombok.val)1 KeyRequirements (org.apache.cxf.sts.request.KeyRequirements)1 TokenRequirements (org.apache.cxf.sts.request.TokenRequirements)1 TokenDelegationHandler (org.apache.cxf.sts.token.delegation.TokenDelegationHandler)1 STSException (org.apache.cxf.ws.security.sts.provider.STSException)1 UsernameTokenType (org.apache.cxf.ws.security.sts.provider.model.secext.UsernameTokenType)1 AMSTSRuntimeException (org.forgerock.openam.sts.AMSTSRuntimeException)1 TokenValidationException (org.forgerock.openam.sts.TokenValidationException)1