CXF、WS-Security 和 Spring:UserToken
我的 websrervice 使用身份验证工作,但问题是它是静态的,它写在 XML 文件中,甚至写在实现 CallbackHandler 的类中。 我想执行我的网络服务,但使用用户在控制台中输入的登录名和密码
这是我编写用户的客户端部分:
<bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<property name="properties">
<map>
<entry key="action" value="UsernameToken Timestamp" />
**<entry key="user" value="pT64f349"/>**
<entry key="passwordType" value="PasswordDigest" />
<entry>
<key>
<value>passwordCallbackRef</value>
</key>
<ref bean="passwordCallback" />
</entry>
</map>
</property>
</bean>
这是我放置密码的地方:
public class ClientPasswordCallback implements CallbackHandler{
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback callback = (WSPasswordCallback) callbacks[0];
if(callback.getIdentifier().equals("pT64f349")){
**callback.setPassword("pass");**
}
}
}
非常感谢
My websrervice works using authentication, but the problem is that it's static, it's written in the XML file, and even in the class that implements CallbackHandler.
I want to execute my webservice but by using a login and a password that user will enter in a console
This is the client part where I wrote the user :
<bean id="wss4jOutInterceptor" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<property name="properties">
<map>
<entry key="action" value="UsernameToken Timestamp" />
**<entry key="user" value="pT64f349"/>**
<entry key="passwordType" value="PasswordDigest" />
<entry>
<key>
<value>passwordCallbackRef</value>
</key>
<ref bean="passwordCallback" />
</entry>
</map>
</property>
</bean>
And this is where I put my password :
public class ClientPasswordCallback implements CallbackHandler{
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
WSPasswordCallback callback = (WSPasswordCallback) callbacks[0];
if(callback.getIdentifier().equals("pT64f349")){
**callback.setPassword("pass");**
}
}
}
Thnx a lot
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以调整您的 ClientPasswordCallback 来从 ThreadLocal 读取用户输入(请参阅 Javadoc 和 示例 1 或示例 2)。
您必须首先将输入填充到
ThreadLocal
中,然后您可以在ClientPasswordCallback
中读取它们。You could maybe adapt your
ClientPasswordCallback
to read the user inputs from aThreadLocal
(see Javadoc and example 1 or example 2).You'll have first to fill the inputs into the
ThreadLocal
and then you can read them in theClientPasswordCallback
.