List of usage examples for org.apache.commons.httpclient HttpStatus SC_UNAUTHORIZED
int SC_UNAUTHORIZED
To view the source code for org.apache.commons.httpclient HttpStatus SC_UNAUTHORIZED.
Click Source Link
From source file:com.thoughtworks.twist.mingle.core.MingleClientTest.java
public void testThrowsMingleAuthenticationExceptionOnHttpStatus401() throws Exception { MingleClient mingleClient = new TestMingleClient("http://localhost:30001/projects/foobar", "ketan", "ketan", HttpStatus.SC_UNAUTHORIZED); try {/* w w w . ja v a 2s.c o m*/ mingleClient.validate(); fail("expected MingleAuthenticationException, should not have reached here"); } catch (MingleAuthenticationException e) { // pass } }
From source file:com.mosso.client.cloudfiles.FilesResponse.java
/** * Checks to see if the user managed to login with their credentials. * * @return true is login succeeded false otherwise *///from w w w. ja va 2 s . com public boolean loginSuccess() { if (getStatusCode() == HttpStatus.SC_UNAUTHORIZED) return false; if (getStatusCode() == HttpStatus.SC_NO_CONTENT) return true; return false; }
From source file:eu.alefzero.owncloud.authenticator.AuthenticationRunnable.java
@Override public void run() { Uri uri;/*from w w w.j a v a2s.c o m*/ uri = Uri.parse(mUrl.toString()); int login_result = WebdavClient.tryToLogin(uri, mUsername, mPassword); switch (login_result) { case HttpStatus.SC_OK: postResult(true, uri.toString()); break; case HttpStatus.SC_UNAUTHORIZED: postResult(false, "Invalid login or/and password"); break; case HttpStatus.SC_NOT_FOUND: postResult(false, "Wrong path given"); break; default: postResult(false, "Internal server error, code: " + login_result); } }
From source file:es.carebear.rightmanagement.client.user.AddAllowedUserId.java
public void AddUser(String authName, String target, String rightMask) throws BadRequestException, InternalServerErrorException, IOException, UnknownResponseException, UnauthorizedException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/change/allowed"); postMethod.addParameter("authName", authName); postMethod.addParameter("target", target); postMethod.addParameter("rightMask", rightMask); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_OK: break;/*www .j a va 2 s. co m*/ case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_INTERNAL_SERVER_ERROR: throw new InternalServerErrorException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); case HttpStatus.SC_FORBIDDEN: throw new ForbiddenException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:com.baifendian.swordfish.webserver.interceptor.LoginInterceptor.java
@Override public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception { // ? session/*from ww w . ja v a2 s . c o m*/ Session session = sessionService.getSessionFromRequest(httpServletRequest); // session ?, false if (session == null) { httpServletResponse.setStatus(HttpStatus.SC_UNAUTHORIZED); return false; } logger.info("session is: {}", session.getId()); // ?, session User user = userMapper.queryById(session.getUserId()); if (user == null) { httpServletResponse.setStatus(HttpStatus.SC_UNAUTHORIZED); return false; } httpServletRequest.setAttribute("session.user", user); return true; }
From source file:es.carebear.rightmanagement.client.user.GetUserAttributes.java
public String[] getAttributes(String authName, String target) throws BadRequestException, InternalServerErrorException, IOException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/" + target); postMethod.addParameter("authName", authName); int responseCode = httpClient.executeMethod(postMethod); System.err.println(responseCode); switch (responseCode) { case HttpStatus.SC_ACCEPTED: String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream()); AttributeContainer lc = XMLHelper.fromXML(response, AttributeContainer.class); return lc.toArray(); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); default://from ww w . j ava 2 s . c o m throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:es.carebear.rightmanagement.client.user.GetAllUsersWithAccess.java
public String[] getUsers(String authName) throws BadRequestException, InternalServerErrorException, IOException, UnauthorizedException, UnknownResponseException { PostMethod postMethod = new PostMethod(baseUri + "/client/users/all/withAccess"); postMethod.addParameter("authName", authName); int responseCode = httpClient.executeMethod(postMethod); switch (responseCode) { case HttpStatus.SC_ACCEPTED: String response = XMLHelper.fromStreamToXML(postMethod.getResponseBodyAsStream()); StringListContainer lc = XMLHelper.fromXML(response, StringListContainer.class); List<String> ls = new ArrayList<>(); lc.getContainer().stream().forEach(obj -> { Gson gson = new Gson(); ls.add(obj);/*from ww w . j a v a2 s.co m*/ }); return ls.toArray(new String[ls.size()]); case HttpStatus.SC_BAD_REQUEST: throw new BadRequestException(); case HttpStatus.SC_UNAUTHORIZED: throw new UnauthorizedException(); default: throw new UnknownResponseException((new Integer(responseCode)).toString()); } }
From source file:com.owncloud.android.authenticator.AuthenticationRunnable.java
@Override public void run() { Uri uri;// w w w .j a va2 s .c o m uri = Uri.parse(mUrl.toString()); WebdavClient wdc = OwnCloudClientUtils.createOwnCloudClient(uri, mUsername, mPassword, mContext); int login_result = wdc.tryToLogin(); switch (login_result) { case HttpStatus.SC_OK: postResult(true, uri.toString()); break; case HttpStatus.SC_UNAUTHORIZED: postResult(false, mContext.getString(R.string.auth_unauthorized)); break; case HttpStatus.SC_NOT_FOUND: postResult(false, mContext.getString(R.string.auth_not_found)); break; default: postResult(false, String.format(mContext.getString(R.string.auth_internal), login_result)); } }
From source file:com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult.java
public void unauthorized(Localizable message, HealthStateType healthStateType) { this.message = message; this.healthStateType = healthStateType; httpCode = HttpStatus.SC_UNAUTHORIZED; }
From source file:cn.edu.seu.herald.auth.AuthenticationServiceImpl.java
@Override public StudentUser authenticate(String username, String password) throws AuthenticationServiceException { PostMethod post = new PostMethod(baseUri); post.setQueryString(new NameValuePair[] { new NameValuePair(PARAM_USER, username), new NameValuePair(PARAM_PASS, password) }); try {//from ww w .ja v a 2 s . co m int statusCode = httpClient.executeMethod(post); if (statusCode == HttpStatus.SC_UNAUTHORIZED) { return null; } if (statusCode != HttpStatus.SC_OK) { throw new AuthenticationServiceException("Unexpected status: " + statusCode); } String csv = post.getResponseBodyAsString(); String values[] = csv.split(","); if (values == null || values.length != 2) { throw new AuthenticationServiceException( String.format("%s\n%s\n", "Unexpected server response:\n", csv)); } String name = values[0]; String cardNumber = values[1]; return new StudentUser(name, cardNumber); } catch (IOException ex) { throw new AuthenticationServiceException(ex); } finally { post.releaseConnection(); } }