Search in sources :

Example 1 with PasswordCredentials

use of org.platformlayer.auth.v1.PasswordCredentials in project platformlayer by platformlayer.

the class SmokeTest method test.

// private static StandaloneUserServer server;
// 
// @BeforeClass
// public static void startServer() throws Exception {
// File base = new File(".").getCanonicalFile();
// 
// while (!base.getName().equals("auth")) {
// base = base.getParentFile();
// }
// 
// base = new File(base, "server-user");
// 
// server = new StandaloneUserServer();
// server.start(base, 8081);
// }
// 
// @AfterClass
// public static void stopServer() throws Exception {
// server.stop();
// }
@Test
public void test() throws Exception {
    KeystoneAuthenticationClient client = new KeystoneAuthenticationClient();
    PasswordCredentials passwordCredentials = new PasswordCredentials();
    passwordCredentials.setUsername("user1");
    passwordCredentials.setPassword("secretuser1");
    String tenantId = null;
    client.authenticate(tenantId, passwordCredentials);
}
Also used : KeystoneAuthenticationClient(org.openstack.keystone.auth.client.KeystoneAuthenticationClient) PasswordCredentials(org.openstack.docs.identity.api.v2.PasswordCredentials) Test(org.junit.Test)

Example 2 with PasswordCredentials

use of org.platformlayer.auth.v1.PasswordCredentials 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)

Example 3 with PasswordCredentials

use of org.platformlayer.auth.v1.PasswordCredentials 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);
}
Also used : AuthenticateResponse(org.platformlayer.auth.v1.AuthenticateResponse) PasswordCredentials(org.platformlayer.auth.v1.PasswordCredentials) PlatformlayerAuthenticationToken(org.platformlayer.auth.PlatformlayerAuthenticationToken)

Example 4 with PasswordCredentials

use of org.platformlayer.auth.v1.PasswordCredentials 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;
}
Also used : AuthenticateResponse(org.platformlayer.auth.v1.AuthenticateResponse) PasswordCredentials(org.platformlayer.auth.v1.PasswordCredentials)

Aggregations

AuthenticateResponse (org.platformlayer.auth.v1.AuthenticateResponse)3 PasswordCredentials (org.platformlayer.auth.v1.PasswordCredentials)2 Test (org.junit.Test)1 PasswordCredentials (org.openstack.docs.identity.api.v2.PasswordCredentials)1 KeystoneAuthenticationClient (org.openstack.keystone.auth.client.KeystoneAuthenticationClient)1 PlatformlayerAuthenticationClientException (org.platformlayer.auth.PlatformlayerAuthenticationClientException)1 PlatformlayerAuthenticationToken (org.platformlayer.auth.PlatformlayerAuthenticationToken)1 PlatformlayerInvalidCredentialsException (org.platformlayer.auth.PlatformlayerInvalidCredentialsException)1 Auth (org.platformlayer.auth.v1.Auth)1 AuthenticateRequest (org.platformlayer.auth.v1.AuthenticateRequest)1 RestClientException (org.platformlayer.rest.RestClientException)1