简体   繁体   中英

Glassfish basic auth error

I have next method:

@RolesAllowed("basicUser")
    @Override
    public boolean LogOn(String UserName, String Password) {
...
}

This my web.xml:

http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> HelloService

<session-config>
    <session-timeout>30</session-timeout>
</session-config>
<security-constraint>
    <display-name>SecurityConstraint</display-name>
    <!-- web resources that are protected -->
    <web-resource-collection>
        <web-resource-name>Secure Pages</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <!-- role-name indicates roles that are allowed to access the web resource specified above -->
        <role-name>basicUser</role-name>
    </auth-constraint>
     <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
    </user-data-constraint>
</security-constraint>
<login-config>
    <auth-method>BASIC</auth-method>
    <realm-name>file</realm-name>
</login-config>
<security-role>
    <role-name>basicUser</role-name>
</security-role>

And sun-web:

<security-role-mapping>
    <role-name>basicUser</role-name>
    <group-name>client</group-name>
</security-role-mapping>

In Glassfish server, in Server-config -> Secirity -> Realms - > File, Assign Groups: cleint , and user with group client present. Deploy run success. When i'm testing web-service, i'm get next error:

INFO:   parsing WSDL...
INFO:   [ERROR] Server returned HTTP response code: 401 for URL:
http://localhost:8080/CalculatorWSApplication/WebServiceImplService?WSDL,
"http://localhost:8080/CalculatorWSApplication/WebServiceImplService?WSDL" needs 
authorization, please provide authorization file with read access at
C:\Users\user.t\.metro\auth or use -Xauthfile to give the authorization
file and on each line provide authorization information using this format :
http[s]://user:password@host:port//<url-path>

PS Without basic-authentication, web-service deploy and testing successfull.

UPD

Exceptions details : null

    com.sun.tools.ws.wscompile.AbortException at 
com.sun.tools.ws.wsdl.parser.MetadataFinder$WSEntityResolver.resolveEntity(MetadataFinder.java:202) at 
com.sun.tools.ws.wsdl.parser.DOMForest.parse(DOMForest.java:212) at
com.sun.tools.ws.wsdl.parser.DOMForest.parse(DOMForest.java:148) at
com.sun.tools.ws.wsdl.parser.MetadataFinder.parseWSDL(MetadataFinder.java:111) at
com.sun.tools.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:439) at
com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:205) at
com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:183) at
com.sun.tools.ws.util.WSToolsObjectFactoryImpl.wsimport(WSToolsObjectFactoryImpl.java:60)at 
com.sun.tools.ws.spi.WSToolsObjectFactory.wsimport(WSToolsObjectFactory.java:88) at
org.glassfish.webservices.monitoring.WebServiceTesterServlet.wsImport(WebServiceTesterServlet.java:642) at
org.glassfish.webservices.monitoring.WebServiceTesterServlet.initializePort(WebServiceTesterServlet.java:528) at 
org.glassfish.webservices.monitoring.WebServiceTesterServlet.doGet(WebServiceTesterServlet.java:169) at 
org.glassfish.webservices.monitoring.WebServiceTesterServlet.invoke(WebServiceTesterServlet.java:104) at 
org.glassfish.webservices.JAXWSServlet.doGet(JAXWSServlet.java:210) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:687) at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:790) at
org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318) at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at
org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at
com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at 
org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:357) at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260) at 
com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:188) at
org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191) at
org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168) at
org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:189) at
org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288) at
org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206) at
org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)at 
org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)at 
org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at
org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:838)at 
org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113) at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115) at 
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55) at
org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135) at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:564) at
org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:544)at java.lang.Thread.run(Thread.java:744)

It seems you need to first create an authfile composed of the wsdl URI plus my username and password. You can see the details here

If you use JAX-WS, try add file sun-jaxws.xml with next contents:

<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
    <endpoint
        name='YOUR_NAME'
        implementation='yourpacket.Web_Service_Implementation'
        url-pattern='/*'/>
</endpoints>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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