2011-09-22 2 views
0

WSS4J 조각을 추가하기 전까지 CXF를 사용하여 웹 서비스 계약의 첫 번째 세트를 설정하는 데 꽤 익숙해졌습니다.CXF를 사용하여 WSS4J 구성

비누 헤더에 비밀번호를 보내고 로그인을 디버깅하려고합니다. WSPasswordCallback 클래스에서 getPassword()를 호출하면 null이 발생합니다. 비누 봉투에서 암호가 전송 된 것을 볼 수 있습니다.

이 게시물 (http://old.nabble.com/PasswordDigest-and-PasswordText-difference-td24475866.html, 2009 년)은 UsernameTokenHandler가 누락 되었습니까 (작성해야하는지) 궁금합니다.

그리고 이것이 사실이라면 누군가 스프링/cxf 빈 xml 파일에서 구성하는 방법을 알려줄 수 있습니까?

조언이나 제안 사항을 보내 주시면 감사하겠습니다.

여기에 문제의 자바 파일입니다 :

package com.netcentric.security.handlers; 

import java.io.IOException; 
import javax.annotation.Resource; 
import javax.com.urity.auth.callback.Callback; 
import javax.com.urity.auth.callback.CallbackHandler; 
import javax.com.urity.auth.callback.UnsupportedCallbackException; 
import org.apache.ws.com.urity.WSPasswordCallback; 

public class ServicePWCallback implements CallbackHandler 
{ 
    @Override 
    public void handle(Callback[] callbacks) throws IOException, 
       UnsupportedCallbackException { 
     try { 
      for (int i = 0; i < callbacks.length; i++) { 
       if (callbacks[i] instanceof WSPasswordCallback) { 

        WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; 

        sString login = pc.getIdentifier(); 

        String password = pc.getPassword(); 
        // password is null, not the expected myPASSWORD**1234 

        int n = pc.getUsage(); 
        // this is 2 == WSPasswordCallback.USERNAME_TOKEN 

       //... 

CXF/Spring 설정 파일 :

 

    <beans xmlns="http://www.springframework.org/schema/beans" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xmlns:context="http://www.springframework.org/schema/context" 
      xmlns:jee="http://www.springframework.org/schema/jee" 
      xmlns:jaxws="http://cxf.apache.org/jaxws" 
      xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd 
    http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd" 
     default-dependency-check="none" default-lazy-init="false"> 

     <import resource="classpath:META-INF/cxf/cxf.xml" /> 
     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> 

     <bean id="serverPasswordCallback" class="com.netcentric.security.handlers.ServicePWCallback"/> 
     <bean id="wss4jInInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor"> 
      <constructor-arg> 
       <map> 
        <entry key="action" value="UsernameToken"/> 
        <entry key="passwordType" value="PasswordText"/> 
            <entry key="passwordCallbackRef"> 
         <ref bean="serverPasswordCallback"/> 
        </entry> 
       </map> 
      </constructor-arg> 
     </bean> 

     <jaxws:endpoint id="FederationImpl" 
      implementor="com.netcentric.services.federation.FederationImpl" 
      endpointName="e:federation" 
      serviceName="e:federation" 
      address="federation" 
      xmlns:e="urn:federation.services.netcentric.sec"> 

        <jaxws:inInterceptors> 
          <bean class="org.apache.cxf.binding.soap.saaj.SAAJInInterceptor"/> 
          <ref bean="wss4jInInterceptor"/> 
        </jaxws:inInterceptors> 
     </jaxws:endpoint> 
    </beans 

비누 메시지 :

 

    <?xml version="1.0" encoding="UTF-8"?> 
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
     <soapenv:Header> 
      <wsse:comurity xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-comext-1.0.xsd" soapenv:mustUnderstand="1"> 
       <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-utility-1.0.xsd" wsu:Id="Timestamp-16757598"> 
        <wsu:Created>2011-09-22T18:21:23.345Z</wsu:Created> 
        <wsu:Expires>2011-09-22T18:26:23.345Z</wsu:Expires> 
       </wsu:Timestamp> 
       <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wscomurity-utility-1.0.xsd" wsu:Id="UsernameToken-16649441"> 
        <wsse:Username>pam</wsse:Username> 
        <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">myPASSWORD**1234</wsse:Password> 
       </wsse:UsernameToken> 
      </wsse:comurity> 
     </soapenv:Header> 
     <soapenv:Body> 
      <getVersion xmlns="urn:federation.services.netcentric.com"> 
       <getVersionRequest/> 
      </getVersion> 
     </soapenv:Body> 
    </soapenv:Envelope> 

답변

5

CXF의 2.4.X를 사용하는 경우, 나는 독서를 권합니다 :

http://coheigea.blogspot.com/2011/02/usernametoken-processing-changes-in.html

및 추가 정보가 있는지 확인하십시오. Colm의 블로그는 최신 WSS4J 릴리즈에 대한 유용한 정보를 담고 있습니다.

+0

정말 도움이됩니다. 이것이 당신에게 의미가 있는지 물어볼 수 있습니까? getIdentifier()를 통해 봉투에 제공된 로그인을 얻을 수 있습니다. 그런 다음 암호를 찾아 setPassword (passwdFromDb)를 사용하면 프레임 워크가 비교 작업을 완료합니다. 그게 맞는 것 같니? setPassword를 호출하는 것이 이상한 것 같지만 콜백 핸들러에서 사용하는 다른 이유는 상상할 수 없습니다. –

3

귀하의 모든 도움에 감사드립니다. 나는 이것을 진전시켰다. 나는 CXF 2.4.2와 WSS4J 1.6.2를 사용하고있다. 이제 프레임 워크가 암호 확인을 처리합니다. 그래서 올바른 내부 섹션 대신 예상 값과 비교하기 위해 SOAP 헤더에서 암호를 검색

  if (callbacks[i] instanceof WSPasswordCallback) { 
       WSPasswordCallback pc = (WSPasswordCallback) callbacks[i]; 
       sString login = pc.getIdentifier(); 
       String password = getPassword(login); 
       pc.getPassword(login); 
       //... 
      } 

, 당신은 기대 값을 조회하고 비교를 할 프레임 워크에 전달합니다.

+2

''pc.getPassword (login);''pc.setPassword (password); '가 아닌가? –

0

난이 추가

// set the password on the callback. 
This will be compared to the    
// password which was sent from the client.    
pc.setPassword("password"); 

==> "사이의 암호가"클라이언트에 의해 발송에 실패 암호와 비교됩니다.

클라이언트 측 : write login = bob; Password = bobPassword

서버 측 : 사용자 user = bob을 잡아서 수신 된 암호가 맞는지 또는 아니요인지 user.setPassword(bobPassword) 함수가 확인하십시오.

관련 문제