SpringSide 에서 Spring + XFire + WSS4J 기본 설정

http://www.blogjava.net/security/archive/2006/08/08/xfire_wss4j.html
          WS-Security   ,   SpringSide    XFire+WSS4J Demo,    SpringSide Spring+XFire+WSS4J     

[WebService Server   ]
  ,       BookService
public interface BookService {
    /** *//**
     *          
     */
    List findBooksByName(String name);

    /** *//**
     *           
     *
     * @param categoryId   category null “all”,       。
     */
    List findBooksByCategory(String categoryId);

    /** *//**
     *       .
     *
     * @return List<Category>,  null。
     */
    List getAllCategorys();
}
  ,    , Extend   BookService, XFire ,   WSS4J         ServiceClass,  <inHandlers>      Overlap。 public interface BookServiceWSS4JEnc  extends BookService {

}
public interface BookServiceWSS4JSign  extends BookService {

}
  ,  Spring ApplicationContext  
    <!--BookService   -->
    <bean id="baseWebService" class="org.codehaus.xfire.spring.remoting.XFireExporter" abstract="true">
        <property name="serviceFactory" ref="xfire.serviceFactory"/>
        <property name="xfire" ref="xfire"/>
    </bean>

    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
        <property name="mappings">
            <value>
                /BookService=bookService
                /BookServiceWSS4J=bookServiceWSS4J
                /BookServiceWSS4JEnc=bookServiceWSS4JEnc
                /BookServiceWSS4JSign=bookServiceWSS4JSign
            </value>
        </property>
    </bean>

   <!--(1)BookWebService      -->
    <bean id="bookService" class="org.codehaus.xfire.spring.remoting.XFireExporter">
        <property name="serviceFactory" ref="xfire.serviceFactory"/>
        <property name="xfire" ref="xfire"/>
        <property name="serviceBean" ref="bookManager"/>
        <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookService"/>
    </bean>

    <!--  (3)BookWebService    WSS4J  -->
    <bean id="bookServiceWSS4J" class="org.codehaus.xfire.spring.remoting.XFireExporter">
        <property name="serviceBean" ref="bookManager"/>
        <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookServiceWSS4J"/>
        <property name="inHandlers">
            <list>
                <ref bean="domInHandler"/>
                <ref bean="wss4jInHandler"/>
                <ref bean="validateUserTokenHandler"/>
            </list>
        </property>
    </bean>

    <bean id="domInHandler" class="org.codehaus.xfire.util.dom.DOMInHandler"/>

    <bean id="wss4jInHandler" class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
        <property name="properties">
            <props>
                <prop key="action">UsernameToken</prop>
                <prop key="passwordCallbackClass">org.springside.bookstore.plugins.xfire.wss4j.PasswordHandler</prop>
            </props>
        </property>
    </bean>

    <bean id="validateUserTokenHandler" class="org.springside.bookstore.plugins.xfire.wss4j.WSS4JTokenHandler"/>
    
    <!--  (4)BookWebService    WSS4J   Encrypt  -->
    <bean id="bookServiceWSS4JEnc" class="org.codehaus.xfire.spring.remoting.XFireExporter">
        <property name="serviceBean" ref="bookManager"/>
        <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookServiceWSS4JEnc"/>
        <property name="inHandlers">
            <list>
                <ref bean="domInHandler"/>
                <ref bean="wss4jInHandlerEnc"/>
                <ref bean="validateUserTokenHandler"/>
            </list>
        </property>
    </bean>
        
    <bean id="wss4jInHandlerEnc" class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
        <property name="properties">
          <props>
            <prop key="action">Encrypt</prop>
            <prop key="decryptionPropFile">org/springside/bookstore/plugins/xfire/wss4j/insecurity_enc.properties</prop>
            <prop key="passwordCallbackClass">org.springside.bookstore.plugins.xfire.wss4j.PasswordHandler</prop>
          </props>
        </property>
    </bean>
    
    <!--  (5)BookWebService    WSS4J   Signature  -->
    <bean id="bookServiceWSS4JSign" class="org.codehaus.xfire.spring.remoting.XFireExporter">
        <property name="serviceBean" ref="bookManager"/>
        <property name="serviceClass" value="org.springside.bookstore.plugins.xfire.service.BookServiceWSS4JSign"/>
        <property name="inHandlers">
            <list>
                <ref bean="domInHandler"/>
                <ref bean="wss4jInHandlerSign"/>
                <ref bean="validateUserTokenHandler"/>
            </list>
        </property>
    </bean>
    
    <bean id="wss4jInHandlerSign" class="org.codehaus.xfire.security.wss4j.WSS4JInHandler">
        <property name="properties">
          <props>
            <prop key="action">Signature</prop>
            <prop key="signaturePropFile">org/springside/bookstore/plugins/xfire/wss4j/insecurity_sign.properties</prop>
            <prop key="passwordCallbackClass">org.springside.bookstore.plugins.xfire.wss4j.PasswordHandler</prop>
          </props>
        </property>
    </bean>
    
</beans>

  ,  insecurity_enc.properties insecurity_sign.properties         
insecurity_enc.properties:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=SpringSide
org.apache.ws.security.crypto.merlin.alias.password=SpringSide
org.apache.ws.security.crypto.merlin.keystore.alias=david
org.apache.ws.security.crypto.merlin.file=org/springside/bookstore/plugins/xfire/wss4j/springside_private.jks
outsecurity_sign.properties:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=SpringSide
org.apache.ws.security.crypto.merlin.keystore.alias=david
org.apache.ws.security.crypto.merlin.file=org/springside/bookstore/plugins/xfire/wss4j/springside_public.jks
  ,  SecureX     keystore  
