我有一个 jax-ws Web 服务,并且正在使用基本身份验证。我将向您展示在我的问题中最重要的 2 段代码。网络服务方法
@WebMethod(operationName = "createBook")
public String createBook(@WebParam(name = "name") Book entity)
{
Logger LOG = Logger.getLogger(Bookservice.class.getName());
LOG.log(Level.INFO, secure_ctx.getUserPrincipal().getName());
网络服务客户端
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Soapservice ss = new Soapservice();
Bookservice bs = ss.getBookservicePort();
//com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump=true;
//client.addFilter(new LoggingFilter());
try
{
System.setProperty("javax.xml.bind.JAXBContext", "com.sun.xml.internal.bind.v2.ContextFactory");
BindingProvider bind_provider = (BindingProvider) bs;
bind_provider .getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "tom");
bind_provider .getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "jones");
this.jTextField1.setText(bs.createBook(null));
} catch (Exception e)
{
java.util.logging.Logger LOG = java.util.logging.Logger.getLogger(testframe.class.getName());
LOG.log(Level.SEVERE, null, e);
}
身份验证不适用于正确的登录详细信息。服务器日志有时也会产生正确的主体名称,但是当它发生并且我更改用户名时,会出现“admin”。当我将其更改回原始用户名时,服务器日志仍为“admin”。我在使用球衣的休息服务中使用了这种机制,没有问题。
有谁知道这是否与我的 web.xml 中没有 servlet 适配器映射有关?
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<security-constraint>
<display-name>Constraint1</display-name>
<web-resource-collection>
<web-resource-name>soapservice</web-resource-name>
<description/>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<description>Access to book services</description>
<role-name>administrator</role-name>
<role-name>developer</role-name>
<role-name>manager</role-name>
</auth-constraint>
<user-data-constraint>
<description/>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>jdbcr</realm-name>
</login-config>
<security-role>
<description>Has complete priviligies on access to soap api</description>
<role-name>administrator</role-name>
</security-role>
<security-role>
<description>Develops applications using soap api, has certain priviligies</description>
<role-name>developer</role-name>
</security-role>
<security-role>
<description>Has access to users and their role priviligies</description>
<role-name>manager</role-name>
</security-role>
</web-app>
我的日志输出在运行时发生变化,没有任何意义。信息:大卫 信息:大卫 信息:管理员 信息:管理员 信息:管理员
大卫是一个正确的用户,我不知道管理员来自哪里??