Search in sources :

Example 26 with TokenValidatorResponse

use of org.apache.cxf.sts.token.validator.TokenValidatorResponse in project OpenAM by OpenRock.

the class SimpleTokenValidatorBase method validateToken.

@Override
public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParameters) {
    TokenValidatorResponse response = new TokenValidatorResponse();
    ReceivedToken validateTarget = tokenParameters.getToken();
    response.setToken(validateTarget);
    String tokenServiceConsumptionToken = null;
    try {
        final String tokenId = generateIdFromValidateTarget(validateTarget);
        tokenServiceConsumptionToken = getTokenServiceConsumptionToken();
        final boolean isTokenValid = tokenServiceConsumer.validateToken(tokenId, tokenServiceConsumptionToken);
        validateTarget.setState(isTokenValid ? ReceivedToken.STATE.VALID : ReceivedToken.STATE.INVALID);
        return response;
    } catch (TokenValidationException e) {
        throw new STSException("Exception caught validating issued token: " + e.getMessage(), e);
    } finally {
        if (tokenServiceConsumptionToken != null) {
            invalidateTokenGenerationServiceConsumptionToken(tokenServiceConsumptionToken);
        }
    }
}
Also used : STSException(org.apache.cxf.ws.security.sts.provider.STSException) TokenValidatorResponse(org.apache.cxf.sts.token.validator.TokenValidatorResponse) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) TokenValidationException(org.forgerock.openam.sts.TokenValidationException)

Example 27 with TokenValidatorResponse

use of org.apache.cxf.sts.token.validator.TokenValidatorResponse in project OpenAM by OpenRock.

the class SoapAMTokenValidator method validateToken.

/**
     *
     * @param tokenParameters the state necessary for token validation
     * @return an instance of the TokenValidatorResponse class which indicates whether the token was successfully
     * validated.
     */
@Override
public TokenValidatorResponse validateToken(TokenValidatorParameters tokenParameters) {
    TokenValidatorResponse response = new TokenValidatorResponse();
    ReceivedToken validateTarget = tokenParameters.getToken();
    validateTarget.setState(ReceivedToken.STATE.INVALID);
    response.setToken(validateTarget);
    try {
        String sessionId = parseSessionIdFromRequest(tokenParameters.getToken());
        Principal principal = principalFromSession.getPrincipalFromSession(sessionId);
        threadLocalAMTokenCache.cacheSessionIdForContext(validationInvocationContext, sessionId, invalidateAMSession);
        response.setPrincipal(principal);
        validateTarget.setState(ReceivedToken.STATE.VALID);
    } catch (Exception e) {
        logger.info("Exception caught obtaining principal from session id: " + e, e);
    }
    return response;
}
Also used : TokenValidatorResponse(org.apache.cxf.sts.token.validator.TokenValidatorResponse) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) Principal(java.security.Principal) ResourceException(org.forgerock.json.resource.ResourceException) TokenCreationException(org.forgerock.openam.sts.TokenCreationException)

Example 28 with TokenValidatorResponse

use of org.apache.cxf.sts.token.validator.TokenValidatorResponse in project ddf by codice.

the class TestPKITokenValidator method testValidateToken.

