admin管理员组

文章数量:1314832



`package com.mahfin.config;

import com.mahfin.security.ServerPasswordCallback;
import com.mahfin.service.MyEncryptedSoapService;
import .apache.cxf.Bus;
import .apache.cxf.binding.soap.saaj.SAAJInInterceptor;
import .apache.cxf.jaxws.EndpointImpl;
import jakarta.xml.ws.Endpoint;
import .apache.cxf.interceptor.LoggingInInterceptor;
import .apache.cxf.interceptor.LoggingOutInterceptor;
import .apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
import .apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
import .apache.wss4jmon.ConfigurationConstants;
import .springframework.beans.factory.annotation.Autowired;
import .springframework.context.annotation.Bean;
import .springframework.context.annotation.Configuration;
import .springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@Configuration
public class SoapConfig {
    @Autowired
    private Bus bus;

    @Bean
    public Endpoint encryptedSoapEndpoint(MyEncryptedSoapService service) throws IOException {
        EndpointImpl endpoint = new EndpointImpl(bus, service);

        // Add logging interceptors for debugging
        endpoint.getInInterceptors().add(new LoggingInInterceptor());
        endpoint.getOutInterceptors().add(new LoggingOutInterceptor());

        // Set the WSDL location
        String wsdlPath = new ClassPathResource("/MMFSL_ReverseFeed_AxisV1.1.wsdl").getURI().toString();
        System.out.println("WSDL Path: " + wsdlPath);
        endpoint.setWsdlLocation(wsdlPath);

        // Add WSS4J interceptors
        endpoint.getInInterceptors().add(new SAAJInInterceptor());
        endpoint.getInInterceptors().add(new WSS4JInInterceptor(getWssInProperties()));
        endpoint.getOutInterceptors().add(new WSS4JOutInterceptor(getWssOutProperties()));

        // Publish the endpoint
        endpoint.publish("/EncryptedSoapService");
        return endpoint;
    }

    private Map<String, Object> getWssInProperties() {
        Map<String, Object> inProps = new HashMap<>();
        inProps.put(ConfigurationConstants.ACTION, "Encrypt");
        inProps.put(ConfigurationConstants.PW_CALLBACK_CLASS, ServerPasswordCallback.class.getName());
        inProps.put(ConfigurationConstants.SIG_PROP_FILE, "serverKeystore.properties");
        inProps.put(ConfigurationConstants.DEC_PROP_FILE, "serverKeystore.properties");
        return inProps;
    }

    private Map<String, Object> getWssOutProperties() {
        Map<String, Object> outProps = new HashMap<>();
        outProps.put(ConfigurationConstants.ACTION, "Encrypt");
        outProps.put(ConfigurationConstants.USER, "mmfsl");
        outProps.put(ConfigurationConstants.PW_CALLBACK_CLASS, ServerPasswordCallback.class.getName());
        outProps.put(ConfigurationConstants.SIG_PROP_FILE, "serverKeystore.properties");
        outProps.put(ConfigurationConstants.ENC_PROP_FILE, "serverKeystore.properties");
        return outProps;
    }
}



package com.mahfin.service;
import com.mahfin.dto.MMFSLReverseFeedAxisResponse;
import jakarta.jws.WebService;
import jakarta.jws.WebMethod;
import lombok.extern.slf4j.Slf4j;
import .springframework.core.io.ClassPathResource;
import .springframework.stereotype.Service;
import .w3c.dom.NodeList;

import javax.xml.soap.*;

@Slf4j
@Service
@WebService(
        serviceName = "EncryptedSoapService",
        targetNamespace = "http://localhost:8080/services/EncryptedSoapService/",
        portName = "EncryptedSoapServicePort",
        name = "MMFSL_ReverseFeed_Axis"
)
public class MyEncryptedSoapService {

    @WebMethod(
            operationName = "MMFSL_ReverseFeed_Axis",
            action = "http://localhost:8080/services/EncryptedSoapService/MMFSL_ReverseFeed_Axis" // Must match the SOAP action in the WSDL

    )
    public MMFSLReverseFeedAxisResponse processRawRequest(SOAPMessage request) throws SOAPException {

        System.out.println("Received encrypted SOAP request {} "+request);

        if (request == null) {
            throw new SOAPException("Received null request");
        }

        // Extract the body content
        SOAPBody requestBody = request.getSOAPBody();
        NodeList elements = requestBody.getElementsByTagName("inputMessage");
        if (elements.getLength() > 0) {
            String input = elements.item(0).getTextContent();
            System.out.println("Decrypted request content: " + input);
        }



        MMFSLReverseFeedAxisResponse response = new MMFSLReverseFeedAxisResponse();

        // Simulate a response (You can populate it based on your logic)
        response.setResponseStatus("Success");
        response.setResponseMessage("The reverse feed has been processed successfully.");

        return response;
    }
}


`



i have used above code to encrypt deccrypt soap message using jks at java code level but getting below exception tried many solutions but my problem is not getting solved

Interceptor for {http://localhost:8080/services/EncryptedSoapService/}EncryptedSoapService has thrown exception, unwinding now
.apache.cxf.binding.soap.SoapFault: A security error was encountered when verifying the message

Caused by: .apache.wss4jmon.ext.WSSecurityException: An error was discovered processing the <wsse:Security> header

本文标签: orgapachecxfbindingsoapSoapFault A security error was encountered when verifying the messageStack Overflow