public void registerSecurityEvent(SecurityEvent securityEvent) throws WSSecurityException {
securityEventList.add(securityEvent);
}
};
InboundWSSecurityContextImpl inboundWSSecurityContext = new InboundWSSecurityContextImpl();
inboundWSSecurityContext.addSecurityEventListener(securityEventListener);
TimestampSecurityEvent timestampSecurityEvent = new TimestampSecurityEvent();
inboundWSSecurityContext.registerSecurityEvent(timestampSecurityEvent);
List<QName> timestampPath = new LinkedList<QName>();
timestampPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
timestampPath.add(WSSConstants.TAG_wsu_Timestamp);
RequiredElementSecurityEvent timestampRequiredElementSecurityEvent = new RequiredElementSecurityEvent();
timestampRequiredElementSecurityEvent.setElementPath(timestampPath);
inboundWSSecurityContext.registerSecurityEvent(timestampRequiredElementSecurityEvent);
SignatureConfirmationSecurityEvent signatureConfirmationSecurityEvent = new SignatureConfirmationSecurityEvent();
inboundWSSecurityContext.registerSecurityEvent(signatureConfirmationSecurityEvent);
List<QName> scPath = new LinkedList<QName>();
scPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
scPath.add(WSSConstants.TAG_wsse11_SignatureConfirmation);
RequiredElementSecurityEvent scRequiredElementSecurityEvent = new RequiredElementSecurityEvent();
scRequiredElementSecurityEvent.setElementPath(scPath);
inboundWSSecurityContext.registerSecurityEvent(scRequiredElementSecurityEvent);
List<QName> samlTokenPath = new LinkedList<QName>();
samlTokenPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
samlTokenPath.add(WSSConstants.TAG_saml2_Assertion);
XMLSecEvent samlTokenXmlEvent = XMLSecEventFactory.createXmlSecStartElement(WSSConstants.TAG_wsse_UsernameToken, null, null);
SAMLCallback samlCallback = new SAMLCallback();
samlCallback.setSamlVersion(SAMLVersion.VERSION_20);
samlCallback.setIssuer("xs:anyURI");
SubjectBean subjectBean = new SubjectBean();
samlCallback.setSubject(subjectBean);
SamlAssertionWrapper samlAssertionWrapper = new SamlAssertionWrapper(samlCallback);
SamlSecurityTokenImpl samlSecurityToken = new SamlSecurityTokenImpl(
samlAssertionWrapper, getX509Token(WSSecurityTokenConstants.X509V3Token), null, null, WSSecurityTokenConstants.KeyIdentifier_X509KeyIdentifier,
null);
samlSecurityToken.setElementPath(samlTokenPath);
samlSecurityToken.setXMLSecEvent(samlTokenXmlEvent);
samlSecurityToken.addTokenUsage(WSSecurityTokenConstants.TokenUsage_Encryption);
SamlTokenSecurityEvent samlTokenSecurityEvent = new SamlTokenSecurityEvent();
samlTokenSecurityEvent.setSecurityToken(samlSecurityToken);
inboundWSSecurityContext.registerSecurityEvent(samlTokenSecurityEvent);
List<XMLSecurityConstants.ContentType> protectionOrder = new LinkedList<XMLSecurityConstants.ContentType>();
protectionOrder.add(XMLSecurityConstants.ContentType.ENCRYPTION);
protectionOrder.add(XMLSecurityConstants.ContentType.SIGNATURE);
List<QName> usernamePath = new LinkedList<QName>();
usernamePath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
usernamePath.add(WSSConstants.TAG_wsse_UsernameToken);
XMLSecEvent usernameTokenXmlEvent = XMLSecEventFactory.createXmlSecStartElement(WSSConstants.TAG_wsse_UsernameToken, null, null);
EncryptedElementSecurityEvent usernameEncryptedElementSecurityEvent = new EncryptedElementSecurityEvent(samlSecurityToken, true, protectionOrder);
usernameEncryptedElementSecurityEvent.setElementPath(usernamePath);
usernameEncryptedElementSecurityEvent.setXmlSecEvent(usernameTokenXmlEvent);
inboundWSSecurityContext.registerSecurityEvent(usernameEncryptedElementSecurityEvent);
List<QName> usernameTokenPath = new LinkedList<QName>();
usernameTokenPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
usernameTokenPath.add(WSSConstants.TAG_wsse_UsernameToken);
UsernameTokenSecurityEvent usernameTokenSecurityEvent = new UsernameTokenSecurityEvent();
UsernameSecurityTokenImpl usernameSecurityToken = new UsernameSecurityTokenImpl(
WSSConstants.UsernameTokenPasswordType.PASSWORD_TEXT,
"username", "password", new Date().toString(), null, new byte[10], 10L,
null, IDGenerator.generateID(null), WSSecurityTokenConstants.KeyIdentifier_SecurityTokenDirectReference);
usernameSecurityToken.setElementPath(usernamePath);
usernameSecurityToken.setXMLSecEvent(usernameTokenXmlEvent);
usernameTokenSecurityEvent.setSecurityToken(usernameSecurityToken);
inboundWSSecurityContext.registerSecurityEvent(usernameTokenSecurityEvent);
List<QName> signaturePath = new LinkedList<QName>();
signaturePath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
signaturePath.add(WSSConstants.TAG_dsig_Signature);
EncryptedElementSecurityEvent signatureEncryptedElementSecurityEvent = new EncryptedElementSecurityEvent(samlSecurityToken, true, protectionOrder);
signatureEncryptedElementSecurityEvent.setElementPath(signaturePath);
inboundWSSecurityContext.registerSecurityEvent(signatureEncryptedElementSecurityEvent);
samlSecurityToken.addTokenUsage(WSSecurityTokenConstants.TokenUsage_Signature);
samlTokenSecurityEvent = new SamlTokenSecurityEvent();
samlTokenSecurityEvent.setSecurityToken(samlSecurityToken);
inboundWSSecurityContext.registerSecurityEvent(samlTokenSecurityEvent);
SignatureValueSecurityEvent signatureValueSecurityEvent = new SignatureValueSecurityEvent();
inboundWSSecurityContext.registerSecurityEvent(signatureValueSecurityEvent);
SignedElementSecurityEvent signedTimestampElementSecurityEvent = new SignedElementSecurityEvent(samlSecurityToken, true, protectionOrder);
signedTimestampElementSecurityEvent.setElementPath(timestampPath);
inboundWSSecurityContext.registerSecurityEvent(signedTimestampElementSecurityEvent);
SignedElementSecurityEvent signedSCElementSecurityEvent = new SignedElementSecurityEvent(samlSecurityToken, true, protectionOrder);
signedSCElementSecurityEvent.setElementPath(scPath);
inboundWSSecurityContext.registerSecurityEvent(signedSCElementSecurityEvent);
SignedElementSecurityEvent signedUsernameTokenElementSecurityEvent = new SignedElementSecurityEvent(samlSecurityToken, true, protectionOrder);
signedUsernameTokenElementSecurityEvent.setElementPath(usernameTokenPath);
signedUsernameTokenElementSecurityEvent.setXmlSecEvent(usernameTokenXmlEvent);
inboundWSSecurityContext.registerSecurityEvent(signedUsernameTokenElementSecurityEvent);
List<QName> bstPath = new LinkedList<QName>();
bstPath.addAll(WSSConstants.WSSE_SECURITY_HEADER_PATH);
bstPath.add(WSSConstants.TAG_wsse_BinarySecurityToken);
XMLSecEvent bstTokenXmlEvent = XMLSecEventFactory.createXmlSecStartElement(WSSConstants.TAG_wsse_UsernameToken, null, null);
SignedElementSecurityEvent bstElementSecurityEvent = new SignedElementSecurityEvent(samlSecurityToken, true, protectionOrder);
bstElementSecurityEvent.setElementPath(bstPath);
bstElementSecurityEvent.setXmlSecEvent(bstTokenXmlEvent);
inboundWSSecurityContext.registerSecurityEvent(bstElementSecurityEvent);
SignedElementSecurityEvent samlTokenElementSecurityEvent = new SignedElementSecurityEvent(samlSecurityToken, true, protectionOrder);
samlTokenElementSecurityEvent.setElementPath(samlTokenPath);
samlTokenElementSecurityEvent.setXmlSecEvent(samlTokenXmlEvent);
inboundWSSecurityContext.registerSecurityEvent(samlTokenElementSecurityEvent);
List<QName> header1Path = new LinkedList<QName>();
header1Path.addAll(WSSConstants.SOAP_11_HEADER_PATH);
header1Path.add(new QName("x", "Header1", "x"));
SignedPartSecurityEvent header1SignedPartSecurityEvent = new SignedPartSecurityEvent(samlSecurityToken, true, protectionOrder);
header1SignedPartSecurityEvent.setElementPath(header1Path);
inboundWSSecurityContext.registerSecurityEvent(header1SignedPartSecurityEvent);
List<QName> header2Path = new LinkedList<QName>();
header2Path.addAll(WSSConstants.SOAP_11_HEADER_PATH);
header2Path.add(new QName("x", "Header1", "x"));
SignedPartSecurityEvent header2SignedPartSecurityEvent = new SignedPartSecurityEvent(samlSecurityToken, true, protectionOrder);
header2SignedPartSecurityEvent.setElementPath(header2Path);
inboundWSSecurityContext.registerSecurityEvent(header2SignedPartSecurityEvent);
List<QName> bodyPath = new LinkedList<QName>();
bodyPath.addAll(WSSConstants.SOAP_11_BODY_PATH);
SignedPartSecurityEvent bodySignedPartSecurityEvent = new SignedPartSecurityEvent(samlSecurityToken, true, protectionOrder);
bodySignedPartSecurityEvent.setElementPath(bodyPath);
inboundWSSecurityContext.registerSecurityEvent(bodySignedPartSecurityEvent);
X509TokenSecurityEvent x509TokenSecurityEvent = new X509TokenSecurityEvent();
X509SecurityTokenImpl signedEndorsingSupportingToken = getX509Token(WSSecurityTokenConstants.X509V3Token);
x509TokenSecurityEvent.setSecurityToken(signedEndorsingSupportingToken);
signedEndorsingSupportingToken.setElementPath(bstPath);
signedEndorsingSupportingToken.setXMLSecEvent(bstTokenXmlEvent);
signedEndorsingSupportingToken.addTokenUsage(WSSecurityTokenConstants.TokenUsage_Signature);
inboundWSSecurityContext.registerSecurityEvent(x509TokenSecurityEvent);
SignatureValueSecurityEvent signature2ValueSecurityEvent = new SignatureValueSecurityEvent();
inboundWSSecurityContext.registerSecurityEvent(signature2ValueSecurityEvent);
SignedElementSecurityEvent signatureElementSecurityEvent = new SignedElementSecurityEvent(signedEndorsingSupportingToken, true, protectionOrder);
signatureElementSecurityEvent.setElementPath(signaturePath);
inboundWSSecurityContext.registerSecurityEvent(signatureElementSecurityEvent);
bstElementSecurityEvent = new SignedElementSecurityEvent(signedEndorsingSupportingToken, true, protectionOrder);
bstElementSecurityEvent.setElementPath(bstPath);
bstElementSecurityEvent.setXmlSecEvent(bstTokenXmlEvent);
inboundWSSecurityContext.registerSecurityEvent(bstElementSecurityEvent);
EncryptedPartSecurityEvent header2EncryptedPartSecurityEvent = new EncryptedPartSecurityEvent(samlSecurityToken, true, protectionOrder);
header2EncryptedPartSecurityEvent.setElementPath(header2Path);
inboundWSSecurityContext.registerSecurityEvent(header2EncryptedPartSecurityEvent);
EncryptedPartSecurityEvent bodyEncryptedPartSecurityEvent = new EncryptedPartSecurityEvent(samlSecurityToken, true, protectionOrder);
bodyEncryptedPartSecurityEvent.setElementPath(bodyPath);
inboundWSSecurityContext.registerSecurityEvent(bodyEncryptedPartSecurityEvent);
OperationSecurityEvent operationSecurityEvent = new OperationSecurityEvent();
operationSecurityEvent.setOperation(new QName("definitions"));
inboundWSSecurityContext.registerSecurityEvent(operationSecurityEvent);
return securityEventList;
}