@Test
public void testValidateToken() {
    BinarySecurityTokenType binarySecurityTokenType = new BinarySecurityTokenType();
    binarySecurityTokenType.setEncodingType(WSConstants.SOAPMESSAGE_NS + "#Base64Binary");
    binarySecurityTokenType.setValueType(PKIAuthenticationToken.PKI_TOKEN_VALUE_TYPE);
    PKIAuthenticationTokenFactory pkiAuthenticationTokenFactory = new PKIAuthenticationTokenFactory();
    pkiAuthenticationTokenFactory.setSignaturePropertiesPath(TestPKITokenValidator.class.getResource("/signature.properties").getPath());
    pkiAuthenticationTokenFactory.init();
    PKIAuthenticationToken pkiAuthenticationToken = pkiAuthenticationTokenFactory.getTokenFromCerts(certificates, "karaf");
    binarySecurityTokenType.setValue(pkiAuthenticationToken.getEncodedCredentials());
    ReceivedToken receivedToken = mock(ReceivedToken.class);
    when(receivedToken.getToken()).thenReturn(binarySecurityTokenType);
    TokenValidatorParameters tokenValidatorParameters = mock(TokenValidatorParameters.class);
    STSPropertiesMBean stsPropertiesMBean = mock(STSPropertiesMBean.class);
    when(stsPropertiesMBean.getSignatureCrypto()).thenReturn(merlin);
    when(tokenValidatorParameters.getStsProperties()).thenReturn(stsPropertiesMBean);
    when(tokenValidatorParameters.getToken()).thenReturn(receivedToken);
    doCallRealMethod().when(receivedToken).setState(any(ReceivedToken.STATE.class));
    doCallRealMethod().when(receivedToken).getState();
    TokenValidatorResponse tokenValidatorResponse = pkiTokenValidator.validateToken(tokenValidatorParameters);
    assertEquals(ReceivedToken.STATE.VALID, tokenValidatorResponse.getToken().getState());
    assertEquals("US", tokenValidatorResponse.getAdditionalProperties().get(SubjectUtils.COUNTRY_CLAIM_URI));
    assertEquals("localhost@example.org", tokenValidatorResponse.getAdditionalProperties().get(SubjectUtils.EMAIL_ADDRESS_CLAIM_URI));
}
Also used : TokenValidatorParameters(org.apache.cxf.sts.token.validator.TokenValidatorParameters) PKIAuthenticationToken(org.codice.ddf.security.handler.api.PKIAuthenticationToken) BinarySecurityTokenType(org.apache.cxf.ws.security.sts.provider.model.secext.BinarySecurityTokenType) PKIAuthenticationTokenFactory(org.codice.ddf.security.handler.api.PKIAuthenticationTokenFactory) STSPropertiesMBean(org.apache.cxf.sts.STSPropertiesMBean) TokenValidatorResponse(org.apache.cxf.sts.token.validator.TokenValidatorResponse) ReceivedToken(org.apache.cxf.sts.request.ReceivedToken) Test(org.junit.Test)

Example 29 with TokenValidatorResponse

use of org.apache.cxf.sts.token.validator.TokenValidatorResponse in project ddf by codice.

the class GuestValidatorTest method testCanValidateIpv6ReachabilityToken.

@Test
public void testCanValidateIpv6ReachabilityToken() {
    TokenValidatorParameters params = new TokenValidatorParameters();
    params.setToken(receivedTokenIpv6Reachability);
    TokenValidatorResponse response = validator.validateToken(params);
    assertEquals(ReceivedToken.STATE.VALID, response.getToken().getState());
}
Also used : TokenValidatorParameters(org.apache.cxf.sts.token.validator.TokenValidatorParameters) TokenValidatorResponse(org.apache.cxf.sts.token.validator.TokenValidatorResponse) Test(org.junit.Test)

Example 30 with TokenValidatorResponse

use of org.apache.cxf.sts.token.validator.TokenValidatorResponse in project ddf by codice.

the class GuestValidatorTest method testCanValidateBadToken.

@Test
public void testCanValidateBadToken() {
    parameters.setToken(receivedBadToken);
    TokenValidatorResponse response = validator.validateToken(parameters);
    assertEquals(ReceivedToken.STATE.INVALID, response.getToken().getState());
}
Also used : TokenValidatorResponse(org.apache.cxf.sts.token.validator.TokenValidatorResponse) Test(org.junit.Test)

Aggregations

TokenValidatorResponse (org.apache.cxf.sts.token.validator.TokenValidatorResponse)49 ReceivedToken (org.apache.cxf.sts.request.ReceivedToken)42 TokenValidatorParameters (org.apache.cxf.sts.token.validator.TokenValidatorParameters)31 Crypto (org.apache.wss4j.common.crypto.Crypto)25 Test (org.junit.Test)19 STSPropertiesMBean (org.apache.cxf.sts.STSPropertiesMBean)17 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)17 CallbackHandler (javax.security.auth.callback.CallbackHandler)16 CustomTokenPrincipal (org.apache.wss4j.common.principal.CustomTokenPrincipal)16 TokenRequirements (org.apache.cxf.sts.request.TokenRequirements)15 Document (org.w3c.dom.Document)15 Element (org.w3c.dom.Element)15 TokenValidator (org.apache.cxf.sts.token.validator.TokenValidator)14 BinarySecurityTokenType (org.apache.cxf.ws.security.sts.provider.model.secext.BinarySecurityTokenType)14 STSException (org.apache.cxf.ws.security.sts.provider.STSException)12 PasswordCallbackHandler (org.apache.cxf.sts.common.PasswordCallbackHandler)11 SAMLTokenValidator (org.apache.cxf.sts.token.validator.SAMLTokenValidator)11 RequestData (org.apache.wss4j.dom.handler.RequestData)10 Credential (org.apache.wss4j.dom.validate.Credential)9 XmlParser (org.codice.ddf.parser.xml.XmlParser)7