use of org.apache.cxf.sts.token.provider.TokenProviderParameters in project cxf by apache.
the class DefaultJWTClaimsProvider method handleWSTrustClaims.
protected void handleWSTrustClaims(JWTClaimsProviderParameters jwtClaimsProviderParameters, JwtClaims claims) {
TokenProviderParameters providerParameters = jwtClaimsProviderParameters.getProviderParameters();
// Handle Claims
ProcessedClaimCollection retrievedClaims = ClaimsUtils.processClaims(providerParameters);
if (retrievedClaims != null) {
Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
while (claimIterator.hasNext()) {
ProcessedClaim claim = claimIterator.next();
if (claim.getClaimType() != null && claim.getValues() != null && !claim.getValues().isEmpty()) {
Object claimValues = claim.getValues();
if (claim.getValues().size() == 1) {
claimValues = claim.getValues().get(0);
}
claims.setProperty(translateClaim(claim.getClaimType().toString()), claimValues);
}
}
}
}
use of org.apache.cxf.sts.token.provider.TokenProviderParameters in project cxf by apache.
the class SAMLTokenRenewer method convertToProviderParameters.
private TokenProviderParameters convertToProviderParameters(TokenRenewerParameters renewerParameters) {
TokenProviderParameters providerParameters = new TokenProviderParameters();
providerParameters.setAppliesToAddress(renewerParameters.getAppliesToAddress());
providerParameters.setEncryptionProperties(renewerParameters.getEncryptionProperties());
providerParameters.setKeyRequirements(renewerParameters.getKeyRequirements());
providerParameters.setPrincipal(renewerParameters.getPrincipal());
providerParameters.setRealm(renewerParameters.getRealm());
providerParameters.setStsProperties(renewerParameters.getStsProperties());
providerParameters.setTokenRequirements(renewerParameters.getTokenRequirements());
providerParameters.setTokenStore(renewerParameters.getTokenStore());
providerParameters.setMessageContext(renewerParameters.getMessageContext());
// Store token to renew in the additional properties in case you want to base some
// Conditions on the token
Map<String, Object> additionalProperties = renewerParameters.getAdditionalProperties();
if (additionalProperties == null) {
additionalProperties = new HashMap<>(1);
}
additionalProperties.put(ReceivedToken.class.getName(), renewerParameters.getToken());
providerParameters.setAdditionalProperties(additionalProperties);
return providerParameters;
}
use of org.apache.cxf.sts.token.provider.TokenProviderParameters in project cxf by apache.
the class JexlIssueSamlClaimsTest 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.token.provider.TokenProviderParameters in project cxf by apache.
the class IssueJWTClaimsUnitTest method createSAMLAssertion.
/*
* Mock up an SAML assertion element
*/
private Element createSAMLAssertion(String tokenType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler, Map<String, RealmProperties> realms) throws WSSecurityException {
SAMLTokenProvider samlTokenProvider = new SAMLTokenProvider();
samlTokenProvider.setRealmMap(realms);
List<AttributeStatementProvider> customProviderList = new ArrayList<>();
customProviderList.add(new ClaimsAttributeStatementProvider());
samlTokenProvider.setAttributeStatementProviders(customProviderList);
TokenProviderParameters providerParameters = createProviderParameters(tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler);
if (realms != null) {
providerParameters.setRealm("A");
}
// Set the ClaimsManager
ClaimsManager claimsManager = new ClaimsManager();
ClaimsHandler claimsHandler = new CustomClaimsHandler();
claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
providerParameters.setClaimsManager(claimsManager);
ClaimCollection requestedClaims = new ClaimCollection();
Claim requestClaim = new Claim();
requestClaim.setClaimType(ClaimTypes.LASTNAME);
requestClaim.setOptional(false);
requestedClaims.add(requestClaim);
providerParameters.setRequestedSecondaryClaims(requestedClaims);
TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
assertTrue(providerResponse != null);
assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId() != null);
return (Element) providerResponse.getToken();
}
use of org.apache.cxf.sts.token.provider.TokenProviderParameters in project cxf by apache.
the class IssueJWTClaimsUnitTest 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;
}
Aggregations