@Test public void testLogin() throws Exception { handler.authenticate(); AliRestClient client = AliRestClient.create(handler.getQcUrl(), "domain", "project", "user", "password", RestClient.SessionStrategy.NONE); client.login(); }
@Override public synchronized void login() { List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate"); String authXml = createAuthXml(); PostMethod post = initPostMethod(authPoint, authXml); ResultInfo resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if(resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) { Credentials cred = new UsernamePasswordCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8"); httpClient.getState().setCredentials(scope, cred); authPoint = pathJoin("/", location, "/authentication-point/authenticate"); GetMethod get = new GetMethod(authPoint); resultInfo = ResultInfo.create(null); executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet()); } HttpStatusBasedException.throwForError(resultInfo); if(resultInfo.getHttpStatus() != 200) { throw new AuthenticationFailureException(resultInfo); } Cookie[] cookies = httpClient.getState().getCookies(); Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME); addTenantCookie(ssoCookie); String siteSessionPoint = pathJoin("/", location, "/rest/site-session"); String sessionParamXml = createRestSessionXml(); post = initPostMethod(siteSessionPoint, sessionParamXml); resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) { HttpStatusBasedException.throwForError(resultInfo); } cookies = httpClient.getState().getCookies(); Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME); sessionContext = new SessionContext(location, ssoCookie, qcCookie); }
AliRestClient implements RestClient { @Override public synchronized void login() { List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate"); String authXml = createAuthXml(); PostMethod post = initPostMethod(authPoint, authXml); ResultInfo resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if(resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) { Credentials cred = new UsernamePasswordCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8"); httpClient.getState().setCredentials(scope, cred); authPoint = pathJoin("/", location, "/authentication-point/authenticate"); GetMethod get = new GetMethod(authPoint); resultInfo = ResultInfo.create(null); executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet()); } HttpStatusBasedException.throwForError(resultInfo); if(resultInfo.getHttpStatus() != 200) { throw new AuthenticationFailureException(resultInfo); } Cookie[] cookies = httpClient.getState().getCookies(); Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME); addTenantCookie(ssoCookie); String siteSessionPoint = pathJoin("/", location, "/rest/site-session"); String sessionParamXml = createRestSessionXml(); post = initPostMethod(siteSessionPoint, sessionParamXml); resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) { HttpStatusBasedException.throwForError(resultInfo); } cookies = httpClient.getState().getCookies(); Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME); sessionContext = new SessionContext(location, ssoCookie, qcCookie); } }
AliRestClient implements RestClient { @Override public synchronized void login() { List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate"); String authXml = createAuthXml(); PostMethod post = initPostMethod(authPoint, authXml); ResultInfo resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if(resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) { Credentials cred = new UsernamePasswordCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8"); httpClient.getState().setCredentials(scope, cred); authPoint = pathJoin("/", location, "/authentication-point/authenticate"); GetMethod get = new GetMethod(authPoint); resultInfo = ResultInfo.create(null); executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet()); } HttpStatusBasedException.throwForError(resultInfo); if(resultInfo.getHttpStatus() != 200) { throw new AuthenticationFailureException(resultInfo); } Cookie[] cookies = httpClient.getState().getCookies(); Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME); addTenantCookie(ssoCookie); String siteSessionPoint = pathJoin("/", location, "/rest/site-session"); String sessionParamXml = createRestSessionXml(); post = initPostMethod(siteSessionPoint, sessionParamXml); resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) { HttpStatusBasedException.throwForError(resultInfo); } cookies = httpClient.getState().getCookies(); Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME); sessionContext = new SessionContext(location, ssoCookie, qcCookie); } private  AliRestClient(String location, String domain, String project,
                          String userName, String password,
                          SessionStrategy sessionStrategy); }
