use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.
the class SamlRoleCallbackHandler method handle.
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof SAMLCallback) {
SAMLCallback callback = (SAMLCallback) callbacks[i];
if (saml2) {
callback.setSamlVersion(Version.SAML_20);
} else {
callback.setSamlVersion(Version.SAML_11);
}
callback.setIssuer("sts");
String subjectName = "uid=sts-client,o=mock-sts.com";
String subjectQualifier = "www.mock-sts.com";
if (!saml2 && SAML2Constants.CONF_SENDER_VOUCHES.equals(confirmationMethod)) {
confirmationMethod = SAML1Constants.CONF_SENDER_VOUCHES;
}
SubjectBean subjectBean = new SubjectBean(subjectName, subjectQualifier, confirmationMethod);
if (SAML2Constants.CONF_HOLDER_KEY.equals(confirmationMethod) || SAML1Constants.CONF_HOLDER_KEY.equals(confirmationMethod)) {
try {
KeyInfoBean keyInfo = createKeyInfo();
subjectBean.setKeyInfo(keyInfo);
} catch (Exception ex) {
throw new IOException("Problem creating KeyInfo: " + ex.getMessage());
}
}
callback.setSubject(subjectBean);
AttributeStatementBean attrBean = new AttributeStatementBean();
attrBean.setSubject(subjectBean);
AttributeBean attributeBean = new AttributeBean();
attributeBean.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_UNSPECIFIED);
if (saml2) {
attributeBean.setQualifiedName(ROLE_URI);
attributeBean.setNameFormat(SAML2Constants.ATTRNAME_FORMAT_UNSPECIFIED);
} else {
String uri = ROLE_URI.toString();
int lastSlash = uri.lastIndexOf("/");
if (lastSlash == (uri.length() - 1)) {
uri = uri.substring(0, lastSlash);
lastSlash = uri.lastIndexOf("/");
}
String namespace = uri.substring(0, lastSlash);
String name = uri.substring(lastSlash + 1, uri.length());
attributeBean.setSimpleName(name);
attributeBean.setQualifiedName(namespace);
}
attributeBean.addAttributeValue(roleName);
attrBean.setSamlAttributes(Collections.singletonList(attributeBean));
callback.setAttributeStatementData(Collections.singletonList(attrBean));
try {
Crypto crypto = CryptoFactory.getInstance(cryptoPropertiesFile);
callback.setIssuerCrypto(crypto);
callback.setIssuerKeyName(cryptoAlias);
callback.setIssuerKeyPassword(cryptoPassword);
callback.setSignAssertion(signAssertion);
} catch (Exception ex) {
throw new IOException("Problem creating KeyInfo: " + ex.getMessage());
}
}
}
}
use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.
the class ActAsAttributeStatementProvider method getStatement.
/**
* Get an AttributeStatementBean using the given parameters.
*/
public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
AttributeStatementBean attrBean = new AttributeStatementBean();
TokenRequirements tokenRequirements = providerParameters.getTokenRequirements();
ReceivedToken actAs = tokenRequirements.getActAs();
try {
if (actAs != null) {
List<AttributeBean> attributeList = new ArrayList<>();
String tokenType = tokenRequirements.getTokenType();
AttributeBean parameterBean = handleAdditionalParameters(actAs.getToken(), tokenType);
if (!parameterBean.getAttributeValues().isEmpty()) {
attributeList.add(parameterBean);
}
attrBean.setSamlAttributes(attributeList);
}
} catch (WSSecurityException ex) {
throw new STSException(ex.getMessage(), ex);
}
return attrBean;
}
use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.
the class ClaimsAttributeStatementProvider method getStatement.
public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
// Handle Claims
ProcessedClaimCollection retrievedClaims = ClaimsUtils.processClaims(providerParameters);
if (retrievedClaims == null) {
return null;
}
Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
if (!claimIterator.hasNext()) {
return null;
}
List<AttributeBean> attributeList = new ArrayList<>();
String tokenType = providerParameters.getTokenRequirements().getTokenType();
AttributeStatementBean attrBean = new AttributeStatementBean();
while (claimIterator.hasNext()) {
ProcessedClaim claim = claimIterator.next();
AttributeBean attributeBean = new AttributeBean();
URI claimType = claim.getClaimType();
if (WSS4JConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType) || WSS4JConstants.SAML2_NS.equals(tokenType)) {
attributeBean.setQualifiedName(claimType.toString());
attributeBean.setNameFormat(nameFormat);
} else {
String uri = claimType.toString();
int lastSlash = uri.lastIndexOf("/");
if (lastSlash == (uri.length() - 1)) {
uri = uri.substring(0, lastSlash);
lastSlash = uri.lastIndexOf("/");
}
String namespace = uri.substring(0, lastSlash);
String name = uri.substring(lastSlash + 1, uri.length());
attributeBean.setSimpleName(name);
attributeBean.setQualifiedName(namespace);
}
attributeBean.setAttributeValues(claim.getValues());
attributeList.add(attributeBean);
}
attrBean.setSamlAttributes(attributeList);
return attrBean;
}
use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.
the class CustomAttributeProvider method createDefaultAttribute.
/**
* Create a default attribute
*/
private AttributeBean createDefaultAttribute(String tokenType) {
AttributeBean attributeBean = new AttributeBean();
if (WSS4JConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType) || WSS4JConstants.SAML2_NS.equals(tokenType)) {
attributeBean.setQualifiedName("token-requestor");
attributeBean.setNameFormat("http://cxf.apache.org/sts/custom");
} else {
attributeBean.setSimpleName("token-requestor");
attributeBean.setQualifiedName("http://cxf.apache.org/sts/custom");
}
attributeBean.addAttributeValue("authenticated");
return attributeBean;
}
use of org.apache.wss4j.common.saml.bean.AttributeBean in project cxf by apache.
the class CustomAttributeStatementProvider method getStatement.
public AttributeStatementBean getStatement(TokenProviderParameters providerParameters) {
// Handle Claims
ClaimsManager claimsManager = providerParameters.getClaimsManager();
ProcessedClaimCollection retrievedClaims = new ProcessedClaimCollection();
if (claimsManager != null) {
ClaimsParameters params = new ClaimsParameters();
params.setAdditionalProperties(providerParameters.getAdditionalProperties());
params.setAppliesToAddress(providerParameters.getAppliesToAddress());
params.setEncryptionProperties(providerParameters.getEncryptionProperties());
params.setKeyRequirements(providerParameters.getKeyRequirements());
params.setPrincipal(providerParameters.getPrincipal());
params.setRealm(providerParameters.getRealm());
params.setStsProperties(providerParameters.getStsProperties());
params.setTokenRequirements(providerParameters.getTokenRequirements());
params.setTokenStore(providerParameters.getTokenStore());
params.setMessageContext(providerParameters.getMessageContext());
retrievedClaims = claimsManager.retrieveClaimValues(providerParameters.getRequestedPrimaryClaims(), providerParameters.getRequestedSecondaryClaims(), params);
}
if (retrievedClaims == null) {
return null;
}
Iterator<ProcessedClaim> claimIterator = retrievedClaims.iterator();
if (!claimIterator.hasNext()) {
return null;
}
List<AttributeBean> attributeList = new ArrayList<>();
String tokenType = providerParameters.getTokenRequirements().getTokenType();
AttributeStatementBean attrBean = new AttributeStatementBean();
while (claimIterator.hasNext()) {
ProcessedClaim claim = claimIterator.next();
AttributeBean attributeBean = new AttributeBean();
URI claimType = claim.getClaimType();
if (WSS4JConstants.WSS_SAML2_TOKEN_TYPE.equals(tokenType) || WSS4JConstants.SAML2_NS.equals(tokenType)) {
attributeBean.setQualifiedName(claimType.toString());
attributeBean.setNameFormat(nameFormat);
} else {
String uri = claimType.toString();
int lastSlash = uri.lastIndexOf("/");
if (lastSlash == (uri.length() - 1)) {
uri = uri.substring(0, lastSlash);
lastSlash = uri.lastIndexOf("/");
}
String namespace = uri.substring(0, lastSlash);
String name = uri.substring(lastSlash + 1, uri.length());
attributeBean.setSimpleName(name);
attributeBean.setQualifiedName(namespace);
}
attributeBean.setAttributeValues(claim.getValues());
attributeList.add(attributeBean);
}
attrBean.setSamlAttributes(attributeList);
return attrBean;
}
Aggregations