Search in sources :

Example 1 with PlatformlayerInvalidCredentialsException

use of org.platformlayer.auth.PlatformlayerInvalidCredentialsException 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;
}
Also used : AuthenticateResponse(org.platformlayer.auth.v1.AuthenticateResponse) AuthenticateRequest(org.platformlayer.auth.v1.AuthenticateRequest) PlatformlayerInvalidCredentialsException(org.platformlayer.auth.PlatformlayerInvalidCredentialsException) Auth(org.platformlayer.auth.v1.Auth) RestClientException(org.platformlayer.rest.RestClientException) PlatformlayerAuthenticationClientException(org.platformlayer.auth.PlatformlayerAuthenticationClientException)

Aggregations

PlatformlayerAuthenticationClientException (org.platformlayer.auth.PlatformlayerAuthenticationClientException)1 PlatformlayerInvalidCredentialsException (org.platformlayer.auth.PlatformlayerInvalidCredentialsException)1 Auth (org.platformlayer.auth.v1.Auth)1 AuthenticateRequest (org.platformlayer.auth.v1.AuthenticateRequest)1 AuthenticateResponse (org.platformlayer.auth.v1.AuthenticateResponse)1 RestClientException (org.platformlayer.rest.RestClientException)1