如何在同一项目中为2种不同的肥皂服务配置2种不同的证券?

时间:2019-08-20 16:42:55

标签: java spring spring-boot soap spring-ws

我想为2个肥皂服务使用2个不同的安全性实现。 Soap服务之一将向客户端公开。其他肥皂服务仅供内部使用。如果客户以某种方式能够到达端点,我不想让客户访问我计划在内部使用的服务。我想将Wss用于这两种服务。我该如何实现?

我已经创建了2个soap服务和一个安全配置,但是我不知道从那里去哪里。 当前,两个肥皂服务都使用定义的一个安全配置。

这是我的配置示例。

WebServiceConfig.java

@Configuration
@EnableWs
public class WebServiceConfig {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext context) {
        MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
        messageDispatcherServlet.setApplicationContext(context);
        messageDispatcherServlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(messageDispatcherServlet, "/ws/*");
    }

    @Bean(name = "courses")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema coursesSchema) {
        DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
        definition.setSchema(coursesSchema);
        definition.setPortTypeName("CoursePort");
        definition.setTargetNamespace("http://sudx.com/soap/courses");
        definition.setLocationUri("/ws");
        return definition;
    }

    @Bean(name = "calc")
    public DefaultWsdl11Definition defaultWsdl11Definition2(XsdSchema calcSchema) {
        DefaultWsdl11Definition definition = new DefaultWsdl11Definition();
        definition.setSchema(calcSchema);
        definition.setPortTypeName("CalcPort");
        definition.setTargetNamespace("http://sudx.com/soap/calc");
        definition.setLocationUri("/ws");
        return definition;
    }

    @Bean(name = "calcSchema")
    public XsdSchema calcSchema() {
        return new SimpleXsdSchema(new ClassPathResource("calc.xsd"));
    }

    @Bean(name = "coursesSchema")
    public XsdSchema coursesSchema() {
        return new SimpleXsdSchema(new ClassPathResource("course-details.xsd"));
    }
}

SecurityConfig.java

@Configuration
@PropertySource("classpath:credentials.properties")
public class SecurityConfig extends WsConfigurerAdapter {

    @Value("#{${user-credentials}}")
    Map<String, String> credentials;

    @Bean
    Wss4jSecurityInterceptor wss4jSecurityInterceptor() {
        Wss4jSecurityInterceptor securityInterceptor = new Wss4jSecurityInterceptor();
        securityInterceptor.setValidationActions("Timestamp UsernameToken");
        securityInterceptor.setValidationCallbackHandler(callbackHandler());
        return securityInterceptor;
    }

    @Bean
    public SimplePasswordValidationCallbackHandler callbackHandler() {
        SimplePasswordValidationCallbackHandler handler = new SimplePasswordValidationCallbackHandler();
        handler.setUsersMap(credentials);
        return handler;
    }

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

    // ADD SECURITY CONFIG FOR 2ND SOAP SERVICE
}

0 个答案:

没有答案