簡體   English   中英

在Spring中使用Hessian遠程處理的客戶端基本HTTP身份驗證

[英]Client side basic HTTP authentication with Hessian remoting in Spring

在客戶端,我有以下spring bean:

<bean id="partneriLogicImpl" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
    <property name="serviceUrl" value="http://localhost:8080/hr.spi.service/hessian/lcspi/lczaj/partneri" />
    <property name="serviceInterface" value="hr.spi.logic.lcspi.lczaj.PartneriLogic" />
</bean>

我正在調用Hessian Web服務:

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContextHessian.xml");
PartneriLogic partneriLogic = (PartneriLogic) context.getBean("partneriLogicImpl");
List<?> partnerList = partneriLogic.dohvatiSveZaExport();

這工作正常,直到我在服務器端打開Spring Security,之后我收到預期的錯誤 - “服務器返回HTTP響應代碼:403”。

那么,如何在客戶端配置用戶名和密碼?

根據API Doc ,org.springframework.remoting.caucho.HessianProxyFactoryBean默認為HTTP基本身份驗證提供兩種setter方法:

  • setUsername

    設置此工廠用於訪問遠程服務的用戶名。 默認為none。

    用戶名將由Hessian通過HTTP基本身份驗證發送。

  • 設置密碼

    設置此工廠用於訪問遠程服務的密碼。 默認為none。

    密碼將由Hessian通過HTTP基本身份驗證發送。

如何在客戶端配置用戶名和密碼?

在applicationContext.xml中,像這樣定義你的HessianProxyFactoryBean:

<bean id="partneriLogicImpl" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
  <property name="serviceUrl" value="http://localhost:8080/hr.spi.service/hessian/lcspi/lczaj/partneri" />
  <property name="serviceInterface" value="hr.spi.logic.lcspi.lczaj.PartneriLogic" />
  <property name="username" value="${username}" />
  <property name="password" value="${password}" />
</bean>

我試圖設置用戶名和密碼進行身份驗證,但它沒有用。

最后,我找到了一個解決方案 - 也許這是一個糟糕的解決方案。

這是在Hessian服務URL上禁用Spring Security。

我不認為這是一個很好的解決方案,但它有效......

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/hessianServiceUrl");
    }
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM