use of org.apache.http.auth.UsernamePasswordCredentials in project jena by apache.
the class TestFusekiTestAuth method testServer_auth_bad_user.
@Test(expected = HttpException.class)
public void testServer_auth_bad_user() {
BasicCredentialsProvider credsProvider = new BasicCredentialsProvider();
Credentials credentials = new UsernamePasswordCredentials("USERUSER", PASSWORD);
credsProvider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build();
try (TypedInputStream in = HttpOp.execHttpGet(FusekiTestAuth.urlDataset(), "*/*", client, null)) {
} catch (HttpException ex) {
throw assertAuthHttpException(ex);
}
}
use of org.apache.http.auth.UsernamePasswordCredentials in project karaf by apache.
the class SyncopeLoginModule method login.
public boolean login() throws LoginException {
Callback[] callbacks = new Callback[2];
callbacks[0] = new NameCallback("Username: ");
callbacks[1] = new PasswordCallback("Password: ", false);
try {
callbackHandler.handle(callbacks);
} catch (IOException ioException) {
throw new LoginException(ioException.getMessage());
} catch (UnsupportedCallbackException unsupportedCallbackException) {
throw new LoginException(unsupportedCallbackException.getMessage() + " not available to obtain information from user.");
}
user = ((NameCallback) callbacks[0]).getName();
char[] tmpPassword = ((PasswordCallback) callbacks[1]).getPassword();
if (tmpPassword == null) {
tmpPassword = new char[0];
}
String password = new String(tmpPassword);
principals = new HashSet<>();
// authenticate the user on Syncope
LOGGER.debug("Authenticate user {} on Syncope located {}", user, address);
DefaultHttpClient client = new DefaultHttpClient();
Credentials creds = new UsernamePasswordCredentials(user, password);
client.getCredentialsProvider().setCredentials(AuthScope.ANY, creds);
HttpGet get = new HttpGet(address + "/users/self");
get.setHeader("Content-Type", "application/xml");
List<String> roles = new ArrayList<>();
try {
CloseableHttpResponse response = client.execute(get);
LOGGER.debug("Syncope HTTP response status code: {}", response.getStatusLine().getStatusCode());
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
LOGGER.warn("User {} not authenticated", user);
return false;
}
LOGGER.debug("User {} authenticated", user);
LOGGER.debug("Populating principals with user");
principals.add(new UserPrincipal(user));
LOGGER.debug("Retrieving user {} roles", user);
roles = extractingRoles(EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
LOGGER.error("User {} authentication failed", user, e);
throw new LoginException("User " + user + " authentication failed: " + e.getMessage());
}
LOGGER.debug("Populating principals with roles");
for (String role : roles) {
principals.add(new RolePrincipal(role));
}
return true;
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jena by apache.
the class TestAuth method withBasicAuth.
private static HttpClient withBasicAuth(AuthScope scope, String user, String passwd) {
BasicCredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(user, passwd);
provider.setCredentials(scope, credentials);
return HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
}
use of org.apache.http.auth.UsernamePasswordCredentials in project jena by apache.
the class TestRemoteEndpointConnectionWithAuth method setup.
/**
* Setup for the tests by allocating a Fuseki instance to work with
* @throws IOException
*/
@BeforeClass
public static void setup() throws IOException {
SecurityHandler sh = FusekiTestAuth.makeSimpleSecurityHandler("/*", USER, PASSWORD);
FusekiTestAuth.setupServer(true, sh);
BasicCredentialsProvider credsProv = new BasicCredentialsProvider();
credsProv.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USER, PASSWORD));
client = HttpClients.custom().setDefaultCredentialsProvider(credsProv).build();
}
use of org.apache.http.auth.UsernamePasswordCredentials in project wildfly by wildfly.
the class JASPIHttpSchemeServerAuthModelTestCase method createHttpClient.
private DefaultHttpClient createHttpClient(final URL webAppURL, final String userName, final String userPassword) {
DefaultHttpClient httpClient = new DefaultHttpClient();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(userName, userPassword);
httpClient.getCredentialsProvider().setCredentials(new AuthScope(webAppURL.getHost(), webAppURL.getPort(), DEPLOYMENT_REALM_NAME), credentials);
return httpClient;
}
Aggregations