PasswordService.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:XPagesToolkit 作者:
public ExecutionUserProperties checkPassword(String strUser, String strPW, String strURL) {
    ExecutionUserProperties eupRC = new ExecutionUserProperties();
    eupRC.setLoggedIn(false);
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();

        httpClient = (DefaultHttpClient) ClientSSLResistanceExtender.wrapClient(httpClient);
        httpClient.setRedirectStrategy(new DefaultRedirectStrategy());
        /*
         * String strNSFURL = strURL; String strRedirection = strNSFURL +
         * "/xsp/xpage.agent?loginCheck"; java.util.List<NameValuePair>
         * formparams = new ArrayList<NameValuePair>(); formparams.add(new
         * BasicNameValuePair("username", strUser)); formparams.add(new
         * BasicNameValuePair("password", strPW)); formparams.add(new
         * BasicNameValuePair("redirectto", strRedirection));
         * UrlEncodedFormEntity entity = new
         * UrlEncodedFormEntity(formparams, "UTF-8");
         * 
         * HttpPost postRequest = new HttpPost(strNSFURL + "?login");
         * postRequest.getParams().setParameter(ClientPNames.COOKIE_POLICY,
         * org
         * .apache.http.client.params.CookiePolicy.BROWSER_COMPATIBILITY);
         * 
         * postRequest.setHeader("Content-Type",
         * "application/x-www-form-urlencoded");
         * postRequest.addHeader("accept", "application/json");
         * postRequest.setEntity(entity); HttpResponse hsr =
         * httpClient.execute(postRequest); for (Cookie ck :
         * httpClient.getCookieStore().getCookies()) { if
         * ("LtpaToken".equalsIgnoreCase(ck.getName())) { blRC = true; } if
         * ("DomAuthSessId".equalsIgnoreCase(ck.getName())) { blRC = true; }
         * }
         */
        String strNSFURL = strURL;
        String strRedirection = strNSFURL + "/xsp/xpage.agent?action=checkLogin";
        HttpGet getRequestINIT = new HttpGet(strNSFURL);

        HttpGet getRequest = new HttpGet(strRedirection);
        getRequest.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(strUser, strPW), "UTF-8", false));
        getRequestINIT.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials(strUser, strPW), "UTF-8", false));
        HttpResponse hsrINTI = httpClient.execute(getRequestINIT);
        if (hsrINTI.getStatusLine().getStatusCode() == 200) {
            EntityUtils.consume(hsrINTI.getEntity());
            HttpResponse hsr = httpClient.execute(getRequest);
            JsonJavaObject json = (JsonJavaObject) JsonParser.fromJson(JsonJavaFactory.instanceEx, EntityUtils.toString(hsr.getEntity()));

            if (json.getString("status").equalsIgnoreCase("ok")) {
                eupRC.setLoggedIn(true);
                eupRC.setUserName(json.getString("username"));
                eupRC.setAccessLevel(json.getInt("level"));
            } else {
                eupRC.setLoggedIn(false);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return eupRC;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号