use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project coprhd-controller by CoprHD.
the class RestClientFactory method getRESTClient.
public RestClientItf getRESTClient(URI endpoint, String username, String password, boolean authFilter) {
RestClientItf clientApi = _clientMap.get(endpoint.toString() + ":" + username + ":" + password);
if (clientApi == null) {
Client jerseyClient = new ApacheHttpClient(_clientHandler);
if (authFilter) {
jerseyClient.addFilter(new HTTPBasicAuthFilter(username, password));
}
clientApi = createNewRestClient(endpoint, username, password, jerseyClient);
_clientMap.putIfAbsent(endpoint.toString() + ":" + username + ":" + password, clientApi);
}
return clientApi;
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project coprhd-controller by CoprHD.
the class LogServiceTest method initToken.
/**
* Create https client after invoking the login api to get security token
*
* @return
*/
private static void initToken() {
Client client = Client.create();
client.setFollowRedirects(false);
client.addFilter(new HTTPBasicAuthFilter(SYSADMIN, SYSADMIN_PASSWORD));
ClientResponse loginResp = client.resource(LOGIN_URI).get(ClientResponse.class);
Assert.assertEquals(200, loginResp.getStatus());
authToken = loginResp.getHeaders().getFirst(AUTH_TOKEN_HEADER);
Assert.assertNotNull(authToken);
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project coprhd-controller by CoprHD.
the class RESTClientUtil method authenticate.
private void authenticate(final Client c, final int authenticateCallCount) throws NoSuchAlgorithmException {
final String methodName = "authenticate(): ";
log.debug(methodName + "Called");
disableCertificateValidation();
c.setFollowRedirects(false);
if (log.isTraceEnabled()) {
c.addFilter(new LoggingFilter());
}
c.addFilter(new HTTPBasicAuthFilter(this._username, this._password));
c.addFilter(new ClientFilter() {
private Object authToken;
// private int callCount = authenticateCallCount;
@Override
public ClientResponse handle(ClientRequest request) throws ClientHandlerException {
if (authToken != null) {
request.getHeaders().put(AUTH_TOKEN_HEADER, Collections.singletonList(authToken));
}
ClientResponse response = getNext().handle(request);
if (response.getHeaders() != null && response.getHeaders().containsKey(AUTH_TOKEN_HEADER)) {
authToken = (response.getHeaders().getFirst(AUTH_TOKEN_HEADER));
}
if (response.getStatus() == 302) {
WebResource wb = c.resource(response.getLocation());
response = wb.header(AUTH_TOKEN_HEADER, authToken).get(ClientResponse.class);
}
return response;
}
});
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project coprhd-controller by CoprHD.
the class AuthClient method login.
/**
* Performs a login operation. The token is automatically associated with this client
* connection.
*
* @param username The username.
* @param password The password.
* @return The authentication token.
*/
public String login(String username, String password) {
WebResource resource = client.getClient().resource(client.uriBuilder("/login").build());
resource.addFilter(new HTTPBasicAuthFilter(username, password));
ClientResponse response = resource.get(ClientResponse.class);
response.close();
client.setLoginTime(System.currentTimeMillis());
return client.getAuthToken();
}
use of com.sun.jersey.api.client.filter.HTTPBasicAuthFilter in project pentaho-platform by pentaho.
the class CommandLineProcessor method initRestService.
/**
* Used only for REST Jersey calls
*
* @throws ParseException
*/
private void initRestService() throws ParseException, InitializationException {
// get information about the remote connection
String username = getOptionValue(INFO_OPTION_USERNAME_NAME, true, false);
String password = getOptionValue(INFO_OPTION_PASSWORD_NAME, true, false);
password = KettleTwoWayPasswordEncoder.decryptPasswordOptionallyEncrypted(password);
ClientConfig clientConfig = new DefaultClientConfig();
clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
client = Client.create(clientConfig);
client.addFilter(new HTTPBasicAuthFilter(username, password));
}
Aggregations