use of org.apache.cxf.sts.token.validator.X509TokenValidator in project cas by apereo.
the class CoreWsSecuritySecurityTokenServiceConfiguration method transportTokenValidators.
@RefreshScope
@Bean
public List transportTokenValidators() {
final List list = new ArrayList<>();
list.add(transportSamlTokenValidator());
list.add(new X509TokenValidator());
return list;
}
use of org.apache.cxf.sts.token.validator.X509TokenValidator in project cxf by apache.
the class DefaultSecurityTokenServiceProvider method populateAbstractOperation.
private void populateAbstractOperation(AbstractOperation abstractOperation) {
if (stsProperties == null) {
LOG.warning("No 'stsProperties' configured on the DefaultSecurityTokenServiceProvider");
return;
}
List<TokenProvider> tokenProviders = new ArrayList<>();
tokenProviders.add(new SAMLTokenProvider());
List<TokenValidator> tokenValidators = new ArrayList<>();
tokenValidators.add(new SAMLTokenValidator());
tokenValidators.add(new UsernameTokenValidator());
tokenValidators.add(new X509TokenValidator());
abstractOperation.setTokenProviders(tokenProviders);
abstractOperation.setTokenValidators(tokenValidators);
abstractOperation.setStsProperties(stsProperties);
abstractOperation.setEncryptIssuedToken(encryptIssuedToken);
abstractOperation.setServices(services);
abstractOperation.setReturnReferences(returnReferences);
abstractOperation.setTokenStore(tokenStore);
abstractOperation.setClaimsManager(claimsManager);
abstractOperation.setEventListener(eventListener);
}
use of org.apache.cxf.sts.token.validator.X509TokenValidator in project cxf by apache.
the class ValidateX509TokenUnitTest method testValidateX509Token.
/**
* Test to successfully validate an X.509 token
*/
@org.junit.Test
public void testValidateX509Token() throws Exception {
TokenValidateOperation validateOperation = new TokenValidateOperation();
// Add Token Validator
validateOperation.setTokenValidators(Collections.singletonList(new X509TokenValidator()));
// Add STSProperties object
STSPropertiesMBean stsProperties = new StaticSTSProperties();
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
stsProperties.setEncryptionCrypto(crypto);
stsProperties.setSignatureCrypto(crypto);
stsProperties.setEncryptionUsername("myservicekey");
stsProperties.setSignatureUsername("mystskey");
stsProperties.setCallbackHandler(new PasswordCallbackHandler());
stsProperties.setIssuer("STS");
validateOperation.setStsProperties(stsProperties);
// Mock up a request
RequestSecurityTokenType request = new RequestSecurityTokenType();
JAXBElement<String> tokenType = new JAXBElement<String>(QNameConstants.TOKEN_TYPE, String.class, STSConstants.STATUS);
request.getAny().add(tokenType);
// Create a BinarySecurityToken
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias("myclientkey");
X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
assertTrue(certs != null && certs.length > 0);
JAXBElement<BinarySecurityTokenType> binarySecurityTokenType = createBinarySecurityToken(certs[0]);
ValidateTargetType validateTarget = new ValidateTargetType();
validateTarget.setAny(binarySecurityTokenType);
JAXBElement<ValidateTargetType> validateTargetType = new JAXBElement<ValidateTargetType>(QNameConstants.VALIDATE_TARGET, ValidateTargetType.class, validateTarget);
request.getAny().add(validateTargetType);
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
Principal principal = new CustomTokenPrincipal("alice");
msgCtx.put(SecurityContext.class.getName(), createSecurityContext(principal));
// Validate a token
RequestSecurityTokenResponseType response = validateOperation.validate(request, principal, msgCtx);
assertTrue(validateResponse(response));
}
use of org.apache.cxf.sts.token.validator.X509TokenValidator in project cxf by apache.
the class ValidateX509TokenUnitTest method testValidateInvalidX509Token.
/**
* Test to validate an invalid X.509 token
*/
@org.junit.Test
public void testValidateInvalidX509Token() throws Exception {
TokenValidateOperation validateOperation = new TokenValidateOperation();
// Add Token Validator
validateOperation.setTokenValidators(Collections.singletonList(new X509TokenValidator()));
// Add STSProperties object
STSPropertiesMBean stsProperties = new StaticSTSProperties();
Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
stsProperties.setEncryptionCrypto(crypto);
stsProperties.setSignatureCrypto(crypto);
stsProperties.setEncryptionUsername("myservicekey");
stsProperties.setSignatureUsername("mystskey");
stsProperties.setCallbackHandler(new PasswordCallbackHandler());
stsProperties.setIssuer("STS");
validateOperation.setStsProperties(stsProperties);
// Mock up a request
RequestSecurityTokenType request = new RequestSecurityTokenType();
JAXBElement<String> tokenType = new JAXBElement<String>(QNameConstants.TOKEN_TYPE, String.class, STSConstants.STATUS);
request.getAny().add(tokenType);
// Create a BinarySecurityToken
CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
cryptoType.setAlias("eve");
Crypto eveCrypto = CryptoFactory.getInstance(getEveCryptoProperties());
X509Certificate[] certs = eveCrypto.getX509Certificates(cryptoType);
assertTrue(certs != null && certs.length > 0);
JAXBElement<BinarySecurityTokenType> binarySecurityTokenType = createBinarySecurityToken(certs[0]);
ValidateTargetType validateTarget = new ValidateTargetType();
validateTarget.setAny(binarySecurityTokenType);
JAXBElement<ValidateTargetType> validateTargetType = new JAXBElement<ValidateTargetType>(QNameConstants.VALIDATE_TARGET, ValidateTargetType.class, validateTarget);
request.getAny().add(validateTargetType);
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
Principal principal = new CustomTokenPrincipal("alice");
msgCtx.put(SecurityContext.class.getName(), createSecurityContext(principal));
// Validate a token
RequestSecurityTokenResponseType response = validateOperation.validate(request, principal, msgCtx);
assertFalse(validateResponse(response));
}
Aggregations