AliRestClient implements RestClient { @Override public synchronized void login() { List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate"); String authXml = createAuthXml(); PostMethod post = initPostMethod(authPoint, authXml); ResultInfo resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if(resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) { Credentials cred = new UsernamePasswordCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8"); httpClient.getState().setCredentials(scope, cred); authPoint = pathJoin("/", location, "/authentication-point/authenticate"); GetMethod get = new GetMethod(authPoint); resultInfo = ResultInfo.create(null); executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet()); } HttpStatusBasedException.throwForError(resultInfo); if(resultInfo.getHttpStatus() != 200) { throw new AuthenticationFailureException(resultInfo); } Cookie[] cookies = httpClient.getState().getCookies(); Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME); addTenantCookie(ssoCookie); String siteSessionPoint = pathJoin("/", location, "/rest/site-session"); String sessionParamXml = createRestSessionXml(); post = initPostMethod(siteSessionPoint, sessionParamXml); resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) { HttpStatusBasedException.throwForError(resultInfo); } cookies = httpClient.getState().getCookies(); Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME); sessionContext = new SessionContext(location, ssoCookie, qcCookie); } private  AliRestClient(String location, String domain, String project,
                          String userName, String password,
                          SessionStrategy sessionStrategy); static AliRestClient create(String location, String domain, String project, String userName, String password, SessionStrategy sessionStrategy); @Override void setTimeout(int timeout); @Override void setHttpProxy(String proxyHost, int proxyPort); @Override void setHttpProxyCredentials(String username, String password); @Override String getEncoding(); @Override SessionStrategy getSessionStrategy(); @Override void setEncoding(String encoding); @Override void setDomain(String domain); @Override void setProject(String project); @Override String getDomain(); @Override String getProject(); @Override List<Cookie> getCookies(String cookieName); @Override synchronized void login(); @Override synchronized void logout(); @Override String getForString(String template, Object... params); @Override InputStream getForStream(String template, Object... params); @Override int get(ResultInfo result, String template, Object... params); @Override int put(InputData inputData, ResultInfo result, String template, Object... params); @Override int delete(ResultInfo result, String template, Object... params); @Override int post(InputData data, ResultInfo result, String template, Object... params); @Override List<String> listDomains(); @Override List<String> listCurrentProjects(); }
AliRestClient implements RestClient { @Override public synchronized void login() { List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); httpClient.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); String authPoint = pathJoin("/", location, "/authentication-point/alm-authenticate"); String authXml = createAuthXml(); PostMethod post = initPostMethod(authPoint, authXml); ResultInfo resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if(resultInfo.getHttpStatus() == HttpStatus.SC_NOT_FOUND) { Credentials cred = new UsernamePasswordCredentials(userName, password); AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT); httpClient.getParams().setParameter(HttpMethodParams.CREDENTIAL_CHARSET, "UTF-8"); httpClient.getState().setCredentials(scope, cred); authPoint = pathJoin("/", location, "/authentication-point/authenticate"); GetMethod get = new GetMethod(authPoint); resultInfo = ResultInfo.create(null); executeAndWriteResponse(get, resultInfo, Collections.<Integer>emptySet()); } HttpStatusBasedException.throwForError(resultInfo); if(resultInfo.getHttpStatus() != 200) { throw new AuthenticationFailureException(resultInfo); } Cookie[] cookies = httpClient.getState().getCookies(); Cookie ssoCookie = getSessionCookieByName(cookies, COOKIE_SSO_NAME); addTenantCookie(ssoCookie); String siteSessionPoint = pathJoin("/", location, "/rest/site-session"); String sessionParamXml = createRestSessionXml(); post = initPostMethod(siteSessionPoint, sessionParamXml); resultInfo = ResultInfo.create(null); executeAndWriteResponse(post, resultInfo, Collections.<Integer>emptySet()); if (resultInfo.getHttpStatus() != HttpStatus.SC_FORBIDDEN) { HttpStatusBasedException.throwForError(resultInfo); } cookies = httpClient.getState().getCookies(); Cookie qcCookie = getSessionCookieByName(cookies, COOKIE_SESSION_NAME); sessionContext = new SessionContext(location, ssoCookie, qcCookie); } private  AliRestClient(String location, String domain, String project,
                          String userName, String password,
                          SessionStrategy sessionStrategy); static AliRestClient create(String location, String domain, String project, String userName, String password, SessionStrategy sessionStrategy); @Override void setTimeout(int timeout); @Override void setHttpProxy(String proxyHost, int proxyPort); @Override void setHttpProxyCredentials(String username, String password); @Override String getEncoding(); @Override SessionStrategy getSessionStrategy(); @Override void setEncoding(String encoding); @Override void setDomain(String domain); @Override void setProject(String project); @Override String getDomain(); @Override String getProject(); @Override List<Cookie> getCookies(String cookieName); @Override synchronized void login(); @Override synchronized void logout(); @Override String getForString(String template, Object... params); @Override InputStream getForStream(String template, Object... params); @Override int get(ResultInfo result, String template, Object... params); @Override int put(InputData inputData, ResultInfo result, String template, Object... params); @Override int delete(ResultInfo result, String template, Object... params); @Override int post(InputData data, ResultInfo result, String template, Object... params); @Override List<String> listDomains(); @Override List<String> listCurrentProjects(); static final Set<Integer> AUTH_FAIL_STATUSES; static final int DEFAULT_CLIENT_TIMEOUT; }