繁体   English   中英

使用领域的JAX-WS基本认证

[英]JAX-WS basic authentication using realm

我有一个jax-ws Web服务,正在使用基本身份验证。 我将向您展示在我的问题中最重要的2条代码片段。 Web服务方式

@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()); 

Web服务客户端

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>

我的日志输出在运行时发生变化,没有任何意义。 信息:大卫信息:大卫信息:管理员信息:管理员信息:管理员

大卫是正确的用户,我不知道管理员来自哪里?

您应该根据所使用的Web服务引擎在web.xml中有一个servlet映射。 例如,我在tomcat上使用Metro堆栈,并具有以下web.xml:

<?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">
<listener>
    <listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
    <servlet-name>CallNotificationService</servlet-name>
    <servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>CallNotificationService</servlet-name>
    <url-pattern>/CallNotificationService</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
</web-app>

您需要让容器知道谁在处理传入请求。 但是,这不能解决身份验证问题。 您确定这是身份验证问题,而不仅仅是服务器上的配置问题吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM