List of usage examples for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN
int SC_FORBIDDEN
To view the source code for org.apache.commons.httpclient HttpStatus SC_FORBIDDEN.
Click Source Link
From source file:org.picketlink.test.authentication.web.BasicAuthenticationSchemeFromAjaxClientTestCase.java
@Test @OperateOnDeployment("default") public void testUnsuccessfulAuthentication() throws Exception { WebClient client = new WebClient(); WebRequestSettings request = new WebRequestSettings(getProtectedResourceURL()); prepareAjaxRequest(request);//from ww w. j ava 2 s . co m WebResponse response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); prepareAuthenticationRequest(request, DEFAULT_USERNAME, "bad_passwd"); response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); }
From source file:org.picketlink.test.authentication.web.ClientCertAuthenticationSchemeTestCase.java
@Test public void testSuccessfulAuthentication() throws Exception { WebClient client = new WebClient(); WebRequestSettings request = new WebRequestSettings(getProtectedResourceURL()); WebResponse response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); prepareAuthenticationRequest(request); response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); assertEquals("Protected Page", response.getContentAsString()); request.setUrl(getContextPath());// ww w. ja v a 2 s . com response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); assertEquals("Index Page", response.getContentAsString()); request.setUrl(getProtectedResourceURL()); response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); assertEquals("Protected Page", response.getContentAsString()); }
From source file:org.picketlink.test.authentication.web.DigestAuthenticationSchemeFromAjaxClientTestCase.java
@Test public void testSuccessfulAuthentication() throws Exception { WebClient client = new WebClient(); WebRequestSettings request = new WebRequestSettings(getProtectedResourceURL()); prepareAjaxRequest(request);/*w w w .ja va 2 s. c om*/ WebResponse response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); String authenticateHeader = response.getResponseHeaderValue("WWW-Authenticate"); assertNotNull(authenticateHeader); assertTrue(authenticateHeader.contains("Digest realm=\"Test Realm\"")); prepareAuthenticationRequest(request, response, "john", "passwd"); response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); assertEquals("Protected Page", response.getContentAsString()); request.setUrl(getContextPath()); response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); assertEquals("Index Page", response.getContentAsString()); request.setUrl(getProtectedResourceURL()); response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_OK, response.getStatusCode()); assertEquals("Protected Page", response.getContentAsString()); }
From source file:org.picketlink.test.authentication.web.DigestAuthenticationSchemeFromAjaxClientTestCase.java
@Test public void testUnsuccessfulAuthentication() throws Exception { WebClient client = new WebClient(); WebRequestSettings request = new WebRequestSettings(getProtectedResourceURL()); prepareAjaxRequest(request);// w w w. j av a2 s. c om WebResponse response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); prepareAuthenticationRequest(request, response, "john", "bad_passwd"); response = client.loadWebResponse(request); assertEquals(HttpStatus.SC_FORBIDDEN, response.getStatusCode()); }
From source file:org.projectforge.web.address.PhoneLookUpServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final String number = req.getParameter("nr"); if (StringUtils.isBlank(number) == true || StringUtils.containsOnly(number, "+1234567890 -/") == false) { log.warn(//from w w w . j ava2s .c o m "Bad request, request parameter nr not given or contains invalid characters (only +0123456789 -/ are allowed): " + number); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } final String key = req.getParameter("key"); final String expectedKey = ConfigXml.getInstance().getPhoneLookupKey(); if (StringUtils.isBlank(expectedKey) == true) { log.warn( "Servlet call for receiving phonelookups ignored because phoneLookupKey is not given in config.xml file."); resp.sendError(HttpStatus.SC_BAD_REQUEST); return; } if (expectedKey.equals(key) == false) { log.warn("Servlet call for phonelookups ignored because phoneLookupKey does not match given key: " + key); resp.sendError(HttpStatus.SC_FORBIDDEN); return; } final String searchNumber = NumberHelper.extractPhonenumber(number); final AddressDao addressDao = (AddressDao) Registry.instance().getDao(AddressDao.class); final BaseSearchFilter filter = new BaseSearchFilter(); filter.setSearchString("*" + searchNumber); final QueryFilter queryFilter = new QueryFilter(filter); final StringBuffer buf = new StringBuffer(); // Use internal get list method for avoiding access checking (no user is logged-in): final List<AddressDO> list = addressDao.internalGetList(queryFilter); if (list != null && list.size() >= 1) { AddressDO result = list.get(0); if (list.size() > 1) { // More than one result, therefore find the newest one: buf.append("+"); // Mark that more than one entry does exist. for (final AddressDO matchingUser : list) { if (matchingUser.getLastUpdate().after(result.getLastUpdate()) == true) { result = matchingUser; } } } resp.setContentType("text/plain"); final String fullname = result.getFullName(); final String organization = result.getOrganization(); StringHelper.listToString(buf, "; ", fullname, organization); resp.getOutputStream().print(buf.toString()); } else { /* mit Thomas abgesprochen. */ resp.getOutputStream().print(0); } }
From source file:org.rhq.enterprise.server.legacy.rss.DownloadPatchTest.java
public void testAccessDownloadsNoUser() throws Exception { int statusCode = accessDownload("", "", ""); assertEquals(HttpStatus.SC_FORBIDDEN, statusCode); }
From source file:org.rhq.enterprise.server.legacy.rss.DownloadPatchTest.java
public void testAccessDownloadsNoPassword() throws Exception { int statusCode = accessDownload("fmerenda@jboss.org", "", ""); assertEquals(HttpStatus.SC_FORBIDDEN, statusCode); }
From source file:org.rhq.enterprise.server.legacy.rss.DownloadPatchTest.java
public void testAccessDownloadsInvalidPassword() throws Exception { int statusCode = accessDownload("fmerenda@jboss.org", "xxxxx", ""); assertEquals(HttpStatus.SC_FORBIDDEN, statusCode); }
From source file:org.rhq.enterprise.server.plugins.url.HttpProvider.java
/** * Given any URL, will return a stream to that URL using the HTTP client and GET method * for the authentication as defined in this content source's configuration. * /*from w ww . j a v a 2 s . c o m*/ * @param url the URL whose stream of content is returned * * @return stream containing the content for the given URL * * @throws Exception if cannot get the streamed content */ protected InputStream getInputStreamForUrl(URL url) throws Exception { String fullLocation = url.toString(); HttpClient client = new HttpClient(); HttpMethodBase method = new GetMethod(fullLocation); prepareHttpClient(client, method); int status = client.executeMethod(method); switch (status) { case HttpStatus.SC_OK: { break; // good to go } case HttpStatus.SC_NOT_FOUND: { throw new Exception("Could not find the content at URL [" + fullLocation + "]. Make sure the content source defines a valid URL."); } case HttpStatus.SC_UNAUTHORIZED: case HttpStatus.SC_FORBIDDEN: { throw new Exception("Invalid login credentials specified for user [" + username + "]. Make sure " + "this user is valid and the password specified for this content source is correct."); } default: { throw new Exception("Failed to retrieve content. status code=" + status); } } InputStream stream = method.getResponseBodyAsStream(); return stream; }
From source file:org.sonatype.nexus.proxy.storage.remote.commonshttpclient.CommonsHttpClientRemoteStorage.java
/** * Execute method. In case of any exception thrown by HttpClient, it will release the connection. In other cases it * is the duty of caller to do it, or process the input stream. * /*from w w w . jav a2s . co m*/ * @param method the method * @return the int */ protected int doExecuteMethod(ProxyRepository repository, ResourceStoreRequest request, HttpMethod method, URL remoteUrl) throws RemoteStorageException { URI methodURI = null; try { methodURI = method.getURI(); } catch (URIException e) { getLogger().debug("Could not format debug log message", e); } if (getLogger().isDebugEnabled()) { getLogger().debug("Invoking HTTP " + method.getName() + " method against remote location " + methodURI); } RemoteStorageContext ctx = getRemoteStorageContext(repository); HttpClient httpClient = (HttpClient) ctx.getContextObject(CTX_KEY_CLIENT); HostConfiguration httpConfiguration = (HostConfiguration) ctx.getContextObject(CTX_KEY_HTTP_CONFIGURATION); method.setRequestHeader(new Header("user-agent", formatUserAgentString(ctx, repository))); method.setRequestHeader(new Header("accept", "*/*")); method.setRequestHeader(new Header("accept-language", "en-us")); method.setRequestHeader(new Header("accept-encoding", "gzip, identity")); method.setRequestHeader(new Header("cache-control", "no-cache")); // HTTP keep alive should not be used, except when NTLM is used Boolean isNtlmUsed = (Boolean) ctx.getContextObject(HttpClientProxyUtil.NTLM_IS_IN_USE_KEY); if (isNtlmUsed == null || !isNtlmUsed) { method.setRequestHeader(new Header("Connection", "close")); method.setRequestHeader(new Header("Proxy-Connection", "close")); } method.setFollowRedirects(true); if (StringUtils.isNotBlank(ctx.getRemoteConnectionSettings().getQueryString())) { method.setQueryString(ctx.getRemoteConnectionSettings().getQueryString()); } int resultCode; try { resultCode = httpClient.executeMethod(httpConfiguration, method); final Header httpServerHeader = method.getResponseHeader("server"); checkForRemotePeerAmazonS3Storage(repository, httpServerHeader == null ? null : httpServerHeader.getValue()); Header proxyReturnedErrorHeader = method.getResponseHeader(NEXUS_MISSING_ARTIFACT_HEADER); boolean proxyReturnedError = proxyReturnedErrorHeader != null && Boolean.valueOf(proxyReturnedErrorHeader.getValue()); if (resultCode == HttpStatus.SC_FORBIDDEN) { throw new RemoteAccessDeniedException(repository, remoteUrl, HttpStatus.getStatusText(HttpStatus.SC_FORBIDDEN)); } else if (resultCode == HttpStatus.SC_UNAUTHORIZED) { throw new RemoteAuthenticationNeededException(repository, HttpStatus.getStatusText(HttpStatus.SC_UNAUTHORIZED)); } else if (resultCode == HttpStatus.SC_OK && proxyReturnedError) { throw new RemoteStorageException( "Invalid artifact found, most likely a proxy redirected to an HTML error page."); } } catch (RemoteStorageException e) { method.releaseConnection(); throw e; } catch (HttpException ex) { method.releaseConnection(); throw new RemoteStorageException("Protocol error while executing " + method.getName() + " method. [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + methodURI + "\"]", ex); } catch (IOException ex) { method.releaseConnection(); throw new RemoteStorageException("Transport error while executing " + method.getName() + " method [repositoryId=\"" + repository.getId() + "\", requestPath=\"" + request.getRequestPath() + "\", remoteUrl=\"" + methodURI + "\"]", ex); } return resultCode; }