use of org.platformlayer.auth.v1.AuthenticateResponse in project platformlayer by platformlayer.
the class PlatformLayerAuthenticationClient method authenticateWithCertificate.
public PlatformlayerAuthenticationToken authenticateWithCertificate(String username, X509Certificate[] certificateChain, PrivateKey privateKey) throws PlatformlayerAuthenticationClientException {
if (username == null) {
throw new IllegalArgumentException();
}
CertificateCredentials certificateCredentials = new CertificateCredentials();
certificateCredentials.setUsername(username);
Auth auth = new Auth();
auth.setCertificateCredentials(certificateCredentials);
AuthenticateRequest request = new AuthenticateRequest();
request.setAuth(auth);
final KeyManager keyManager = new SimpleClientCertificateKeyManager(privateKey, certificateChain);
for (int i = 0; i < 2; i++) {
AuthenticateResponse response;
try {
RestfulRequest<AuthenticateResponse> httpRequest = httpClient.buildRequest(HttpMethod.POST, "api/tokens", HttpPayload.asXml(request), AuthenticateResponse.class);
httpRequest.setKeyManager(keyManager);
response = httpRequest.execute();
} catch (RestClientException e) {
throw new PlatformlayerAuthenticationClientException("Error authenticating", e);
}
if (i == 0) {
if (response == null || response.getChallenge() == null) {
return null;
}
byte[] challenge = response.getChallenge();
byte[] challengeResponse = decrypt(privateKey, challenge);
certificateCredentials.setChallengeResponse(challengeResponse);
} else {
if (response == null || response.getAccess() == null) {
return null;
}
return new PlatformlayerAuthenticationToken(response.getAccess());
}
}
return null;
}
use of org.platformlayer.auth.v1.AuthenticateResponse in project platformlayer by platformlayer.
the class PlatformlayerAuthenticator method getAuthenticationToken.
@Override
public AuthenticationToken getAuthenticationToken() throws PlatformlayerAuthenticationClientException {
if (token == null) {
PasswordCredentials passwordCredentials = new PasswordCredentials();
passwordCredentials.setUsername(username);
passwordCredentials.setPassword(password);
AuthenticateResponse response = client.authenticate(passwordCredentials);
token = new PlatformlayerAuthenticationToken(response.getAccess());
}
return token;
}
use of org.platformlayer.auth.v1.AuthenticateResponse in project platformlayer by platformlayer.
the class PlatformlayerAuthenticationService method authenticateWithPassword.
@Override
public PlatformlayerAuthenticationToken authenticateWithPassword(String username, String password) throws PlatformlayerAuthenticationClientException {
PasswordCredentials passwordCredentials = new PasswordCredentials();
passwordCredentials.setUsername(username);
passwordCredentials.setPassword(password);
// TODO: Cache auth tokens??
AuthenticateResponse response = keystoneUserClient.authenticate(passwordCredentials);
PlatformlayerAuthenticationToken authToken = new PlatformlayerAuthenticationToken(response.getAccess());
return authToken;
// // TODO: Cache decoded tokens?
// KeystoneAuthentication auth = (KeystoneAuthentication) keystoneSystemClient.validate(
// authToken.getAuthTokenValue(), project);
// if (auth == null) {
// return null;
// }
//
// return new KeystoneUser(auth);
}
use of org.platformlayer.auth.v1.AuthenticateResponse in project platformlayer by platformlayer.
the class PlatformLayerAuthenticationClient method authenticate.
public AuthenticateResponse authenticate(PasswordCredentials passwordCredentials) throws PlatformlayerAuthenticationClientException {
Auth auth = new Auth();
auth.setPasswordCredentials(passwordCredentials);
AuthenticateRequest request = new AuthenticateRequest();
request.setAuth(auth);
AuthenticateResponse response;
try {
response = doSimpleXmlRequest(HttpMethod.POST, "api/tokens", request, AuthenticateResponse.class);
} catch (RestClientException e) {
Integer httpResponseCode = e.getHttpResponseCode();
if (httpResponseCode != null && httpResponseCode == 401) {
throw new PlatformlayerInvalidCredentialsException("Invalid credentials");
}
throw new PlatformlayerAuthenticationClientException("Error authenticating", e);
}
return response;
}
Aggregations