//this code need not be called for UT
setTokenInclusion(untBinding,(Token) tokenAssertion);
setTokenValueType(untBinding, tokenAssertion);
untBinding.isOptional(tokenAssertion.isOptional());
if(unToken.getIssuer() != null){
Address addr = unToken.getIssuer().getAddress();
if(addr != null)
untBinding.setIssuer(addr.getURI().toString());
} else if(unToken.getIssuerName() != null){
untBinding.setIssuer(unToken.getIssuerName().getIssuerName());
}
if(unToken.getClaims() != null){
untBinding.setClaims(unToken.getClaims().getClaimsAsBytes());
}
untBinding.setUseCreated(unToken.useCreated());
untBinding.setUseNonce(unToken.useNonce());
if (!ignoreDK && unToken.isRequireDerivedKeys()) {
DerivedTokenKeyBinding dtKB = new DerivedTokenKeyBinding();
//Support for PasswordDerivedKeys
if ((binding instanceof AsymmetricBinding) && (((AsymmetricBinding) binding).getInitiatorToken() != null)) {
skb.setKeyBinding(untBinding);
dtKB.setOriginalKeyBinding(skb);
policy.setKeyBinding(dtKB);
} else {
dtKB.setOriginalKeyBinding(untBinding);
policy.setKeyBinding(dtKB);
}
dtKB.setUUID(pid.generateID());
} else if (unToken.isRequireDerivedKeys()) {
DerivedTokenKeyBinding dtKB = new DerivedTokenKeyBinding();
if ((binding instanceof AsymmetricBinding) && (((AsymmetricBinding) binding).getInitiatorToken() != null)) {
skb.setKeyBinding(untBinding);
dtKB.setOriginalKeyBinding(skb);
policy.setKeyBinding(dtKB);
} else {
dtKB.setOriginalKeyBinding(untBinding);
policy.setKeyBinding(dtKB);
}
dtKB.setUUID(pid.generateID());
} else {
if ((binding instanceof AsymmetricBinding) && (((AsymmetricBinding) binding).getInitiatorToken() != null)) {
skb.setKeyBinding(untBinding);
policy.setKeyBinding(skb);
} else {
policy.setKeyBinding(untBinding);
}
}
}else if(PolicyUtil.isX509Token(tokenAssertion, spVersion)){
AuthenticationTokenPolicy.X509CertificateBinding x509CB =new AuthenticationTokenPolicy.X509CertificateBinding();
// (AuthenticationTokenPolicy.X509CertificateBinding)policy.newX509CertificateKeyBinding();
X509Token x509Token = (X509Token)tokenAssertion;
x509CB.setUUID(token.getTokenId());
setX509TokenRefType(x509CB, x509Token);
setTokenInclusion(x509CB,(Token) tokenAssertion);
setTokenValueType(x509CB, tokenAssertion);
x509CB.isOptional(tokenAssertion.isOptional());
if(x509Token.getIssuer() != null){
Address addr = x509Token.getIssuer().getAddress();
if(addr != null)
x509CB.setIssuer(addr.getURI().toString());
} else if(x509Token.getIssuerName() != null){
x509CB.setIssuer(x509Token.getIssuerName().getIssuerName());
}
if(x509Token.getClaims() != null){
x509CB.setClaims(x509Token.getClaims().getClaimsAsBytes());
}
//x509CB.setPolicyToken(token);
if(!ignoreDK && x509Token.isRequireDerivedKeys()){
DerivedTokenKeyBinding dtKB = new DerivedTokenKeyBinding();
dtKB.setOriginalKeyBinding(x509CB);
policy.setKeyBinding(dtKB);
dtKB.setUUID(pid.generateID());
}else{
policy.setKeyBinding(x509CB);
}
}else if(PolicyUtil.isSamlToken(tokenAssertion, spVersion)){
AuthenticationTokenPolicy.SAMLAssertionBinding sab = new AuthenticationTokenPolicy.SAMLAssertionBinding();
//(AuthenticationTokenPolicy.SAMLAssertionBinding)policy.newSAMLAssertionKeyBinding();
SamlToken samlToken = (SamlToken)tokenAssertion;
sab.setUUID(token.getTokenId());
sab.setSTRID(token.getTokenId());
sab.setReferenceType(MessageConstants.DIRECT_REFERENCE_TYPE);
setTokenInclusion(sab,(Token) tokenAssertion);
sab.isOptional(tokenAssertion.isOptional());
//sab.setPolicyToken((Token) tokenAssertion);
if(samlToken.getIssuer() != null){
Address addr = samlToken.getIssuer().getAddress();
if(addr != null)
sab.setIssuer(addr.getURI().toString());
} else if(samlToken.getIssuerName() != null){
sab.setIssuer(samlToken.getIssuerName().getIssuerName());
}
if(samlToken.getClaims() != null){
sab.setClaims(samlToken.getClaims().getClaimsAsBytes());
}
if(samlToken.isRequireDerivedKeys()){
DerivedTokenKeyBinding dtKB = new DerivedTokenKeyBinding();
dtKB.setOriginalKeyBinding(sab);
policy.setKeyBinding(dtKB);
dtKB.setUUID(pid.generateID());
}else{
policy.setKeyBinding(sab);
}
}else if(PolicyUtil.isIssuedToken(tokenAssertion, spVersion)){
IssuedTokenKeyBinding itkb = new IssuedTokenKeyBinding();
setTokenInclusion(itkb,(Token) tokenAssertion);
//itkb.setPolicyToken((Token) tokenAssertion);
itkb.setUUID(((Token)tokenAssertion).getTokenId());
itkb.setSTRID(token.getTokenId());
IssuedToken it = (IssuedToken)tokenAssertion;
itkb.isOptional(tokenAssertion.isOptional());
if (it.getRequestSecurityTokenTemplate() != null) {
itkb.setTokenType(it.getRequestSecurityTokenTemplate().getTokenType());
}
if(it.getIssuer() != null){
Address addr = it.getIssuer().getAddress();
if(addr != null)
itkb.setIssuer(addr.getURI().toString());
} else if(it.getIssuerName() != null){
itkb.setIssuer(it.getIssuerName().getIssuerName());
}
if(it.getClaims() != null){
itkb.setClaims(it.getClaims().getClaimsAsBytes());
}
if(it.isRequireDerivedKeys()){
DerivedTokenKeyBinding dtKB = new DerivedTokenKeyBinding();
dtKB.setOriginalKeyBinding(itkb);
policy.setKeyBinding(dtKB);
dtKB.setUUID(pid.generateID());
}else{
policy.setKeyBinding(itkb);
}
}else if(PolicyUtil.isSecureConversationToken(tokenAssertion, spVersion)){
SecureConversationTokenKeyBinding sct = new SecureConversationTokenKeyBinding();
SecureConversationToken sctPolicy = (SecureConversationToken)tokenAssertion;
sct.isOptional(tokenAssertion.isOptional());
if(sctPolicy.getIssuer() != null){
Address addr = sctPolicy.getIssuer().getAddress();
if(addr != null)
sct.setIssuer(addr.getURI().toString());
} else if(sctPolicy.getIssuerName() != null){
sct.setIssuer(sctPolicy.getIssuerName().getIssuerName());
}
if(sctPolicy.getClaims() != null){
sct.setClaims(sctPolicy.getClaims().getClaimsAsBytes());
}
if(sctPolicy.isRequireDerivedKeys()){
DerivedTokenKeyBinding dtKB = new DerivedTokenKeyBinding();
dtKB.setOriginalKeyBinding(sct);
policy.setKeyBinding(dtKB);
dtKB.setUUID(pid.generateID());
}else{
policy.setKeyBinding(sct);
}
setTokenInclusion(sct,(Token) tokenAssertion);
//sct.setPolicyToken((Token)tokenAssertion);
sct.setUUID(((Token)tokenAssertion).getTokenId());
} else if (PolicyUtil.isKerberosToken(tokenAssertion, spVersion)) {
AuthenticationTokenPolicy.KerberosTokenBinding kerbBinding =new AuthenticationTokenPolicy.KerberosTokenBinding();
KerberosToken kerbToken = (KerberosToken)tokenAssertion;
kerbBinding.setUUID(token.getTokenId());
setTokenInclusion(kerbBinding,(Token) tokenAssertion);
setTokenValueType(kerbBinding, tokenAssertion);
kerbBinding.isOptional(tokenAssertion.isOptional());
if(kerbToken.getIssuer() != null){
Address addr = kerbToken.getIssuer().getAddress();
if(addr != null)
kerbBinding.setIssuer(addr.getURI().toString());
} else if(kerbToken.getIssuerName() != null){
kerbBinding.setIssuer(kerbToken.getIssuerName().getIssuerName());
}
if(kerbToken.getClaims() != null){