springside_private.jks
    : david
    : 2006-8-6
    :KeyEntry
     : 1
   [1]:
Owner: CN=david, OU=SpringSide, O=org, L=gz, ST=gd, C=cn
   : CN=david, OU=SpringSide, O=org, L=gz, ST=gd, C=cn
  : 44d4cdcd
    : Sun Aug 06 00:56:45 CST 2006  : Mon Aug 06 00:56:45 CST 2007
    :
         MD5:  CF:97:13:0C:70:D0:4D:B6:B4:27:0F:1A:0B:CF:D9:F2
         SHA1: 8E:8E:E8:BC:64:39:C8:43:E4:F7:1B:3B:CE:48:1D:6B:A0:2B:58:B5
springside_public.jks
    : david
    : 2006-8-6
    : trustedCertEntry

Owner: CN=david, OU=SpringSide, O=org, L=gz, ST=gd, C=cn
   : CN=david, OU=SpringSide, O=org, L=gz, ST=gd, C=cn
  : 44d4cdcd
    : Sun Aug 06 00:56:45 CST 2006  : Mon Aug 06 00:56:45 CST 2007
    :
         MD5:  CF:97:13:0C:70:D0:4D:B6:B4:27:0F:1A:0B:CF:D9:F2
         SHA1: 8E:8E:E8:BC:64:39:C8:43:E4:F7:1B:3B:CE:48:1D:6B:A0:2B:58:B5
  ,   SpringSide  
http://www.bouncycastle.org/download/bcprov-jdk15-133.jar
     java.security
  ,    jdk      
http://www.blogjava.net/openssl/archive/2006/03/08/34381.html

     WSS4J,    Bouncycastle  SecurityProvider,  
  Enc   XFire     ,     :
org.apache.ws.security.WSSecurityException: An unsupported signature or encryption algorithm was used unsupported key
  java.security      :
     BouncycastleProvider。
security.provider.1=sun.security.provider.Sun
security.provider.2=com.sun.net.ssl.internal.ssl.Provider
security.provider.3=com.sun.rsajca.Provider
security.provider.4=com.sun.crypto.provider.SunJCE
security.provider.5=sun.security.jgss.SunProvider
security.provider.6=org.bouncycastle.jce.provider.BouncyCastleProvider

[WebService Client   ]
1,Encrypt   Client      david     Soap   usernameToken,     Web  ,Web   david      。                    。

 Encrypt   ,      ClientHandler:
        Service serviceModel = new ObjectServiceFactory().create(BookServiceWSS4JEnc.class);
        XFireProxyFactory factory = new XFireProxyFactory(getXFire());

        BookService service = (BookService) factory.create(serviceModel, "xfire.local://BookServiceWSS4JEnc");

        Client client = ((XFireProxy) Proxy.getInvocationHandler(service)).getClient();
        //  WSS4JOutHandler,    
        client.addOutHandler(new DOMOutHandler());
        Properties properties = new Properties();
        configureOutProperties(properties);
        client.addOutHandler(new WSS4JOutHandler(properties));

        List list = service.getAllCategorys();configureOutProperties      Client        ,  ,  outsecurity_enc.properties,  properties  Server  insecurity_enc.properties     。
    protected void configureOutProperties(Properties config) {
        config.setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.ENCRYPT);
        config.setProperty(WSHandlerConstants.USER, "david");
        //config.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordHandler.class.getName());
        //Configuration of public key used to encrypt message goes to properties file.
        config.setProperty(WSHandlerConstants.ENC_PROP_FILE,
                               "org/springside/bookstore/plugins/xfire/outsecurity_enc.properties");
    }

outsecurity_enc.properties:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=SpringSide
org.apache.ws.security.crypto.merlin.keystore.alias=david
org.apache.ws.security.crypto.merlin.file=org/springside/bookstore/plugins/xfire/wss4j/springside_public.jks

2, Sign   Client       ,     Client        usernameToken  ,     Client        ,  ,                。
   Encrypt  ,   configureOutProperties       :
    protected void configureOutProperties(Properties properties) {
        properties.setProperty(WSHandlerConstants.ACTION,WSHandlerConstants.SIGNATURE);
        // User in keystore
        properties.setProperty(WSHandlerConstants.USER, "david");
        // This callback is used to specify password for given user for keystore
        properties.setProperty(WSHandlerConstants.PW_CALLBACK_CLASS, PasswordHandler.class.getName());
        // Configuration for accessing private key in keystore
        properties.setProperty(WSHandlerConstants.SIG_PROP_FILE,"org/springside/bookstore/plugins/xfire/outsecurity_sign.properties");
        properties.setProperty(WSHandlerConstants.SIG_KEY_ID,"IssuerSerial");
    }


outsecurity_sign.properties:
org.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin
org.apache.ws.security.crypto.merlin.keystore.type=jks
org.apache.ws.security.crypto.merlin.keystore.password=SpringSide
org.apache.ws.security.crypto.merlin.alias.password=SpringSide
org.apache.ws.security.crypto.merlin.keystore.alias=david
org.apache.ws.security.crypto.merlin.file=org/springside/bookstore/plugins/xfire/wss4j/springside_private.jks

좋은 웹페이지 즐겨찾기