List of usage examples for org.apache.commons.httpclient.auth AuthenticationException AuthenticationException
public AuthenticationException(String paramString)
From source file:com.microfocus.application.automation.tools.srf.utilities.HttpCodeErrorClassifier.java
public static void throwError(int statusCode, String responseMessage) throws IOException, AuthorizationException, SrfException { systemLogger.fine(String.format("Received http status code %d with response message %s", statusCode, responseMessage));// w w w. j ava 2 s. c o m switch (statusCode) { case 401: throw new AuthenticationException("Failed to login, possibly wrong credentials supplied"); case 403: throw new AuthorizationException("Operation is forbidden"); default: JSONObject srfError = JSONObject.fromObject(responseMessage); if (SrfException.isSrfException(srfError)) throw new SrfException(srfError.getString("message"), srfError.getString("code")); throw new SrfException(String.format("Request failed with http code %d and http response %s", statusCode, responseMessage)); } }
From source file:net.adamcin.httpsig.http.apache3.Http3SignatureAuthScheme.java
public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException { throw new AuthenticationException("Signature authentication requires access to all request headers"); }
From source file:com.mobilehelix.appserver.auth.JCIFS_NTLMScheme.java
public JCIFS_NTLMScheme() throws AuthenticationException { // Check if JCIFS is present. If not present, do not proceed. try {/*from w w w .ja va 2s. co m*/ Class.forName("jcifs.ntlmssp.NtlmMessage", false, this.getClass().getClassLoader()); } catch (ClassNotFoundException e) { throw new AuthenticationException("Unable to proceed as JCIFS library is not found."); } }
From source file:com.esri.gpt.control.search.ServletSavedSearch.java
/** * Execute./*from w w w . j a v a 2s . co m*/ * * @param request the request * @param response the response * @param context the context * @throws Exception the exception */ @Override protected void execute(HttpServletRequest request, HttpServletResponse response, RequestContext context) throws Exception { try { if (context.getUser().getName().equals("")) { throw new AuthenticationException("Login needed"); } if (request.getMethod().toLowerCase().equals("get")) { writeSavedSearches(request, response, context); } else if (request.getMethod().toLowerCase().equals("put") || request.getMethod().toLowerCase().equals("post")) { putSavedSearches(request, response, context); } else if (request.getMethod().toLowerCase().equals("delete")) { deleteSavedSearch(request, response, context); } } catch (AuthenticationException e) { response.sendError(404, "User principle not found. Try authenticating."); LOG.log(Level.INFO, "Tried to get saved search but principle not found for " + request.getRemoteAddr(), e); } catch (Throwable e) { response.sendError(500, e.getMessage()); LOG.log(Level.WARNING, "Error while interacting with saved searches", e); } }
From source file:com.jivesoftware.authHelper.customescheme.negotiate.CustomNegotiateScheme.java
/** * Method not supported by Negotiate scheme. * * @throws org.apache.commons.httpclient.auth.AuthenticationException if called. * * @deprecated Use {@link #authenticate(org.apache.commons.httpclient.Credentials, org.apache.commons.httpclient.HttpMethod)} *///from w w w .j a va2 s . c om @Deprecated public String authenticate(Credentials credentials, String method, String uri) throws AuthenticationException { throw new AuthenticationException("method not supported by Negotiate scheme"); }
From source file:com.jivesoftware.authHelper.customescheme.negotiate.CustomNegotiateScheme.java
/** * Produces Negotiate authorization string based on token created by * processChallenge./*from w w w .j a v a2 s.co m*/ * * @param credentials Never used be the Negotiate scheme but must be provided to * satisfy common-httpclient API. Credentials from JAAS will be used insted. * @param method The method being authenticated * * @throws org.apache.commons.httpclient.auth.AuthenticationException if authorization string cannot * be generated due to an authentication failure * * @return an Negotiate authorization string * * @since 3.0 */ public synchronized String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { LOG.info("enter CustomNegotiateScheme.authenticate(Credentials, HttpMethod)"); if (state == UNINITIATED) { throw new IllegalStateException("Negotiation authentication process has not been initiated"); } try { try { if (context == null) { LOG.info("host: " + method.getURI().getHost()); init(method.getURI().getHost(), (UsernamePasswordCredentials) credentials); } } catch (org.apache.commons.httpclient.URIException urie) { LOG.severe(urie.getMessage()); state = FAILED; throw new AuthenticationException(urie.getMessage()); } // HTTP 1.1 issue: // Mutual auth will never complete do to 200 insted of 401 in // return from server. "state" will never reach ESTABLISHED // but it works anyway // token = context.initSecContext(token, 0, token.length); LOG.info("got token, sending " + token.length + " to server"); } catch (GSSException gsse) { LOG.severe(gsse.getMessage()); state = FAILED; if (gsse.getMajor() == GSSException.DEFECTIVE_CREDENTIAL || gsse.getMajor() == GSSException.CREDENTIALS_EXPIRED) { throw new InvalidCredentialsException(gsse.getMessage(), gsse); } if (gsse.getMajor() == GSSException.NO_CRED) { throw new CredentialsNotAvailableException(gsse.getMessage(), gsse); } if (gsse.getMajor() == GSSException.DEFECTIVE_TOKEN || gsse.getMajor() == GSSException.DUPLICATE_TOKEN || gsse.getMajor() == GSSException.OLD_TOKEN) { throw new AuthChallengeException(gsse.getMessage(), gsse); } // other error throw new AuthenticationException(gsse.getMessage()); } return "Negotiate " + new String(new Base64(-1).encode(token)); }
From source file:com.hpe.application.automation.tools.srf.run.RunFromSrfBuilder.java
private JSONArray executeTestsSet() throws MalformedURLException, AuthenticationException, IOException, SrfException { StringBuffer response = new StringBuffer(); JSONArray jobs;//from w w w. j a v a 2 s . c o m _con = connect("/rest/jobmanager/v1/execution/jobs", "POST"); fillExecutionReqBody(); int responseCode = _con.getResponseCode(); BufferedReader br; if (responseCode == 401 && _secretApplied) { throw new AuthenticationException("Login required\n\r"); } if (responseCode == 200) { br = new BufferedReader(new InputStreamReader((_con.getInputStream()))); } else { br = new BufferedReader(new InputStreamReader((_con.getErrorStream()))); } String inputLine; while ((inputLine = br.readLine()) != null) { response.append(inputLine); } if (responseCode != 200) { JSONObject srfError = JSONObject.fromObject(response.toString()); if (srfError.containsKey("name") && srfError.getString("name").equalsIgnoreCase("srferror")) throw new SrfException(srfError.getString("message"), srfError.getString("code")); throw new SrfException(String.format( "Failed for SRF execution request, received response with status code: %d and body: %s", responseCode, response.toString())); } else { jobs = JSONObject.fromObject(response.toString()).getJSONArray("jobs"); if (jobs == null || jobs.size() == 0) throw new SrfException(String.format("No tests found for %s", this.srfTestId != null && !this.srfTestId.equals("") ? "test id: " + this.srfTestId : "test tags: " + this.srfTagNames)); } return getJobIds(jobs); }
From source file:org.apache.abdera.ext.gdata.GoogleLoginAuthScheme.java
public String authenticate(Credentials credentials, HttpMethod method) throws AuthenticationException { String auth = null;/*from w w w .j a v a 2s . com*/ if (credentials instanceof UsernamePasswordCredentials) { UsernamePasswordCredentials usercreds = (UsernamePasswordCredentials) credentials; String id = usercreds.getUserName(); String pwd = usercreds.getPassword(); auth = getAuth(id, pwd); } else if (credentials instanceof GoogleLoginAuthCredentials) { GoogleLoginAuthCredentials gcreds = (GoogleLoginAuthCredentials) credentials; service = gcreds.getService(); auth = gcreds.getAuth(); } else { throw new AuthenticationException("Cannot use credentials for GoogleLogin authentication"); } StringBuffer buf = new StringBuffer("GoogleLogin "); buf.append(auth); return buf.toString(); }
From source file:org.apache.wookie.proxy.ProxyClient.java
private String executeMethod(HttpMethod method, Configuration properties) throws Exception, AuthenticationException { // Execute the method. try {/*from w ww . j a v a 2s . c o m*/ HttpClient client = new HttpClient(); // set the clients proxy values if needed ConnectionsPrefsManager.setProxySettings(client, properties); if (fUseProxyAuthentication) { if (fBase64Auth != null) { method.setRequestHeader("Authorization", fBase64Auth); } else { List<String> authPrefs = new ArrayList<String>(2); authPrefs.add(AuthPolicy.DIGEST); authPrefs.add(AuthPolicy.BASIC); client.getParams().setParameter(AuthPolicy.AUTH_SCHEME_PRIORITY, authPrefs); // send the basic authentication response even before the server gives an unauthorized response client.getParams().setAuthenticationPreemptive(true); // Pass our credentials to HttpClient client.getState().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM), new UsernamePasswordCredentials(fProxyUsername, fProxyPassword)); } } // Add user language to http request in order to notify server of user's language Locale locale = Locale.getDefault(); method.setRequestHeader("Accept-Language", locale.getLanguage()); //$NON-NLS-1$ method.removeRequestHeader("Content-Type"); //method.setRequestHeader("Content-Type","application/json"); //method.setRequestHeader("Referer", ""); //method.removeRequestHeader("Referer"); method.setRequestHeader("Accept", "*/*"); int statusCode = client.executeMethod(method); //System.out.println("response="+method.getResponseBodyAsString()); //System.out.println("method="+method.toString()); //System.out.println("response="+method.getResponseBodyAsStream()); if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) { Header hType = method.getResponseHeader("Content-Type"); if (hType != null) { fContentType = hType.getValue(); } // for now we are only expecting Strings //return method.getResponseBodyAsString(); return readFully(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8")); } else if (statusCode == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED || statusCode == HttpStatus.SC_UNAUTHORIZED) { throw new AuthenticationException("Authentication failed:" + method.getStatusLine() + ' ' + method.getURI() + ' ' + method.getStatusText()); } else { throw new Exception("Method failed: " + method.getStatusLine() + ' ' + method.getURI() + ' ' //$NON-NLS-1$ + method.getStatusText()); } } catch (IOException e) { throw e; } finally { // Release the connection. method.releaseConnection(); } }
From source file:org.kuali.kra.institutionalproposal.web.struts.action.InstitutionalProposalHomeAction.java
@Override public ActionForward downloadBOAttachment(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { int attachmentIndex = selectedAttachmentIndex(request); InstitutionalProposalForm ipForm = (InstitutionalProposalForm) form; InstitutionalProposalDocument institutionalProposalDocument = ipForm.getInstitutionalProposalDocument(); if (!WebUtils.canViewNoteAttachment(institutionalProposalDocument, null)) { throw new AuthenticationException("Unable to view attachment."); }//from w w w . j a v a 2 s . c o m List<InstitutionalProposalNotepad> notepads = institutionalProposalDocument.getInstitutionalProposal() .getInstitutionalProposalNotepads(); PersistableBusinessObject noteParent = notepads.get(attachmentIndex); if (attachmentIndex >= 0) { // each IPNotepad has only one KNS note attached to it, and a KNS attachment is attached to that note Note note = noteParent.getBoNote(0); Attachment attachment = note.getAttachment(); //make sure attachment is setup with backwards reference to note (rather then doing this we could also just call the attachment service (with a new method that took in the note) attachment.setNote(note); // since we're downloading a file, all of the editable properties from the previous request will continue to be editable. KualiDocumentFormBase documentForm = (KualiDocumentFormBase) form; documentForm.copyPopulateEditablePropertiesToActionEditableProperties(); WebUtils.saveMimeInputStreamAsFile(response, attachment.getAttachmentMimeTypeCode(), attachment.getAttachmentContents(), attachment.getAttachmentFileName(), attachment.getAttachmentFileSize().intValue()); return null; } return mapping.findForward(RiceConstants.MAPPING_BASIC); }