javaspringspring-securityhessianspring-remoting

Client side basic HTTP authentication with Hessian remoting in Spring


On the client side i have the following 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>

And I'm calling the Hessian web service with:

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

This works just fine until I turn on Spring Security on the server side, after which I get the expected error - "Server returned HTTP response code: 403".

So, how do I configure the username and password on the client side?


Solution

  • According to the API Doc, org.springframework.remoting.caucho.HessianProxyFactoryBean provides two setter method for HTTP basic authentication by default:

    how do I configure the username and password on the client side?

    In your applicationContext.xml, define your HessianProxyFactoryBean like so:

    <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>