UsernameTokenValidator 不能@Autowired Dao

问题描述 投票:0回答:3

我有一个 Spring-ws,我正在使用 Apahce-wss4j 进行 spring-ws 身份验证。我想在我的自定义 TokenValidator 类中使用我的 Dao 类。但有一个例外,不能 @Autowired 我的 Dao 类。这是我的代码

applicationContext.xml

<bean id="myWssConfig" class="tr.com.xxx.services.MyWssConfig"/>
      <bean id="kepDBDAO" class="tr.com.xxx.dao.KepDBDAOImpl"/>
      <bean id="ssha" class="tr.com.xxx.utils.SSHA"/>
      <bean id="memberStatusService" class="tr.com.xxx.services.MemberStatusServiceImpl"/>
      <bean id="myUsernameTokenValidator" class="tr.com.xxx.services.MyUsernameTokenValidator">
          <property name="kepDBDAO" ref="kepDBDAO"/>
      </bean>

<sws:interceptors>
    <bean class="org.springframework.ws.soap.security.wss4j.Wss4jSecurityInterceptor">
        <property name="validationActions" value="UsernameToken"/>
        <property name="validationCallbackHandler" ref="callbackHandler"/>
        <property name="wssConfig">
            <ref bean="myWssConfig"/>
        </property>
    </bean>
</sws:interceptors>

这里是MyWssConfig.java

@Component("myWssConfig")
public class MyWssConfig extends WSSConfig {

    public MyWssConfig() {
        setValidator(WSSecurityEngine.USERNAME_TOKEN, MyUsernameTokenValidator.class);
        setRequiredPasswordType(WSConstants.PASSWORD_TEXT);
    }
}

这是 MyUsernameTokenValidator.java

@Component
public class MyUsernameTokenValidator extends UsernameTokenValidator {


    private static final Logger LOGGER = LoggerFactory
            .getLogger(MyUsernameTokenValidator.class);

    @Autowired
    private KepDBDAO kepDBDAO;

    @Transactional
    protected void verifyPlaintextPassword(UsernameToken usernameToken, RequestData data) throws WSSecurityException {
        if (usernameToken != null && usernameToken.getPassword() != null) {   

            byte[] saltValue = null;
            kepDBDAO.getWsUsers("basvuru");
            String hashPassword = null;
            try {
                hashPassword = SSHA.calculateSSHA256(saltValue, usernameToken.getPassword());
            } catch (NoSuchAlgorithmException e) {
                LOGGER.error(e.toString(), e);
            } catch (IOException e) {
                LOGGER.error(e.toString(), e);
            }


            usernameToken.setPassword(hashPassword);


            super.verifyDigestPassword(usernameToken, data);
        }
    }

    public KepDBDAO getKepDBDAO() {
        return kepDBDAO;
    }

    public void setKepDBDAO(KepDBDAO kepDBDAO) {
        this.kepDBDAO = kepDBDAO;
    }
}

当我在 SOAPUI 中调用 Web 服务时,无法@Autowired 我的 KepDBDAO。

请帮助我..谢谢大家。

spring web-services hibernate autowired spring-ws
3个回答
0
投票
Try this:

1. In applicationContext:

<context:component-scan base-package="tr.com.xxx.dao"/> 
<context:component-scan base-package="package for MyUsernameTokenValidator"/>

remove these beans:

kepDBDAO, myUsernameTokenValidator

2. Remove setter and getter for KepDBDAO in MyUsernameTokenValidator 

3. Make sure KepDBDAOImpl is marked as @Service

0
投票

我解决了我的问题。

@Component("myWssConfig")
public class MyWssConfig extends WSSConfig {

    @Autowired
    private MyUsernameTokenValidator myUsernameTokenValidator;

    //
    @PostConstruct
    public void myInit() {
        setValidator(WSSecurityEngine.USERNAME_TOKEN, myUsernameTokenValidator);
        setRequiredPasswordType(WSConstants.PASSWORD_TEXT);
    }
}

0
投票

你能帮助我自定义 CustomUsernameTokenValidator

© www.soinside.com 2019 - 2024. All rights reserved.