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);
}
}
}
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;
}
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));
}
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());
}
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());
}
Aggregations