【问题标题】:JAXB Header security with Spring-WS使用 Spring-WS 的 JAXB 标头安全性
【发布时间】:2016-05-31 12:28:12
【问题描述】:

我尝试使用 JAXB 和 SpringWS 开发 Web 服务。 但我有一个问题。 我将 wss 安全性放在哪里以及如何创建标头?

这是我的实际代码:

上下文弹簧客户

    @Configuration
public class MonsterWSClientContext {

    private static final String URL = "AAA";
    private static final String TEST_URL = "TEST";
    private static final String WS_URL = TEST_URL + "/soap/WSOfferService";

    @Bean
    @Autowired
    public MonsterWSClient monsterClient(Jaxb2Marshaller marshaller) {
        MonsterWSClient client = new MonsterWSClient();
        client.setDefaultUri(WS_URL);
        client.setMarshaller(marshaller);
        client.setUnmarshaller(marshaller);
        return client;
    }


    @Bean
    public Jaxb2Marshaller marshaller() {
        Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
        jaxb2Marshaller.setPackagesToScan(com.monster.schemas.monster.ObjectFactory.class.getPackage().getName(), 
                com.monster.schemas.monsterheader.ObjectFactory.class.getPackage().getName(), 
                com.monster.schemas.ObjectFactory.class.getPackage().getName(),
                com.monster.webservices.monsterportal.ObjectFactory.class.getPackage().getName());
        return jaxb2Marshaller;

    }

}

这是客户

public class MonsterWSClient extends WebServiceGatewaySupport {


    public JobsResponse updateJob(Job request) {

        return (JobsResponse) getWebServiceTemplate().marshalSendAndReceive(request,
                new SoapActionCallback(getDefaultUri() + "/createOffer"));
    }
}

这是主要的:

public class Test {
     public JobsResponse callMonster(String jobRefCode, String userName,
     InformazioniAnnuncio datiAnnuncio)
     {
         MonsterWSClient client = new MonsterWSClient();
         JobsResponse response = new JobsResponse();    
         return response = client.updateJob(createJob(jobRefCode, userName, datiAnnuncio));

     }
}
  • 我已经创建了 Job 对象。
  • 但我不明白我将带有凭据的标题放在哪里。

谢谢。

【问题讨论】:

  • 嗨,但是现在我在启动此应用程序时遇到了另一个问题,在 home.LaunchCall 中创建名称为“lookup”的 bean 时出错:通过构造函数参数表示的不满足依赖关系,索引为 0,类型为 [MonsterWSClient] :没有为依赖项找到类型为 [com.proximainformatica.client.MonsterWSClient] 的合格 bean:预计至少有 1 个 bean 有资格作为此依赖项的自动装配候选者。依赖注解:{};嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖找到 [MonsterWSClient] 类型的合格 bean:预期 ..

标签: java spring web-services jaxb spring-ws


【解决方案1】:

您必须使用 spring-ws-security。使用此链接spring ws security 。此页面包含所有与安全相关的设置,您需要使用您的用户名和密码设置 Wss4jSecurityInterceptor。

像这样的

    @Bean
    public Wss4jSecurityInterceptor securityInterceptor() {
    Wss4jSecurityInterceptor securityInterceptor = new   Wss4jSecurityInterceptor();
    securityInterceptor.setSecurementActions("UsernameToken");
    securityInterceptor.setSecurementUsername({username});
    securityInterceptor.setSecurementPassword({password});
    securityInterceptor.setSecurementPasswordType("PasswordText");
    securityInterceptor.setSecurementUsernameTokenElements("Created");
    return securityInterceptor;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-20
    相关资源
    最近更新 更多