List<SecurityToken> securityTokens = new LinkedList<SecurityToken>();
for (int i = 0; i < tokenUsages.size(); i++) {
WSSecurityTokenConstants.TokenUsage tokenUsage = tokenUsages.get(i);
X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent();
X509SecurityTokenImpl securityToken = getX509Token(WSSecurityTokenConstants.X509V3Token);
securityTokens.add(securityToken);
securityToken.setElementPath(bstPath);
securityToken.addTokenUsage(tokenUsage);
x509TokenSecurityEvent.setSecurityToken(securityToken);
policyEnforcer.registerSecurityEvent(x509TokenSecurityEvent);
if (tokenUsage.getName().contains("Signature") || tokenUsage.getName().contains("Endorsing")) {
SignedElementSecurityEvent signedElementSecurityEvent = new SignedElementSecurityEvent(securityToken, true, protectionOrder);
signedElementSecurityEvent.setElementPath(bstPath);
policyEnforcer.registerSecurityEvent(signedElementSecurityEvent);
}
if (tokenUsage.getName().contains("Endorsing")) {
SignedElementSecurityEvent signedElementSecurityEvent = new SignedElementSecurityEvent(securityToken, true, protectionOrder);
signedElementSecurityEvent.setElementPath(sigPath);
policyEnforcer.registerSecurityEvent(signedElementSecurityEvent);
}
}
SecurityToken mainSignatureToken = null;
Iterator<SecurityToken> securityTokenIterator = securityTokens.iterator();
while (securityTokenIterator.hasNext()) {
SecurityToken securityToken = securityTokenIterator.next();
if (securityToken.getTokenUsages().contains(WSSecurityTokenConstants.TokenUsage_MainSignature)) {
mainSignatureToken = securityToken;
break;
}
}
securityTokenIterator = securityTokens.iterator();
while (securityTokenIterator.hasNext()) {
SecurityToken securityToken = securityTokenIterator.next();
if (securityToken.getTokenUsages().get(0).getName().contains("Signed")) {
SignedElementSecurityEvent signedElementSecurityEvent =
new SignedElementSecurityEvent((InboundSecurityToken)mainSignatureToken, true, protectionOrder);
signedElementSecurityEvent.setElementPath(bstPath);
policyEnforcer.registerSecurityEvent(signedElementSecurityEvent);
}