I'm following this example to create a web service secured with signature only: https://github.com/apache/cxf/blob/master/distribution/src/main/release/samples/ws_security/sign_enc/src/main/java/demo/wssec/server/Server.java
This is what my code looks like:
public static void main(String[] args) {
FooService service = new FooService();
String address = "http://localhost:1235/foo";
EndpointImpl endpoint = (EndpointImpl) javax.xml.ws.Endpoint.publish(address, service);
Map<String,Object> inProps = new HashMap<>();
inProps.put(WSHandlerConstants.ACTION, "Signature");
inProps.put(WSHandlerConstants.SIG_PROP_FILE, Server.class.getResource("./server_sign.properties"));
inProps.put("signatureKeyIdentifier", "DirectReference");
inProps.put("encryptionKeyTransportAlgorithm", "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p");
inProps.put("signatureAlgorithm", "http://www.w3.org/2000/09/xmldsig#rsa-sha1");
endpoint.getInInterceptors().add(new WSS4JInInterceptor(inProps));}
When I send a soap messge to the server it throws an error:
org.apache.wss4j.common.ext.WSSecurityException: An error was discovered processing the <wsse:Security> header
Also it shows the message
Security processing failed (actions mismatch)
Why does this happen?
Related
When we send SOAP API using CXF Client proxy we get the below error -
Caused by: org.w3c.dom.DOMException: WRONG_DOCUMENT_ERR: A node is used in a different document than the one that created it.
at java.xml/com.sun.org.apache.xerces.internal.dom.ParentNode.internalInsertBefore(ParentNode.java:355)
at java.xml/com.sun.org.apache.xerces.internal.dom.ParentNode.insertBefore(ParentNode.java:286)
at java.xml/com.sun.org.apache.xerces.internal.dom.NodeImpl.appendChild(NodeImpl.java:230)
at org.apache.wss4j.dom.util.WSSecurityUtil.prependChildElement(WSSecurityUtil.java:283)
at org.apache.wss4j.dom.util.WSSecurityUtil.findWsseSecurityHeaderBlock(WSSecurityUtil.java:377)
This error is unknown to me. Can anyone please help me in this. My Client Code is below -
Client client = ClientProxy.getClient(servicesPort);
Endpoint endpoint2 = client.getEndpoint();
Map<String, Object> props = new HashMap();
props.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
props.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
props.put(WSHandlerConstants.PW_CALLBACK_CLASS, UTPasswordCallback.class.getName());
props.put(WSHandlerConstants.USER, "<username>");
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(props);
endpoint2.getOutInterceptors().add(wssOut);
List<Ocpninstances> list = chargePointServicesPort.getCPNInstances();
UTPasswordCallback class -
class UTPasswordCallback implements CallbackHandler {
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for (Callback callback : callbacks) {
WSPasswordCallback wpc = (WSPasswordCallback) callback;
if (wpc.getIdentifier().equals("<username>")) {
wpc.setPassword("<password>");
return;
}
}
}
}
I tried with one solution by adding Saaj-impl dependency, but after using that also getting some other issues.
I am working on implementing WebSocket integration tests. I cannot get the mock user to be passed to the client.
#WithMockUser(value = "user", roles = "USER")
void test() throws ExecutionException, InterruptedException, TimeoutException {
webSocketStompClient = new WebSocketStompClient(
new SockJsClient(List.of(new WebSocketTransport(new StandardWebSocketClient())))
);
StompSession session = webSocketStompClient
.connect(String.format("ws://localhost:%d/ws", port),
new StompSessionHandlerAdapter() {
}
)
.get(1, SECONDS);
}
Unfortunately, I receive the following error:
TopicInterceptorIT > test() FAILED
java.util.concurrent.ExecutionException at TopicInterceptorIT.java:57
Caused by: org.springframework.messaging.simp.stomp.ConnectionLostException at DefaultStompSession.java:518
2022-01-17 12:04:19.415 WARN [,,,] 44518 --- [ XNIO-1 I/O-9] w.s.h.ExceptionWebSocketHandlerDecorator : Unhandled exception after connection closed for ExceptionWebSocketHandlerDecorator [delegate=LoggingWebSocketHandlerDecorator [delegate=WebSocketMsgEnhancer [delegate=SubProtocolWebSocketHandler[StompSubProtocolHandler[v10.stomp, v11.stomp, v12.stomp]]]]]
org.springframework.messaging.MessageDeliveryException: Failed to send message to ExecutorSubscribableChannel[clientInboundChannel]; nested exception is org.springframework.security.access.AccessDeniedException: Access is denied
Do I have to manually create the access token and inject it into the request headers? Or is there an approach similar to the #WithMockUser over MockMvc familiar when testing REST endpoints?
I tried to built Fuseki server, and add some data to it. There is my function to build Fuseki
(according to example3 of https://jena.apache.org/documentation/fuseki2/fuseki-embedded.html):
public static FusekiServer createFusekiServer() {
DatasetGraph ds = DatasetGraphFactory.createTxnMem();
DataService dataService = new DataService(ds);
dataService.addEndpoint(OperationName.Update, "");
FusekiServer server = FusekiServer.create().setPort(3332).add("/data", dataService).build() ;
server.start();
return server;
}
After creating it, I want to add some data to it.
public static void main(String[] args) {
FusekiSrv fusekiSrv = new FusekiSrv();
String uri = "http://host:3332/ds";
DatasetAccessor accessor = DatasetAccessorFactory.createHTTP(uri);
Model model = ontology.loadOntology(pathName);
FusekiServer fusekiServer = fusekiSrv.createFusekiServer();
fusekiSrv.sendOntologyToFuseki(accessor, model);
fusekiServer.stop();
}
public static void sendOntologyToFuseki(DatasetAccessor accessor, Model model) {
if (accessor != null) {
accessor.add(model);
}}
My error message is :
Exception in thread "main" org.apache.jena.atlas.web.HttpException: 405 - HTTP method POST is not supported by this URL
at org.apache.jena.riot.web.HttpOp.exec(HttpOp.java:1084)
at org.apache.jena.riot.web.HttpOp.execHttpPost(HttpOp.java:711)
at org.apache.jena.riot.web.HttpOp.execHttpPost(HttpOp.java:655)
at org.apache.jena.web.DatasetGraphAccessorHTTP.doPost(DatasetGraphAccessorHTTP.java:192)
at org.apache.jena.web.DatasetGraphAccessorHTTP.httpPost(DatasetGraphAccessorHTTP.java:182)
at org.apache.jena.web.DatasetAdapter.add(DatasetAdapter.java:91)
I've seen these issues :
405 HTTP method PUT is not supported by this URL
getting error HTTP Status 405 - HTTP method GET is not supported by this URL but not used `get` ever?
but it didn't help me.
.add("/data",
then
uri = "http://host:3332/ds"
"data" in one, "ds" in the other.
You need to use the same service name.
The error is Jetty rejecting the request. It didn't get to Fuseki.
i want to send an org.apache.cxf.message.Message object via CXF Jax-ws. For example:
A service declared:
#WebService
public interface HelloWorld {
void send(Message msg);
}
Implementation of this service:
public class HelloWorldImpl implements HelloWorld {
public void send(Message msg) {
System.out.println("receives msg id:" +((MessageImpl)msg).getId());
}
}
Server:
HelloWorldImpl implementor = new HelloWorldImpl();
JaxWsServerFactoryBean svrFactory1 = new JaxWsServerFactoryBean();
svrFactory1.setServiceClass(HelloWorld.class);
svrFactory1.setAddress("http://192.168.56.1:9000/HelloWorld");
svrFactory1.setServiceBean(implementor);
org.apache.cxf.endpoint.Server server1 = svrFactory1.create();
server1.start();
Client:
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setAddress("http://192.168.56.1:9000/HelloWorld");
HelloWorld client = factory.create(HelloWorld.class);
Message msg = new MessageImpl();
msg.setId("abc");
client.send(msg);
I receive an error when running as follows:
Exception in thread "main" javax.xml.ws.soap.SOAPFaultException: Fault occurred while processing.
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:160)
at com.sun.proxy.$Proxy37.sayHiToUser(Unknown Source)
at objecttype.Client.main(Client.java:60)
Caused by: org.apache.cxf.binding.soap.SoapFault: Fault occurred while processing.
.......
How to correct this error ?
Regards,
I am trying to invoke a axis2 web service enabled with Rampart security. When I try to invoke the service through the client I am getting the following exception, (I have also included Jaxen Jar in my project)
Exception in thread "main" org.apache.axis2.AxisFault: java.lang.NoClassDefFoundError: org/jaxen/JaxenException
at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:446)
at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:371)
at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:417)
at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
at com.tcs.secure.SecureServiceStub.add(SecureServiceStub.java:186)
at com.tcs.secure.Client.main(Client.java:16)
I have generated stubs for my password call back class and my sample class and imported it to my client. Here is my sample client.
public class Client {
public static void main(String[] args) throws RemoteException {
SecureServiceStub stub = new SecureServiceStub();
Add request = new Add();
request.setA(23);
request.setB(389);
AddResponse response = stub.add(request);
System.out.println(response);
}
}