【问题标题】:Autowire failed in Password Callback ClassAutowire 在密码回调类中失败
【发布时间】:2017-03-23 09:42:42
【问题描述】:

我正在使用WSS4JOutInterceptorWSS4JInInterceptor 来拦截soap web 服务。在那里我正在使用

密码回调类

示例拦截器

<bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor" id="inbound-security">
    <constructor-arg>
        <map>
            <entry key="action" value="Signature Encrypt"/>
            <entry key="signaturePropFile" value="serviceKeystore.properties"/>
            <entry key="decryptionPropFile" value="clientKeystore.properties"/>
            <entry key="passwordCallbackClass" value="com.service.toolprovider.ToolProviderCallbackHandler"/>
        </map>
    </constructor-arg>
</bean>

在我的密码回调类中,我需要注入另一个类来获取密码。

@Component
public class ToolProviderCallbackHandler implements CallbackHandler {

    @Autowired
    private IAuthenticationConfiguration configuration;

    @Override
    public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {

        for (Callback callback : callbacks) {

            WSPasswordCallback wsPasswordCallback = (WSPasswordCallback) callback;

            if (wsPasswordCallback.getUsage() == WSPasswordCallback.SIGNATURE || wsPasswordCallback.getUsage() == WSPasswordCallback.DECRYPT) {

                if (wsPasswordCallback.getIdentifier().equals("client alias")) {
                    wsPasswordCallback.setPassword("password");
                }
            }
        }
    }
}

但是这里自动接线不起作用。配置属性始终为空。

【问题讨论】:

  • 我也有同样的问题

标签: spring autowired wss4j


【解决方案1】:

对于将来遇到此问题的任何人,我遇到了同样的问题并使用以下方法解决了: https://dzone.com/articles/autowiring-spring-beans-into-classes-not-managed-by-spring


@Service
public class BeanUtil implements ApplicationContextAware {
    private static ApplicationContext context;
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
    public static <T> T getBean(Class<T> beanClass) {
        return context.getBean(beanClass);
    }
}

然后在回调处理程序中使用 BeanUtil.getBean(IAuthenticationConfiguration.class) 设置配置

【讨论】:

    【解决方案2】:

    将您的配置保存在 passwordCallbackClass 的拦截器中,如下所示,这将有助于您的密码回调处理程序也由 Spring 管理。

    这意味着您的自动接线将起作用

    <bean class="org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor" id="inbound-security">
        <constructor-arg>
            <map>
                <entry key="action" value="Signature Encrypt"/>
                <entry key="signaturePropFile" value="serviceKeystore.properties"/>
                <entry key="decryptionPropFile" value="clientKeystore.properties"/>
                <entry>
                        <key>
                            <value>passwordCallbackRef</value>
                        </key>
                        <ref bean="passwordCallbackHandler" />
                    </entry>
            </map>
        </constructor-arg>
    </bean>
    
    <bean id="passwordCallbackHandler" class="com.service.toolprovider.ToolProviderCallbackHandler" />
    

    参考:https://deepintojee.wordpress.com/2010/12/13/securing-a-webservice-at-method-level-apache-cxf-spring-security-jsr-250-wss4j/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-04-29
      • 2015-09-02
      • 2013-05-12
      • 2015-07-06
      • 2015-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多