List of usage examples for org.apache.http.auth Credentials getUserPrincipal
Principal getUserPrincipal();
From source file:org.apache.http.impl.auth.BasicScheme.java
/** * Produces basic authorization header for the given set of {@link Credentials}. * * @param credentials The set of credentials to be used for authentication * @param request The request being authenticated * @throws org.apache.http.auth.InvalidCredentialsException if authentication * credentials are not valid or not applicable for this authentication scheme * @throws AuthenticationException if authorization string cannot * be generated due to an authentication failure * * @return a basic authorization string// ww w. j av a2s. c o m */ @Override public Header authenticate(final Credentials credentials, final HttpRequest request, final HttpContext context) throws AuthenticationException { Args.notNull(credentials, "Credentials"); Args.notNull(request, "HTTP request"); final StringBuilder tmp = new StringBuilder(); tmp.append(credentials.getUserPrincipal().getName()); tmp.append(":"); tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword()); final byte[] base64password = base64codec .encode(EncodingUtils.getBytes(tmp.toString(), getCredentialsCharset(request))); final CharArrayBuffer buffer = new CharArrayBuffer(32); if (isProxy()) { buffer.append(AUTH.PROXY_AUTH_RESP); } else { buffer.append(AUTH.WWW_AUTH_RESP); } buffer.append(": Basic "); buffer.append(base64password, 0, base64password.length); return new BufferedHeader(buffer); }
From source file:org.apache.http.impl.auth.BasicScheme.java
/** * Returns a basic <tt>Authorization</tt> header value for the given * {@link Credentials} and charset./*from ww w .ja v a 2 s . co m*/ * * @param credentials The credentials to encode. * @param charset The charset to use for encoding the credentials * * @return a basic authorization header * * @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}. */ @Deprecated public static Header authenticate(final Credentials credentials, final String charset, final boolean proxy) { Args.notNull(credentials, "Credentials"); Args.notNull(charset, "charset"); final StringBuilder tmp = new StringBuilder(); tmp.append(credentials.getUserPrincipal().getName()); tmp.append(":"); tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword()); final byte[] base64password = Base64.encodeBase64(EncodingUtils.getBytes(tmp.toString(), charset), false); final CharArrayBuffer buffer = new CharArrayBuffer(32); if (proxy) { buffer.append(AUTH.PROXY_AUTH_RESP); } else { buffer.append(AUTH.WWW_AUTH_RESP); } buffer.append(": Basic "); buffer.append(base64password, 0, base64password.length); return new BufferedHeader(buffer); }
From source file:org.callimachusproject.behaviours.SqlDatasourceSupport.java
private void registerConnectionDriver(String name, DriverConnectionPoolManager manager) throws SQLException, OpenRDFException, IOException { Exception cause = null;//from w w w . j av a2 s . c o m String url = this.getCalliJdbcUrl(); List<String> classnames = new ArrayList<>(this.getCalliDriverClassName()); ClassLoader cl = createClassLoader(); for (String classname : classnames) { try { Object d = Class.forName(classname, true, cl).newInstance(); if (!(d instanceof Driver)) { logger.error("{} is not a java.sql.Driver class", classname); } Driver driver = (Driver) d; if (driver.getClass().getClassLoader() == cl) { deregisterDriverOnReset(name, driver); } if (driver.acceptsURL(url)) { Config config = new Config(); config.testOnBorrow = true; config.maxActive = intOrNeg(this.getCalliMaxActive()); config.maxIdle = intOrNeg(this.getCalliMaxIdle()); config.maxWait = intOrNeg(this.getCalliMaxWait()); Properties props = new Properties(); Credentials cred = getCredential(url); if (cred != null) { props.setProperty("user", cred.getUserPrincipal().getName()); props.setProperty("password", cred.getPassword()); } verifyDriver(url, driver, props); manager.registerDriver(name, driver, url, props, config, this.getCalliValidationQuery()); return; } } catch (ClassNotFoundException e) { cause = e; logger.error("{} is not found in {}", classname, this.getCalliDriverJar()); } catch (InstantiationException e) { cause = e; logger.error("Could not instaniate {}", classname); } catch (IllegalAccessException e) { cause = e; logger.error("Could not access {}", classname); } catch (Exception e) { cause = e; logger.error("Could not load driver {}", classname); } } reset(); if (cause instanceof SQLException) throw (SQLException) cause; if (cause != null) throw new SQLException("Could not load driver " + classnames, cause); throw new SQLException("Could not load driver " + classnames); }
From source file:test.com.xceptance.xlt.common.actions.LWSimpleURLTest.java
/********************************************************************************** * Check setting of credentials/*from ww w . jav a 2s . co m*/ * * @throws IOException *********************************************************************************/ @Test public void testCredentials_Set() throws IOException { final List<AbstractLightWeightPageAction> actions = mockIt(login, password, "URL", "{url}"); final Credentials creds = actions.get(0).getWebClient().getCredentialsProvider() .getCredentials(AuthScope.ANY); Assert.assertEquals("Login does not match.", login, creds.getUserPrincipal().getName()); Assert.assertEquals("Password does not match.", password, creds.getPassword()); }
From source file:test.com.xceptance.xlt.common.actions.SimpleURLTest.java
/********************************************************************************** * Check setting of credentials/*from ww w. ja va2 s .c o m*/ * * @throws IOException *********************************************************************************/ @Test public void testCredentials_Set() throws IOException { final List<AbstractHtmlPageAction> actions = mockIt(login, password, "URL", "{url}"); final Credentials creds = actions.get(0).getWebClient().getCredentialsProvider() .getCredentials(AuthScope.ANY); Assert.assertEquals("Login does not match.", login, creds.getUserPrincipal().getName()); Assert.assertEquals("Password does not match.", password, creds.getPassword()); }