2013-03-11 103 views
0

甚至可能吗?文件没有说清楚。我尝试了各种不同的机制来获得身份验证的工作,但我不断得到一个“401:未经授权”的错误。这里是我在哪里:Axis2甚至可以使用BASIC认证

stub = new EngineStub(); 

    HttpClient client = new HttpClient(); 
    client.getParams().setAuthenticationPreemptive(true); 
    stub._getServiceClient().getServiceContext().getConfigurationContext().setProperty(HTTPConstants.CACHED_HTTP_CLIENT, client); 

    HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator(); 
    List<String> authpref = new ArrayList<String>(); 
    authpref.add(AuthPolicy.BASIC); 
    auth.setAuthSchemes(authpref); 
    auth.setUsername(username); 
    auth.setPassword(password); 
    auth.setPreemptiveAuthentication(true); 
    stub._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth); 
+0

看一看这样的: http://stackoverflow.com/questions/3283234/http-basic-authentication-in-java-using-httpclient – 2013-03-11 04:09:59

+0

还共享安全如何配置这些网页的细节-服务。 – 2013-03-11 04:11:09

+0

关于此的文档是无用的。整件事情都被打破了。 – Jacob 2013-03-11 05:30:57

回答

1

你是什么意思axis2与BASIC AUTH合作?如果您的后端服务使用基本身份验证进行安全保护,则您只需从客户端设置基本身份验证标头并发送请求即可。你的客户代码看起来正确;不确定关于授权政策;尝试没有这样;

auth.setUsername(USER_NAME); 
    auth.setPassword(PASSWORD); 
    auth.setPreemptiveAuthentication(true); 
    option.setProperty(org.apache.axis2.transport.http.HTTPConstants.AUTHENTICATE, auth); 
    option.setManageSession(true); 
相关问题