use of org.apache.cxf.sts.request.TokenRequirements in project cxf by apache.
the class ValidateJWTTransformationTest method createProviderParameters.
private TokenProviderParameters createProviderParameters(String tokenType, String keyType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler) throws WSSecurityException {
TokenProviderParameters parameters = new TokenProviderParameters();
TokenRequirements tokenRequirements = new TokenRequirements();
tokenRequirements.setTokenType(tokenType);
parameters.setTokenRequirements(tokenRequirements);
KeyRequirements keyRequirements = new KeyRequirements();
keyRequirements.setKeyType(keyType);
parameters.setKeyRequirements(keyRequirements);
parameters.setPrincipal(new CustomTokenPrincipal("alice"));
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
parameters.setMessageContext(msgCtx);
parameters.setAppliesToAddress("http://dummy-service.com/dummy");
// Add STSProperties object
StaticSTSProperties stsProperties = new StaticSTSProperties();
stsProperties.setSignatureCrypto(crypto);
stsProperties.setSignatureUsername(signatureUsername);
stsProperties.setCallbackHandler(callbackHandler);
stsProperties.setIssuer("STS");
parameters.setStsProperties(stsProperties);
parameters.setEncryptionProperties(new EncryptionProperties());
return parameters;
}
use of org.apache.cxf.sts.request.TokenRequirements in project cxf by apache.
the class SCTCancellerTest method testCancelToken.
/**
* Get a (valid) SecurityContextToken and successfully cancel it.
*/
@org.junit.Test
public void testCancelToken() throws Exception {
TokenCanceller sctCanceller = new SCTCanceller();
sctCanceller.setVerifyProofOfPossession(false);
TokenCancellerParameters cancellerParameters = createCancellerParameters();
TokenRequirements tokenRequirements = cancellerParameters.getTokenRequirements();
// Create a CancelTarget consisting of a SecurityContextToken
TokenProviderResponse providerResponse = getSecurityContextToken();
ReceivedToken cancelTarget = new ReceivedToken(providerResponse.getToken());
tokenRequirements.setCancelTarget(cancelTarget);
cancellerParameters.setToken(cancelTarget);
assertTrue(sctCanceller.canHandleToken(cancelTarget));
TokenCancellerResponse cancellerResponse = sctCanceller.cancelToken(cancellerParameters);
assertTrue(cancellerResponse != null);
assertTrue(cancellerResponse.getToken().getState() == STATE.CANCELLED);
// Try to cancel the token again - this should fail
cancellerResponse = sctCanceller.cancelToken(cancellerParameters);
assertTrue(cancellerResponse != null);
assertFalse(cancellerResponse.getToken().getState() == STATE.CANCELLED);
}
use of org.apache.cxf.sts.request.TokenRequirements in project cxf by apache.
the class SCTCancellerTest method testCancelInvalidToken.
/**
* Try to cancel an invalid SecurityContextToken
*/
@org.junit.Test
public void testCancelInvalidToken() throws Exception {
TokenCanceller sctCanceller = new SCTCanceller();
sctCanceller.setVerifyProofOfPossession(false);
TokenCancellerParameters cancellerParameters = createCancellerParameters();
TokenRequirements tokenRequirements = cancellerParameters.getTokenRequirements();
// Create a CancelTarget consisting of a SecurityContextToken
Document doc = DOMUtils.getEmptyDocument();
SecurityContextToken sct = new SecurityContextToken(doc);
ReceivedToken cancelTarget = new ReceivedToken(sct.getElement());
tokenRequirements.setCancelTarget(cancelTarget);
cancellerParameters.setToken(cancelTarget);
assertTrue(sctCanceller.canHandleToken(cancelTarget));
TokenCancellerResponse cancellerResponse = sctCanceller.cancelToken(cancellerParameters);
assertTrue(cancellerResponse != null);
assertFalse(cancellerResponse.getToken().getState() == STATE.CANCELLED);
}
use of org.apache.cxf.sts.request.TokenRequirements in project cxf by apache.
the class SCTCancellerTest method createProviderParameters.
private TokenProviderParameters createProviderParameters(String tokenType) throws WSSecurityException {
TokenProviderParameters parameters = new TokenProviderParameters();
TokenRequirements tokenRequirements = new TokenRequirements();
tokenRequirements.setTokenType(tokenType);
parameters.setTokenRequirements(tokenRequirements);
KeyRequirements keyRequirements = new KeyRequirements();
parameters.setKeyRequirements(keyRequirements);
parameters.setTokenStore(tokenStore);
parameters.setPrincipal(new CustomTokenPrincipal("alice"));
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
parameters.setMessageContext(msgCtx);
parameters.setAppliesToAddress("http://dummy-service.com/dummy");
// Add STSProperties object
StaticSTSProperties stsProperties = new StaticSTSProperties();
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
stsProperties.setSignatureCrypto(crypto);
stsProperties.setSignatureUsername("mystskey");
stsProperties.setCallbackHandler(new PasswordCallbackHandler());
stsProperties.setIssuer("STS");
parameters.setStsProperties(stsProperties);
parameters.setEncryptionProperties(new EncryptionProperties());
return parameters;
}
use of org.apache.cxf.sts.request.TokenRequirements in project cxf by apache.
the class CustomSubjectProvider method getSubject.
/**
* Get a SubjectBean object.
*/
public SubjectBean getSubject(SubjectProviderParameters subjectProviderParameters) {
TokenProviderParameters providerParameters = subjectProviderParameters.getProviderParameters();
TokenRequirements tokenRequirements = providerParameters.getTokenRequirements();
KeyRequirements keyRequirements = providerParameters.getKeyRequirements();
String tokenType = tokenRequirements.getTokenType();
String keyType = keyRequirements.getKeyType();
String confirmationMethod = getSubjectConfirmationMethod(tokenType, keyType);
Principal principal = providerParameters.getPrincipal();
return new SubjectBean(principal.getName(), subjectNameQualifier, confirmationMethod);
}
Aggregations