List of usage examples for org.apache.commons.httpclient UsernamePasswordCredentials getPassword
public String getPassword()
From source file:com.gargoylesoftware.htmlunit.DefaultCredentialsProviderTest.java
/** * Test that successive calls to {@link DefaultCredentialsProvider#addCredentials(String, String)} * overwrite values previously set.//from w w w . ja v a 2s .c om * @throws Exception if the test fails */ @Test public void overwrite() throws Exception { final DefaultCredentialsProvider provider = new DefaultCredentialsProvider(); provider.addCredentials("username", "password"); UsernamePasswordCredentials credentials = (UsernamePasswordCredentials) provider .getCredentials(new BasicScheme(), "host", 80, false); assertEquals("username", credentials.getUserName()); assertEquals("password", credentials.getPassword()); provider.addCredentials("username", "new password"); credentials = (UsernamePasswordCredentials) provider.getCredentials(new BasicScheme(), "host", 80, false); assertEquals("username", credentials.getUserName()); assertEquals("new password", credentials.getPassword()); provider.addCredentials("new username", "other password"); credentials = (UsernamePasswordCredentials) provider.getCredentials(new BasicScheme(), "host", 80, false); assertEquals("new username", credentials.getUserName()); assertEquals("other password", credentials.getPassword()); }
From source file:com.idega.slide.authentication.AuthenticationBusinessBean.java
public boolean isRootUser(HttpServletRequest request) { // HttpServletRequest request = iwc.getRequest(); LoginBusinessBean loginBusiness = getLoginBusiness(); String[] usernameAndPassword = loginBusiness.getLoginNameAndPasswordFromBasicAuthenticationRequest(request); UsernamePasswordCredentials tmpCredential = getRootUserCredentials(); return tmpCredential.getUserName().equals(usernameAndPassword[0]) && tmpCredential.getPassword().equals(usernameAndPassword[1]); }
From source file:net.praqma.jenkins.rqm.request.RQMHttpClient.java
public int logout() { log.finest("Logout"); try {//w w w .j a v a2s . co m log.finest("URI:" + url.toURI().toString()); } catch (URISyntaxException ex) { log.finest("Logout URISyntaxException " + ex.getMessage()); } String logoutUrl = this.url.toString() + contextRoot + JAZZ_LOGOUT_URL; log.finest("Attempting to log out with this url: " + logoutUrl); HttpMethodBase authenticationMethod = new PostMethod(this.url.toString() + contextRoot + JAZZ_LOGOUT_URL); authenticationMethod.setFollowRedirects(false); UsernamePasswordCredentials credentials = (UsernamePasswordCredentials) super.getState() .getCredentials(new AuthScope(host, port)); if (null != credentials && !(credentials.getUserName().isEmpty() && credentials.getPassword().isEmpty())) { log.finest(String.format("Adding authorizationheadder for logout for user: %s", credentials.getUserName())); authenticationMethod.addRequestHeader("Authorization:", "Base " + credentials.getUserName() + ":" + credentials.getPassword()); } String body = ""; String status = ""; int responseCode = 0; ; try { responseCode = executeMethod(authenticationMethod); body = authenticationMethod.getResponseBodyAsString(); status = authenticationMethod.getStatusText(); log.finest(String.format("Response code %s, Status text %s", responseCode, status)); } catch (Exception e) { log.log(Level.SEVERE, "Failed to log out!", e); log.log(Level.SEVERE, body); } return responseCode; }
From source file:it.eng.spagobi.commons.filters.ProfileFilter.java
private void authenticate(UsernamePasswordCredentials credentials) throws Throwable { logger.debug("IN: userId = " + credentials.getUserName()); try {//from w ww. ja v a 2 s.com ISecurityServiceSupplier supplier = SecurityServiceSupplierFactory.createISecurityServiceSupplier(); SpagoBIUserProfile profile = supplier.checkAuthentication(credentials.getUserName(), credentials.getPassword()); if (profile == null) { logger.error("Authentication failed for user " + credentials.getUserName()); throw new SecurityException("Authentication failed"); } } catch (Throwable t) { logger.error("Error while authenticating userId = " + credentials.getUserName(), t); throw t; } finally { logger.debug("OUT"); } }
From source file:com.jivesoftware.authHelper.customescheme.negotiate.CustomNegotiateScheme.java
/** * Init GSSContext for negotiation.//from w ww. j ava 2 s. c o m * * @param server servername only (e.g: radar.it.su.se) */ protected void init(String server, UsernamePasswordCredentials credentials) throws GSSException { LOG.info("init " + server); // Create a callback handler Configuration.setConfiguration(null); CallbackHandler callbackHandler = new CustomNegotiateCallbackHandler(credentials.getUserName(), credentials.getPassword()); PrivilegedExceptionAction action = new MyAction(server); LoginContext con = null; try { CustomConfiguration cc = getCustomConfiguration(credentials); // Create a LoginContext with a callback handler con = new LoginContext("com.sun.security.jgss.login", null, callbackHandler, cc); Configuration.setConfiguration(cc); // Perform authentication con.login(); } catch (LoginException e) { System.err.println("Login failed"); e.printStackTrace(); // System.exit(-1); throw new RuntimeException(e); } catch (Exception e) { System.err.println("Login failed"); e.printStackTrace(); // System.exit(-1); throw new RuntimeException(e); } // Perform action as authenticated user Subject subject = con.getSubject(); //LOG.trace("Subject is :"+ subject.toString()); LOG.info("Authenticated principal:**** " + subject.getPrincipals()); try { Subject.doAs(subject, action); } catch (PrivilegedActionException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.google.gsa.valve.modules.krb.KerberosAuthenticationProcess.java
/** * It does the Kerberos authentication when it has to be done through * username and password. It looks in the default Kerberos domain defined * in the Kerberos config file (krb5.ini or krb5.conf) if there is a valid * user with those credentials. If so, it gets his/her Kerberos ticket. * // www. ja v a 2s .c om * @param userCred username and password credentials * * @return the method result in HTTP error format */ public int authUsernamePassword(Credential userCred) { int result = HttpServletResponse.SC_UNAUTHORIZED; Krb5LoginModule login = null; userSubject = new Subject(); logger.debug("authUsernamePassword: using username and password"); try { //Create config objects and pass the credentials Map state = new HashMap(); UsernamePasswordCredentials usrpwdCred = new UsernamePasswordCredentials(userCred.getUsername(), userCred.getPassword()); state.put("javax.security.auth.login.name", usrpwdCred.getUserName()); state.put("javax.security.auth.login.password", usrpwdCred.getPassword().toCharArray()); state.put("java.security.krb5.conf", krbini); if (logger.isDebugEnabled()) { logger.debug("Username: " + usrpwdCred.getUserName()); } Map option = new HashMap(); String isDebug = "false"; if (logger.isDebugEnabled()) { isDebug = "true"; } option.put("debug", isDebug); option.put("tryFirstPass", "true"); option.put("useTicketCache", "false"); option.put("doNotPrompt", "false"); option.put("storePass", "false"); option.put("forwardable", "true"); login = new Krb5LoginModule(); login.initialize(userSubject, new NegotiateCallbackHandler(), state, option); if (login.login()) { login.commit(); logger.debug("Login commit"); if (id == null) { username = usrpwdCred.getUserName(); id = username; } logger.debug("username is ... " + id); result = HttpServletResponse.SC_OK; } } catch (LoginException e) { logger.error("LoginException while creating id: " + e.getMessage(), e); result = HttpServletResponse.SC_UNAUTHORIZED; } catch (Exception e) { e.printStackTrace(); logger.error("Exception while creating id: " + e.getMessage(), e); result = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; } return result; }
From source file:com.idega.slide.business.IWSlideServiceBean.java
/** * Gets the root url for the webdav server with authentication * * @return//from w w w .jav a 2 s . co m */ private HttpURL getWebdavServerURL(UsernamePasswordCredentials credential, String path, String servletPath, boolean addSessionId) { try { String server = getIWApplicationContext().getDomain().getURL(); if (server == null) { return null; } int port = 80; boolean https = false; if (server.endsWith(CoreConstants.SLASH)) { server = server.substring(0, server.lastIndexOf(CoreConstants.SLASH)); } if (server.startsWith("http://")) { server = server.substring(7, server.length()); } if (server.startsWith("https://")) { if (getIWMainApplication().getSettings().getBoolean("slide.allow.local.https")) { // https protocol when to slide is only enabled when this property is set https = true; } server = server.substring(8, server.length()); } if (server.indexOf(CoreConstants.COLON) != -1) { String sPort = server.substring(server.indexOf(CoreConstants.COLON) + 1, server.length()); port = Integer.parseInt(sPort); server = server.substring(0, server.indexOf(CoreConstants.COLON)); } String rootPath = servletPath; String realPath = rootPath; if (path != null) { realPath = rootPath + path; } HttpURL hrl = https ? new HttpsURL(server, port, realPath) : new HttpURL(server, port, realPath); if (credential != null) { hrl.setUserinfo(credential.getUserName(), credential.getPassword()); } return hrl; } catch (URIException e) { throw new IBORuntimeException(e); } }
From source file:org.alfresco.util.HttpClientHelperTest.java
public void testHTTPProxySettings() { String host = "testHost"; Integer port = 8080;//w ww .j a v a 2s .c om setHTTPSystemProperties(host, port, "user1", "password", null); ProxyHost proxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT); UsernamePasswordCredentials proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper .createProxyCredentials("http.proxyUser", "http.proxyPassword"); assertEquals(HTTP, proxyHost.getProtocol().getScheme()); assertEquals(host, proxyHost.getHostName()); assertEquals(port, Integer.valueOf(proxyHost.getPort())); assertEquals("user1", proxyCredentials.getUserName()); assertEquals("password", proxyCredentials.getPassword()); // Test default port and no credentials setHTTPSystemProperties(host, null, null, null, null); proxyHost = HttpClientHelper.createProxyHost("http.proxyHost", "http.proxyPort", DEFAULT_HTTP_PORT); proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("http.proxyUser", "http.proxyPassword"); assertEquals(HTTP, proxyHost.getProtocol().getScheme()); assertEquals(host, proxyHost.getHostName()); assertEquals(DEFAULT_HTTP_PORT, proxyHost.getPort()); assertNull(proxyCredentials); }
From source file:org.alfresco.util.HttpClientHelperTest.java
public void testHTTPSProxySettings() { String host = "testHost"; Integer port = 8444;//from w w w. ja v a 2 s.c o m setHTTPSSystemProperties(host, port, "user1", "password", null); ProxyHost proxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT); UsernamePasswordCredentials proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper .createProxyCredentials("https.proxyUser", "https.proxyPassword"); // Proxy hosts always use plain HTTP connection when communicating with clients (by commons.httpclient doc) assertEquals(HTTP, proxyHost.getProtocol().getScheme()); assertEquals(host, proxyHost.getHostName()); assertEquals(port, Integer.valueOf(proxyHost.getPort())); assertEquals("user1", proxyCredentials.getUserName()); assertEquals("password", proxyCredentials.getPassword()); // Test default port and no credentials setHTTPSSystemProperties(host, null, null, null, null); proxyHost = HttpClientHelper.createProxyHost("https.proxyHost", "https.proxyPort", DEFAULT_HTTPS_PORT); proxyCredentials = (UsernamePasswordCredentials) HttpClientHelper.createProxyCredentials("https.proxyUser", "https.proxyPassword"); assertEquals(host, proxyHost.getHostName()); assertEquals(DEFAULT_HTTPS_PORT, proxyHost.getPort()); assertNull(proxyCredentials); }
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 va 2 s. c o m 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(); }