2013-03-11 45 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); 
相關問題