use of org.apache.cxf.sts.request.ReceivedToken in project OpenAM by OpenRock.
the class TokenCancellerBase method cancelToken.
@Override
public TokenCancellerResponse cancelToken(TokenCancellerParameters tokenParameters) {
TokenCancellerResponse response = new TokenCancellerResponse();
ReceivedToken cancelTarget = tokenParameters.getToken();
cancelTarget.setState(ReceivedToken.STATE.VALID);
response.setToken(cancelTarget);
String tokenServiceConsumptionToken = null;
try {
final String tokenId = generateIdFromValidateTarget(cancelTarget);
tokenServiceConsumptionToken = getTokenServiceConsumptionToken();
tokenServiceConsumer.cancelToken(tokenId, tokenServiceConsumptionToken);
cancelTarget.setState(ReceivedToken.STATE.CANCELLED);
return response;
} catch (TokenCancellationException e) {
throw new STSException("Exception caught validating issued token: " + e.getMessage(), e);
} finally {
if (tokenServiceConsumptionToken != null) {
invalidateTokenGenerationServiceConsumptionToken(tokenServiceConsumptionToken);
}
}
}
use of org.apache.cxf.sts.request.ReceivedToken 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.request.ReceivedToken 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.request.ReceivedToken in project ddf by codice.
the class TestBSTDelegationHandler method testCanNotHandle.
@Test
public void testCanNotHandle() {
BinarySecurityTokenType binarySecurityTokenType = new BinarySecurityTokenType();
binarySecurityTokenType.setEncodingType(WSConstants.SOAPMESSAGE_NS + "#WrongType");
binarySecurityTokenType.setValueType(BSTAuthenticationToken.BST_NS + "#" + BSTAuthenticationToken.BST_LN);
ReceivedToken receivedToken = mock(ReceivedToken.class);
when(receivedToken.getToken()).thenReturn(binarySecurityTokenType);
BSTDelegationHandler bstDelegationHandler = new BSTDelegationHandler();
boolean result = bstDelegationHandler.canHandleToken(receivedToken);
assertEquals(false, result);
}
use of org.apache.cxf.sts.request.ReceivedToken in project ddf by codice.
the class TestBSTDelegationHandler method testCanHandle.
@Test
public void testCanHandle() {
BinarySecurityTokenType binarySecurityTokenType = new BinarySecurityTokenType();
binarySecurityTokenType.setEncodingType(WSConstants.SOAPMESSAGE_NS + "#Base64Binary");
binarySecurityTokenType.setValueType(BSTAuthenticationToken.BST_NS + "#" + BSTAuthenticationToken.BST_LN);
ReceivedToken receivedToken = mock(ReceivedToken.class);
when(receivedToken.getToken()).thenReturn(binarySecurityTokenType);
BSTDelegationHandler bstDelegationHandler = new BSTDelegationHandler();
boolean result = bstDelegationHandler.canHandleToken(receivedToken);
assertEquals(true, result);
}
Aggregations