Search in sources :

Example 6 with IamAdminServicesException

use of org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException in project airavata by apache.

the class TenantManagementKeycloakImpl method addRoleToUser.

@Override
public boolean addRoleToUser(PasswordCredential realmAdminCreds, String tenantId, String username, String roleName) throws IamAdminServicesException {
    Keycloak client = null;
    try {
        client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
        List<UserRepresentation> retrieveCreatedUserList = client.realm(tenantId).users().search(username, null, null, null, 0, 1);
        UserResource retrievedUser = client.realm(tenantId).users().get(retrieveCreatedUserList.get(0).getId());
        // Add user to the role
        RoleResource roleResource = client.realm(tenantId).roles().get(roleName);
        retrievedUser.roles().realmLevel().add(Arrays.asList(roleResource.toRepresentation()));
        return true;
    } catch (ApplicationSettingsException ex) {
        logger.error("Error getting values from property file, reason: " + ex.getMessage(), ex);
        IamAdminServicesException exception = new IamAdminServicesException();
        exception.setMessage("Error getting values from property file, reason " + ex.getMessage());
        throw exception;
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) RoleResource(org.keycloak.admin.client.resource.RoleResource) UserResource(org.keycloak.admin.client.resource.UserResource) Keycloak(org.keycloak.admin.client.Keycloak)

Example 7 with IamAdminServicesException

use of org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException in project airavata by apache.

the class TenantManagementKeycloakImpl method resetUserPassword.

@Override
public boolean resetUserPassword(PasswordCredential realmAdminCreds, String tenantId, String username, String newPassword) throws IamAdminServicesException {
    Keycloak client = null;
    try {
        client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
        List<UserRepresentation> retrieveUserList = client.realm(tenantId).users().search(username, null, null, null, 0, 1);
        if (!retrieveUserList.isEmpty()) {
            UserResource retrievedUser = client.realm(tenantId).users().get(retrieveUserList.get(0).getId());
            CredentialRepresentation credential = new CredentialRepresentation();
            credential.setType(CredentialRepresentation.PASSWORD);
            credential.setValue(newPassword);
            credential.setTemporary(false);
            retrievedUser.resetPassword(credential);
            // Remove the UPDATE_PASSWORD required action
            UserRepresentation userRepresentation = retrievedUser.toRepresentation();
            userRepresentation.getRequiredActions().remove("UPDATE_PASSWORD");
            retrievedUser.update(userRepresentation);
            return true;
        } else {
            logger.error("requested User not found");
            return false;
        }
    } catch (ApplicationSettingsException ex) {
        logger.error("Error getting values from property file, reason: " + ex.getMessage(), ex);
        IamAdminServicesException exception = new IamAdminServicesException();
        exception.setMessage("Error getting values from property file, reason " + ex.getMessage());
        throw exception;
    } catch (Exception ex) {
        logger.error("Error resetting user password in keycloak server, reason: " + ex.getMessage(), ex);
        IamAdminServicesException exception = new IamAdminServicesException();
        exception.setMessage("Error resetting user password in keycloak server, reason: " + ex.getMessage());
        throw exception;
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) UserResource(org.keycloak.admin.client.resource.UserResource) Keycloak(org.keycloak.admin.client.Keycloak) IOException(java.io.IOException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException)

Example 8 with IamAdminServicesException

use of org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException in project airavata by apache.

the class TenantManagementKeycloakImpl method findUser.

@Override
public List<UserProfile> findUser(PasswordCredential realmAdminCreds, String tenantId, String email, String userName) throws IamAdminServicesException {
    Keycloak client = null;
    try {
        client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
        List<UserRepresentation> retrieveUserList = client.realm(tenantId).users().search(userName, null, null, email, 0, 1);
        if (!retrieveUserList.isEmpty()) {
            List<UserProfile> userList = new ArrayList<>();
            for (UserRepresentation user : retrieveUserList) {
                UserProfile profile = new UserProfile();
                profile.setUserId(user.getUsername());
                profile.setFirstName(user.getFirstName());
                profile.setLastName(user.getLastName());
                profile.setEmails(Arrays.asList(new String[] { user.getEmail() }));
                userList.add(profile);
            }
            return userList;
        } else {
            logger.error("requested User not found");
            return null;
        }
    } catch (ApplicationSettingsException ex) {
        logger.error("Error getting values from property file, reason: " + ex.getMessage(), ex);
        IamAdminServicesException exception = new IamAdminServicesException();
        exception.setMessage("Error getting values from property file, reason " + ex.getMessage());
        throw exception;
    } catch (Exception ex) {
        logger.error("Error finding user in keycloak server, reason: " + ex.getMessage(), ex);
        IamAdminServicesException exception = new IamAdminServicesException();
        exception.setMessage("Error finding user in keycloak server, reason: " + ex.getMessage());
        throw exception;
    } finally {
        if (client != null) {
            client.close();
        }
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) UserProfile(org.apache.airavata.model.user.UserProfile) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) ArrayList(java.util.ArrayList) Keycloak(org.keycloak.admin.client.Keycloak) IOException(java.io.IOException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException)

Example 9 with IamAdminServicesException

use of org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException in project airavata by apache.

the class SetupNewGateway method setUpGateway.

public static void setUpGateway() {
    Gateway testGateway = new Gateway();
    testGateway.setGatewayId("maven.test.gateway");
    testGateway.setGatewayName("maven test gateway");
    testGateway.setIdentityServerUserName("mavenTest");
    testGateway.setGatewayAdminFirstName("Maven");
    testGateway.setGatewayAdminLastName("Test");
    testGateway.setGatewayAdminEmail("some.man@gmail.com");
    PasswordCredential superAdminCreds = new PasswordCredential();
    superAdminCreds.setGatewayId(testGateway.getGatewayId());
    superAdminCreds.setDescription("test credentials for IS admin creation");
    superAdminCreds.setLoginUserName("airavataAdmin");
    superAdminCreds.setPassword("Airavata@123");
    superAdminCreds.setPortalUserName("superAdmin");
    TenantManagementKeycloakImpl client = new TenantManagementKeycloakImpl();
    try {
        client.addTenant(superAdminCreds, testGateway);
        if (!client.createTenantAdminAccount(superAdminCreds, testGateway, "Test@123")) {
            logger.error("Admin account creation failed !!, please refer error logs for reason");
        }
        Gateway gatewayWithIdAndSecret = client.configureClient(superAdminCreds, testGateway);
        System.out.println(gatewayWithIdAndSecret.getOauthClientId());
        System.out.println(gatewayWithIdAndSecret.getOauthClientSecret());
    } catch (IamAdminServicesException ex) {
        logger.error("Gateway Setup Failed, reason: " + ex.getCause(), ex);
    }
}
Also used : TenantManagementKeycloakImpl(org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) Gateway(org.apache.airavata.model.workspace.Gateway) PasswordCredential(org.apache.airavata.model.credential.store.PasswordCredential)

Example 10 with IamAdminServicesException

use of org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException in project airavata by apache.

the class ProfileServiceClientFactory method createIamAdminServiceClient.

public static IamAdminServices.Client createIamAdminServiceClient(String serverHost, int serverPort) throws IamAdminServicesException {
    try {
        TTransport transport = new TSocket(serverHost, serverPort);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        TMultiplexedProtocol multiplexedProtocol = new TMultiplexedProtocol(protocol, iam_admin_services_cpiConstants.IAM_ADMIN_SERVICES_CPI_NAME);
        return new IamAdminServices.Client(multiplexedProtocol);
    } catch (TTransportException e) {
        throw new IamAdminServicesException(e.getMessage());
    }
}
Also used : TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) TProtocol(org.apache.thrift.protocol.TProtocol) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Aggregations

IamAdminServicesException (org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException)25 ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)21 PasswordCredential (org.apache.airavata.model.credential.store.PasswordCredential)12 TenantManagementKeycloakImpl (org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl)12 Keycloak (org.keycloak.admin.client.Keycloak)11 SecurityCheck (org.apache.airavata.service.security.interceptor.SecurityCheck)9 TException (org.apache.thrift.TException)8 UserResource (org.keycloak.admin.client.resource.UserResource)8 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 UserProfile (org.apache.airavata.model.user.UserProfile)4 Response (javax.ws.rs.core.Response)3 RoleResource (org.keycloak.admin.client.resource.RoleResource)3 Gateway (org.apache.airavata.model.workspace.Gateway)2 CredentialStoreService (org.apache.airavata.credential.store.cpi.CredentialStoreService)1 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)1 AuthorizationException (org.apache.airavata.model.error.AuthorizationException)1 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)1 UserProfileServiceException (org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1