private Element convertToDOM( BinarySecurityTokenType binarySecurityTokenType, byte[] securityTokenData ) throws WSSecurityException { Document doc = DOMUtils.getEmptyDocument(); BinarySecurity binarySecurity = null; if (WSSConstants.NS_X509_V3_TYPE.equals(binarySecurityTokenType.getValueType())) { binarySecurity = new X509Security(doc); } else if (WSSConstants.NS_X509_PKIPATH_V1.equals(binarySecurityTokenType.getValueType())) { binarySecurity = new PKIPathSecurity(doc); } else if (WSSConstants.NS_GSS_KERBEROS5_AP_REQ.equals(binarySecurityTokenType.getValueType())) { binarySecurity = new KerberosSecurity(doc); } else { throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN); } binarySecurity.addWSSENamespace(); binarySecurity.addWSUNamespace(); binarySecurity.setEncodingType(binarySecurityTokenType.getEncodingType()); binarySecurity.setValueType(binarySecurityTokenType.getValueType()); binarySecurity.setID(binarySecurityTokenType.getId()); binarySecurity.setToken(securityTokenData); return binarySecurity.getElement(); } }
private Element convertToDOM( BinarySecurityTokenType binarySecurityTokenType, byte[] securityTokenData ) throws WSSecurityException { Document doc = DOMUtils.getEmptyDocument(); BinarySecurity binarySecurity = null; if (WSSConstants.NS_X509_V3_TYPE.equals(binarySecurityTokenType.getValueType())) { binarySecurity = new X509Security(doc); } else if (WSSConstants.NS_X509_PKIPATH_V1.equals(binarySecurityTokenType.getValueType())) { binarySecurity = new PKIPathSecurity(doc); } else if (WSSConstants.NS_GSS_KERBEROS5_AP_REQ.equals(binarySecurityTokenType.getValueType())) { binarySecurity = new KerberosSecurity(doc); } else { throw new WSSecurityException(WSSecurityException.ErrorCode.INVALID_SECURITY_TOKEN); } binarySecurity.addWSSENamespace(); binarySecurity.addWSUNamespace(); binarySecurity.setEncodingType(binarySecurityTokenType.getEncodingType()); binarySecurity.setValueType(binarySecurityTokenType.getValueType()); binarySecurity.setID(binarySecurityTokenType.getId()); binarySecurity.setToken(securityTokenData); return binarySecurity.getElement(); } }
@org.junit.Test public void testBinarySecurityToken() throws Exception { SpringBusFactory bf = new SpringBusFactory(); URL busFile = BinarySecurityTokenTest.class.getResource("client.xml"); Bus bus = bf.createBus(busFile.toString()); BusFactory.setDefaultBus(bus); BusFactory.setThreadDefaultBus(bus); URL wsdl = BinarySecurityTokenTest.class.getResource("DoubleItTokens.wsdl"); Service service = Service.create(wsdl, SERVICE_QNAME); // Successful invocation QName portQName = new QName(NAMESPACE, "DoubleItBinarySecurityTokenPort"); DoubleItPortType port = service.getPort(portQName, DoubleItPortType.class); updateAddressPort(port, PORT); // Mock up a BinarySecurityToken to add SecurityToken securityToken = new SecurityToken(); securityToken.setId("_" + UUID.randomUUID().toString()); Document doc = DOMUtils.newDocument(); BinarySecurity binarySecurity = new BinarySecurity(doc); binarySecurity.setValueType("http://custom-value-type"); binarySecurity.setToken("This is a token".getBytes()); securityToken.setToken(binarySecurity.getElement()); ((BindingProvider)port).getRequestContext().put(SecurityConstants.TOKEN, securityToken); assertEquals(50, port.doubleIt(25)); ((java.io.Closeable)port).close(); bus.shutdown(true); }
binarySecurity = new X509Security(doc); binarySecurity.setEncodingType(encodingType); binarySecurity.setValueType(binarySecurityType.getValueType()); String data = binarySecurityType.getValue();
binarySecurity = new X509Security(doc); binarySecurity.setEncodingType(encodingType); binarySecurity.setValueType(binarySecurityType.getValueType()); String data = binarySecurityType.getValue();