WSSCPluginpublic class WSSCPlugin extends Object
Fields Summary |
---|
com.sun.xml.ws.security.trust.Configuration | config | private static final Logger | log | private static com.sun.xml.ws.security.trust.WSTrustElementFactory | eleFac | private static final int | DEFAULT_KEY_SIZE | private static final String | SC_ASSERTION | private static final String | FOR_CANCEL | private com.sun.xml.ws.api.message.Packet | packet |
Methods Summary |
---|
private com.sun.xml.ws.api.message.Packet | addAddressingHeaders(com.sun.xml.ws.api.message.Packet packet, com.sun.xml.ws.api.model.wsdl.WSDLPort wsdlPort, com.sun.xml.ws.api.WSBinding binding, java.lang.String action, com.sun.xml.ws.api.addressing.AddressingVersion addVer)
final HeaderList list = packet.getMessage().getHeaders();
list.fillRequestAddressingHeaders(packet, addVer,binding.getSOAPVersion(),false,action);
return packet;
| private com.sun.xml.ws.security.trust.elements.RequestSecurityToken | createRequestSecurityToken(boolean reqClientEntropy, int skl)
final URI tokenType = URI.create(WSSCConstants.SECURITY_CONTEXT_TOKEN_TYPE);
final URI requestType = URI.create(WSTrustConstants.ISSUE_REQUEST);
final SecureRandom random = new SecureRandom();
final byte[] rawValue = new byte[skl/8];
random.nextBytes(rawValue);
final BinarySecret secret = eleFac.createBinarySecret(rawValue, BinarySecret.NONCE_KEY_TYPE);
final Entropy entropy = reqClientEntropy?eleFac.createEntropy(secret):null;
RequestSecurityToken rst = null;
try {
rst = eleFac.createRSTForIssue(tokenType, requestType, null, null, null, entropy, null);
rst.setKeySize(skl);
rst.setKeyType(URI.create(WSTrustConstants.SYMMETRIC_KEY));
rst.setComputedKeyAlgorithm(URI.create(WSTrustConstants.CK_PSHA1));
} catch (WSTrustException ex){
throw new WSSecureConversationException(ex);
}
return rst;
| private com.sun.xml.ws.security.trust.elements.RequestSecurityToken | createRequestSecurityTokenForCancel(com.sun.xml.ws.security.IssuedTokenContext ctx)
URI requestType = null;
requestType = URI.create(WSTrustConstants.CANCEL_REQUEST);
final CancelTarget target = eleFac.createCancelTarget((SecurityTokenReference)ctx.getUnAttachedSecurityTokenReference());
final RequestSecurityToken rst = eleFac.createRSTForCancel(requestType, target);
return rst;
| private com.sun.xml.ws.policy.AssertionSet | getAssertions(com.sun.xml.ws.security.policy.SecureConversationToken scToken)
return scToken.getBootstrapPolicy().getAssertionSet();
| private java.lang.String | printMessageAsString(com.sun.xml.ws.api.message.Message message)
final StringWriter writer = new StringWriter();
final XMLOutputFactory factory = XMLOutputFactory.newInstance();
try {
final XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
message.writeTo(streamWriter);
streamWriter.flush();
return writer.toString();
} catch (XMLStreamException ex) {
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0025_PROBLEM_PRINTING_MSG(), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0025_PROBLEM_PRINTING_MSG(), ex);
}
| public com.sun.xml.ws.security.IssuedTokenContext | process(com.sun.xml.ws.policy.PolicyAssertion token, com.sun.xml.ws.api.model.wsdl.WSDLPort wsdlPort, com.sun.xml.ws.api.WSBinding binding, com.sun.xml.ws.api.pipe.Pipe securityPipe, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller, java.lang.String endPointAddress, com.sun.xml.ws.api.message.Packet packet, com.sun.xml.ws.api.addressing.AddressingVersion addVer)
this.packet = packet;
//==============================
// Get Required policy assertions
//==============================
final SecureConversationToken scToken = (SecureConversationToken)token;
final AssertionSet assertions = getAssertions(scToken);
Trust10 trust10 = null;
SymmetricBinding symBinding = null;
for(PolicyAssertion policyAssertion : assertions){
if(PolicyUtil.isTrust10(policyAssertion)){
trust10 = (Trust10)policyAssertion;
}else if(PolicyUtil.isSymmetricBinding(policyAssertion)){
symBinding = (SymmetricBinding)policyAssertion;
}
}
int skl = DEFAULT_KEY_SIZE;
boolean reqClientEntropy = true;
if(symBinding!=null){
final AlgorithmSuite algoSuite = symBinding.getAlgorithmSuite();
skl = algoSuite.getMinSKLAlgorithm();
if(skl<1){
skl = DEFAULT_KEY_SIZE;
}
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
LogStringsMessages.WSSC_1006_SYM_BIN_KEYSIZE(skl, this.DEFAULT_KEY_SIZE));
}
}
if(trust10 != null){
final Set trustReqdProps = trust10.getRequiredProperties();
reqClientEntropy = trustReqdProps.contains(Constants.REQUIRE_CLIENT_ENTROPY);
}
//==============================
// Create RequestSecurityToken
//==============================
RequestSecurityToken rst = null;
try{
rst = createRequestSecurityToken(reqClientEntropy,skl);
} catch (WSSecureConversationException ex){
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0024_ERROR_CREATING_RST(""), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0024_ERROR_CREATING_RST(""), ex);
}/* catch (WSTrustException ex){
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0021_PROBLEM_CREATING_RST_TRUST(), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0021_PROBLEM_CREATING_RST_TRUST(), ex);
}*/
final RequestSecurityTokenResponse rstr = sendRequest(token, wsdlPort, binding, securityPipe, marshaller, unmarshaller, rst, WSSCConstants.REQUEST_SECURITY_CONTEXT_TOKEN_ACTION, endPointAddress, addVer);
// Handle the RequestSecurityTokenResponse
final IssuedTokenContext context = new IssuedTokenContextImpl();
try {
processRequestSecurityTokenResponse(rst, rstr, context);
} catch (WSSecureConversationException ex){
throw new RuntimeException(ex);
}
context.setEndpointAddress(endPointAddress);
return context;
| public com.sun.xml.ws.security.IssuedTokenContext | processCancellation(com.sun.xml.ws.security.IssuedTokenContext ctx, com.sun.xml.ws.api.model.wsdl.WSDLPort wsdlPort, com.sun.xml.ws.api.WSBinding binding, com.sun.xml.ws.api.pipe.Pipe securityPipe, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller, java.lang.String endPointAddress, com.sun.xml.ws.api.addressing.AddressingVersion addVer)
//==============================
// Create RequestSecurityToken
//==============================
RequestSecurityToken rst = null;
try{
rst = createRequestSecurityTokenForCancel(ctx);
} catch (WSSecureConversationException ex){
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0024_ERROR_CREATING_RST(FOR_CANCEL), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0024_ERROR_CREATING_RST(FOR_CANCEL), ex);
}
final RequestSecurityTokenResponse rstr = sendRequest(null, wsdlPort, binding, securityPipe, marshaller, unmarshaller, rst, WSSCConstants.CANCEL_SECURITY_CONTEXT_TOKEN_ACTION, endPointAddress, addVer);
// Handle the RequestSecurityTokenResponse
try {
processRequestSecurityTokenResponse(rst, rstr, ctx);
} catch (WSSecureConversationException ex){
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0020_PROBLEM_CREATING_RSTR(), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0020_PROBLEM_CREATING_RSTR(), ex);
}
return ctx;
| private void | processRequestSecurityTokenResponse(com.sun.xml.ws.security.trust.elements.RequestSecurityToken rst, com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponse rstr, com.sun.xml.ws.security.IssuedTokenContext context)
final WSSCClientContract contract = WSSCFactory.newWSSCClientContract(config);
contract.handleRSTR(rst, rstr, context);
| private com.sun.xml.ws.security.trust.elements.RequestSecurityTokenResponse | sendRequest(com.sun.xml.ws.policy.PolicyAssertion issuedToken, com.sun.xml.ws.api.model.wsdl.WSDLPort wsdlPort, com.sun.xml.ws.api.WSBinding binding, com.sun.xml.ws.api.pipe.Pipe securityPipe, javax.xml.bind.Marshaller marshaller, javax.xml.bind.Unmarshaller unmarshaller, com.sun.xml.ws.security.trust.elements.RequestSecurityToken rst, java.lang.String action, java.lang.String endPointAddress, com.sun.xml.ws.api.addressing.AddressingVersion addVer)
// Marshaller marshaller;
//Unmarshaller unmarshaller;
// try {
// marshaller = jbCxt.createMarshaller();
// unmarshaller = jbCxt.createUnmarshaller();
//} catch (JAXBException ex){
// log.log(Level.SEVERE,"WSSC0016.problem.mar.unmar", ex);
// throw new RuntimeException("Problem creating JAXB Marshaller/Unmarshaller", ex);
//}
final Message request = Messages.create(marshaller, eleFac.toJAXBElement(rst), binding.getSOAPVersion());
// Log Request created
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
LogStringsMessages.WSSC_1009_SEND_REQ_MESSAGE(printMessageAsString(request)));
}
Packet reqPacket = new Packet(request);
if (issuedToken != null){
reqPacket.invocationProperties.put(SC_ASSERTION, issuedToken);
}
if (packet != null){
for(WSTrustConstants.STS_PROPERTIES stsProperty : WSTrustConstants.STS_PROPERTIES.values()) {
reqPacket.invocationProperties.put(stsProperty.toString(),packet.invocationProperties.get(stsProperty.toString()));
}
}
reqPacket.setEndPointAddressString(endPointAddress);
if (log.isLoggable(Level.FINE)) {
log.log(Level.FINE,
LogStringsMessages.WSSC_1008_SET_EP_ADDRESS(endPointAddress));
}
// Add addressing headers to the message
try{
reqPacket = addAddressingHeaders(reqPacket, wsdlPort, binding, action, addVer);
}catch (WSSecureConversationException ex){
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0017_PROBLEM_ADD_ADDRESS_HEADERS(), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0017_PROBLEM_ADD_ADDRESS_HEADERS(), ex);
}
// Ideally this property for enabling FI or not should be available to the pipeline.
// As a workaround for now, we
// copy the property for the client packet to the reqPacket mananually here.
if (packet != null){
reqPacket.contentNegotiation = packet.contentNegotiation;
}
// Send the message
final Packet respPacket = securityPipe.process(reqPacket);
// Obtain the RequestSecurtyTokenResponse
final Message response = respPacket.getMessage();
RequestSecurityTokenResponse rstr = null;
if (!response.isFault()){
JAXBElement rstrEle = null;
try {
rstrEle = (JAXBElement)response.readPayloadAsJAXB(unmarshaller);
}catch (JAXBException ex){
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0018_ERR_JAXB_RSTR(), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0018_ERR_JAXB_RSTR(), ex);
}
rstr = eleFac.createRSTRFrom(rstrEle);
} else {
try{
// SOAPFaultBuilder builder = SOAPFaultBuilder.create(response);
//throw (SOAPFaultException)builder.createException(null, response);
throw new SOAPFaultException(response.readAsSOAPMessage().getSOAPBody().getFault());
} catch (SOAPException ex){
log.log(Level.SEVERE,
LogStringsMessages.WSSC_0022_PROBLEM_CREATING_FAULT(), ex);
throw new RuntimeException(LogStringsMessages.WSSC_0022_PROBLEM_CREATING_FAULT(), ex);
}
}
return rstr;
|
|