java - 无法处理 MustUnderstand header : {http://docs. oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}安全性。返回故障

标签 java spring-boot soap spring-ws

我浏览了以下链接:SOAPFaultException "MustUnderstand headers (oasis-200401-wss-wssecurity-secext-1.0.xsd) are not understood" ,但仍在挣扎。

我正在使用 Spring Boot v2.2.2..RELEASE 和 SOAP 项目。

我正在将两个不同的 WSDL 文件加载到我的项目中。一个 URL 生成到 http://localhost:8080/employee/employee-soap ,效果很好。但是 http://localhost:8080/student/student-soap 这给出了以下错误。

2020-02-17 15:31:00.241 WARN 20236 --- [nio-8080-exec-5] o.s.w.soap.server.SoapMessageDispatcher : Could not handle mustUnderstand headers: {http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}Security. Returning fault

Java代码:

@EnableWs
@Configuration
public class AppConfig extends WsConfigurerAdapter {

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/*");
    }

    @Bean
    public SaajSoapMessageFactory messageFactory() {
        SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
        messageFactory.setSoapVersion(SoapVersion.SOAP_11);
        messageFactory.afterPropertiesSet();
        return messageFactory;
    }

    @Bean("empXSD")
    public XsdSchema organizationSchema() {
        return new SimpleXsdSchema(new ClassPathResource("/xsd/employee.xsd"));
    }


    @Bean(name = "employee")
    public DefaultWsdl11Definition defaultWsdl11Definition(@Qualifier("empXSD") XsdSchema schema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("employee");
        wsdl11Definition.setLocationUri("employee/employee-soap");
        wsdl11Definition.setTargetNamespace("urn:example.com:dms:wsdls:employee");
        wsdl11Definition.setSchema(schema);
        wsdl11Definition.setCreateSoap11Binding(true);
        return wsdl11Definition;
    }

    @Bean
    @Qualifier(value="stuXSD")
    public XsdSchema stuSchema() {
        return new SimpleXsdSchema(new ClassPathResource("/xsd/student.xsd"));
    }

    @Bean(name = "student")
    public DefaultWsdl11Definition geographyWsdl11Definition(@Qualifier("stuXSD") XsdSchema schema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("student");
        wsdl11Definition.setLocationUri("student-soap");
        wsdl11Definition.setTargetNamespace("urn:example.com:dms:wsdls:student");
        wsdl11Definition.setSchema(schema);
        wsdl11Definition.setCreateSoap11Binding(true);
        return wsdl11Definition;
    }


    @Override
    public void addInterceptors(List<EndpointInterceptor> interceptors) {
        interceptors.add(new Interceptor(endpoints, req));
    }
}

代码:

@Configuration
public class SimpleMustUnderstandEndpointInterceptor implements SoapEndpointInterceptor{
    private final String SAMPLE_NS = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";

    @Override
    public boolean handleRequest(MessageContext messageContext, Object endpoint) throws Exception {
        return true;
    }

    @Override
    public boolean handleResponse(MessageContext messageContext, Object endpoint) throws Exception {
        return true;
    }

    @Override
    public boolean handleFault(MessageContext messageContext, Object endpoint) throws Exception {
        return true;
    }

    @Override
    public void afterCompletion(MessageContext messageContext, Object endpoint, Exception ex) throws Exception {

    }

    @Override
    public boolean understands(SoapHeaderElement header) {
        if(header.getName().getNamespaceURI().equalsIgnoreCase(SAMPLE_NS)) {
            return true;
        }
        return false;
    }

}

根据观察,看起来甚至这个 SoapEndpointInterceptor 也没有调用,在此之前只是给出了错误。

在调用 SOAP 端点期间,将出现以下 header 信息并给出我上面提到的错误。有什么指示吗?

<soapenv:Header><wsse:Security soapenv:mustUnderstand="1" 
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity- 
secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401- 
wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken- 
518482F2CDC2F635FF158202815227129"><wsse:Username>aispoc_usr1</wsse:Username> 
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss- 
username-token-profile-1.0#PasswordText">aispoc_usr1</wsse:Password><wsse:Nonce 
EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap- 
message-security-1.0#Base64Binary">/fdGCEilz/dkVeZE05b7LQ==</wsse:Nonce> 

2020-02-18T12:15:52.271Z

最佳答案

您可以尝试以下配置来解决该问题。

@Bean
public Wss4jSecurityInterceptor securityInterceptor() {
    Wss4jSecurityInterceptor security = new Wss4jSecurityInterceptor();
    security.setValidationActions("NoSecurity");
    security.setValidateRequest(false);
    security.setValidateResponse(true);
    return security;
}

@Override
public void addInterceptors(List<EndpointInterceptor> interceptors) {
    interceptors.add(securityInterceptor());
}

关于java - 无法处理 MustUnderstand header : {http://docs. oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd}安全性。返回故障,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60260277/

相关文章:

.net - 在不使用 azcopy 的情况下跨 Azure 容器复制文件

java - 在 Spring Boot 中排除 Hibernate 不起作用

Spring Transactional - 确保测试和产品中的可预测行为

java - 是否可以创建一个类方法,根据给定的条件,该方法将返回一个数组或根本不返回任何内容?

java - 根据点赞数和创建时间对实体进行评分

java - 无论如何打印最后一个对象

java - JPQL从自引用表中删除

c# - 使用 JSON 将继承的对象传递给 WCF 服务

java - SOAP java 客户端 HTTPS/SSL

PHP、MYSQL Web 服务与 nusoap