Java Glassfish基本身份验证错误

Java Glassfish基本身份验证错误,java,xml,web-services,soap,glassfish,Java,Xml,Web Services,Soap,Glassfish,我有下一个方法: @RolesAllowed("basicUser") @Override public boolean LogOn(String UserName, String Password) { ... } 这是my web.xml: http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"> HelloService <session-config> <session-timeout>3

我有下一个方法:

@RolesAllowed("basicUser")
    @Override
    public boolean LogOn(String UserName, String Password) {
...
}
这是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>

您似乎需要首先创建一个由wsdl URI加上我的用户名和密码组成的authfile。您可以查看详细信息

如果您使用JAX-WS,请尝试添加文件sun-jaxws.xml和下一个内容:

<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>


请看,谢谢!我现在就试试。我正在做。我正在从*.war文件部署web服务。现在我遇到了下一个错误(我在UPD中排名靠前)
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>
    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)
<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>