Refine search
tmp.append(credentials.getUserPrincipal().getName()); tmp.append(":"); tmp.append((credentials.getPassword() == null) ? "null" : credentials.getPassword()); EncodingUtils.getBytes(tmp.toString(), charset)); 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);
public void testCredentialsWithBasicAuthentication() { // Setup final HttpServletRequest request = context.mock(HttpServletRequest.class); AuthentificationHelper helper = new AuthentificationHelper(); String login = "mickael"; String password = ":&=/?é$£"; String base64Hash = Base64.encodeString(login + ":" + password); final String authHeader = "Basic " + base64Hash; // Expectations context.checking(new Expectations() { { oneOf (request).getHeader("Authorization"); will(returnValue(authHeader)); } }); // Execute Credentials credentials = helper.credentialsWithBasicAuthentication(request); // Verify assertNotNull(credentials); assertEquals(login, credentials.getLogin()); assertEquals(password, credentials.getPassword()); context.assertIsSatisfied(); }
@POST @Produces("application/json") @Consumes("application/json") public Response authenticateUser(Credentials credentials) { String username = credentials.getUsername(); String password = credentials.getPassword(); // Authenticate the user, issue a token and return a response }
String uname = credentials.getUserPrincipal().getName(); String pwd = credentials.getPassword(); String tmp2=encode(md5Helper.digest(EncodingUtils.getBytes(a1, charset))); StringBuilder tmp3 = new StringBuilder(tmp2.length() + nonce.length() + cnonce.length() + 2); tmp3.append(tmp2); throw new AuthenticationException("Unhandled algorithm " + algorithm + " requested"); String md5a1 = encode(md5Helper.digest(EncodingUtils.getBytes(a1, charset))); a2 = method + ':' + uri; String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2)));
@Test public void testAddCredentials() throws IOException, ClassNotFoundException { String testUser = "test_username"; slaveServer.setUsername( testUser ); String testPassword = "test_password"; slaveServer.setPassword( testPassword ); String host = "somehost"; slaveServer.setHostname( host ); int port = 1000; slaveServer.setPort( "" + port ); HttpClientContext auth = slaveServer.getAuthContext(); Credentials cred = auth.getCredentialsProvider().getCredentials( new AuthScope( host, port ) ); assertEquals( testUser, cred.getUserPrincipal().getName() ); assertEquals( testPassword, cred.getPassword() ); String user2 = "user2"; slaveServer.setUsername( user2 ); slaveServer.setPassword( "pass2" ); auth = slaveServer.getAuthContext(); cred = auth.getCredentialsProvider().getCredentials( new AuthScope( host, port ) ); assertEquals( user2, cred.getUserPrincipal().getName() ); }
@Override public byte[] generateToken(byte[] input, String authServer, Credentials credentials) { Set<Principal> principals = new HashSet<>(); principals.add(credentials.getUserPrincipal()); Subject subject = new Subject(false, principals, new HashSet<>(), new HashSet<>()); try { LoginContext loginContext = new LoginContext("", subject, null, new KerberosConfiguration(credentials.getUserPrincipal().getName(), ((KerberosKeytabCredentials) credentials).getKeytab())); loginContext.login(); Subject loggedInSubject = loginContext.getSubject(); return Subject.doAs(loggedInSubject, new PrivilegedExceptionAction<byte[]>() { public byte[] run() throws UnknownHostException, ClassNotFoundException, GSSException, IllegalAccessException, NoSuchFieldException { GSSManager gssManager = GSSManager.getInstance(); String servicePrincipal = KerberosUtil.getServicePrincipal("HTTP", authServer); Oid serviceOid = KerberosUtil.getOidInstance("NT_GSS_KRB5_PRINCIPAL"); GSSName serviceName = gssManager.createName(servicePrincipal, serviceOid); Oid mechOid = KerberosUtil.getOidInstance("GSS_KRB5_MECH_OID"); GSSContext gssContext = gssManager.createContext(serviceName, mechOid, null, 0); gssContext.requestCredDeleg(true); gssContext.requestMutualAuth(true); return gssContext.initSecContext(input, 0, input.length); } }); } catch (PrivilegedActionException | LoginException e) { throw new RuntimeException(e); } }
private static Principal getAuthPrincipal(final AuthState authState) { AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }
private void checkAuthFailure(final HttpResponse response) { if (response != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED) { final Credentials credentials = httpContext.getCredentialsProvider().getCredentials(AuthScope.ANY); LOG.error("Cloudian admin API authentication failed, please check Cloudian configuration. Admin auth principal=" + credentials.getUserPrincipal() + ", password=" + credentials.getPassword() + ", API url=" + adminApiUrl); throw new ServerApiException(ApiErrorCode.UNAUTHORIZED, "Cloudian backend API call unauthorized, please ask your administrator to fix integration issues."); } }
private void createAndVerifyNTCredentials(final String domain, final String name, final String domainName, final String pass) { final AuthenticationInfo info = new AuthenticationInfo(domainName, pass, "server", "display"); final Credentials credentials = AuthHelper.getCredentials(ServerContext.Type.TFS, info); Assert.assertTrue(credentials instanceof NTCredentials); Assert.assertEquals(name, ((NTCredentials) credentials).getUserName()); Assert.assertEquals(domain, ((NTCredentials) credentials).getDomain().toLowerCase()); if(SystemHelper.getComputerName() != null) { //coming back null when running from command line on Mac, works inside IDE Assert.assertEquals(SystemHelper.getComputerName().toLowerCase(), ((NTCredentials) credentials).getWorkstation().toLowerCase()); } Assert.assertEquals(pass, credentials.getPassword()); }
@Override public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException { for( Callback callback : callbacks ) { if( callback instanceof NameCallback ) { String username = credentials.getUserPrincipal().getName(); ((NameCallback)callback).setName( username ); } else if ( callback instanceof PasswordCallback ) { String password = credentials.getPassword(); ((PasswordCallback)callback).setPassword( password.toCharArray() ); } } }
@Override public HttpResponse answer( InvocationOnMock invocation ) throws Throwable { HttpClientContext context = invocation.getArgumentAt( 1, HttpClientContext.class ); Credentials cred = context.getCredentialsProvider().getCredentials( new AuthScope( "hname", 1111 ) ); assertEquals( "uname", cred.getUserPrincipal().getName() ); return mockResponse( 200, responseContent ); } } );
String uname = credentials.getUserPrincipal().getName(); String pwd = credentials.getPassword(); String tmp2=encode(md5Helper.digest(EncodingUtils.getBytes(a1, charset))); StringBuilder tmp3 = new StringBuilder(tmp2.length() + nonce.length() + cnonce.length() + 2); tmp3.append(tmp2); throw new AuthenticationException("Unhandled algorithm " + algorithm + " requested"); String md5a1 = encode(md5Helper.digest(EncodingUtils.getBytes(a1, charset))); a2 = method + ':' + uri; String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2)));
private static Principal getAuthPrincipal(final AuthState authState) { final AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { final Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }
String username = credentials.getUsername(); String password = credentials.getPassword(); authenticate(username, password);
final String digest) throws AuthenticationException { CharArrayBuffer buffer = new CharArrayBuffer(128); if (isProxy()) { buffer.append(AUTH.PROXY_AUTH_RESP); } else { buffer.append(AUTH.WWW_AUTH_RESP); buffer.append(": Digest "); String algorithm = getParameter("algorithm"); String uname = credentials.getUserPrincipal().getName(); .formatNameValuePair(buffer, param, !noQuotes); return new BufferedHeader(buffer);
@Override public void handle( Callback[] callbacks ) throws IOException, UnsupportedCallbackException { for( Callback callback : callbacks ) { if( callback instanceof NameCallback ) { String username = credentials.getUserPrincipal().getName(); ((NameCallback)callback).setName( username ); //System.out.println( "Provided username: " + username ); } else if ( callback instanceof PasswordCallback ) { String password = credentials.getPassword(); ((PasswordCallback)callback).setPassword( password.toCharArray() ); //System.out.println( "Provided password: " + password ); } } }
/** * Creates a new cache for the specified credential. * * @param credentials credentials to associate cache with */ HttpSignatureCache(final Credentials credentials) { if (credentials == null) { throw new IllegalArgumentException("Credentials must be present"); } if (credentials.getUserPrincipal() == null) { throw new IllegalArgumentException("User principal must be present"); } if (credentials.getUserPrincipal().getName() == null) { throw new IllegalArgumentException("User principal name must be present"); } this.credentials = credentials; }
String uname = credentials.getUserPrincipal().getName(); String pwd = credentials.getPassword(); String tmp2=encode(md5Helper.digest(EncodingUtils.getBytes(a1, charset))); StringBuilder tmp3 = new StringBuilder(tmp2.length() + nonce.length() + cnonce.length() + 2); tmp3.append(tmp2); throw new AuthenticationException("Unhandled algorithm " + algorithm + " requested"); String md5a1 = encode(md5Helper.digest(EncodingUtils.getBytes(a1, charset))); a2 = method + ':' + uri; String md5a2 = encode(md5Helper.digest(EncodingUtils.getAsciiBytes(a2)));
private static Principal getAuthPrincipal(final AuthState authState) { final AuthScheme scheme = authState.getAuthScheme(); if (scheme != null && scheme.isComplete() && scheme.isConnectionBased()) { final Credentials creds = authState.getCredentials(); if (creds != null) { return creds.getUserPrincipal(); } } return null; }
@Override public Header authenticate(Credentials credentials, HttpRequest request, HttpContext httpContext) throws AuthenticationException { CharArrayBuffer buffer = new CharArrayBuffer(32); buffer.append(AUTH.WWW_AUTH_RESP); buffer.append(": Bearer "); buffer.append(credentials.getUserPrincipal().getName()); return new BufferedHeader(buffer); }