Search in sources :

Example 1 with IamAdminServicesException

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

the class IamAdminServicesHandler method setUpGateway.

@Override
@SecurityCheck
public Gateway setUpGateway(AuthzToken authzToken, Gateway gateway) throws IamAdminServicesException, AuthorizationException {
    TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
    PasswordCredential isSuperAdminCredentials = getSuperAdminPasswordCredential();
    try {
        keycloakclient.addTenant(isSuperAdminCredentials, gateway);
        // Load the tenant admin password stored in gateway request
        CredentialStoreService.Client credentialStoreClient = getCredentialStoreServiceClient();
        // Admin password token should already be stored under requested gateway's gatewayId
        PasswordCredential tenantAdminPasswordCredential = credentialStoreClient.getPasswordCredential(gateway.getIdentityServerPasswordToken(), gateway.getGatewayId());
        if (!keycloakclient.createTenantAdminAccount(isSuperAdminCredentials, gateway, tenantAdminPasswordCredential.getPassword())) {
            logger.error("Admin account creation failed !!, please refer error logs for reason");
        }
        Gateway gatewayWithIdAndSecret = keycloakclient.configureClient(isSuperAdminCredentials, gateway);
        return gatewayWithIdAndSecret;
    } catch (TException | ApplicationSettingsException ex) {
        logger.error("Gateway Setup Failed, reason: " + ex.getMessage(), ex);
        IamAdminServicesException iamAdminServicesException = new IamAdminServicesException(ex.getMessage());
        throw iamAdminServicesException;
    }
}
Also used : TenantManagementKeycloakImpl(org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) 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) CredentialStoreService(org.apache.airavata.credential.store.cpi.CredentialStoreService) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 2 with IamAdminServicesException

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

the class IamAdminServicesHandler method updateUserProfile.

@Override
@SecurityCheck
public void updateUserProfile(AuthzToken authzToken, UserProfile userDetails) throws IamAdminServicesException, AuthorizationException, TException {
    TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
    try {
        String username = authzToken.getClaimsMap().get(Constants.USER_NAME);
        String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
        if (!gatewayId.equals(userDetails.getGatewayId())) {
            throw new IamAdminServicesException("gatewayId in user profile doesn't match authorization token!");
        }
        if (!username.equals(userDetails.getUserId())) {
            throw new IamAdminServicesException("userId in user profile doesn't match authorization token!");
        }
        PasswordCredential credential = getTenantAdminPasswordCredential(gatewayId);
        keycloakclient.updateUserProfile(credential, gatewayId, username, userDetails);
    } catch (ApplicationSettingsException e) {
        throw new IamAdminServicesException("Unable to create service clients. Reason: " + e.getMessage());
    }
}
Also used : TenantManagementKeycloakImpl(org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) PasswordCredential(org.apache.airavata.model.credential.store.PasswordCredential) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 3 with IamAdminServicesException

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

the class IamAdminServicesHandler method registerUser.

// ToDo: Will only be secure when using SSL between PGA and Airavata
@Override
@SecurityCheck
public boolean registerUser(AuthzToken authzToken, String username, String emailAddress, String firstName, String lastName, String newPassword) throws IamAdminServicesException, AuthorizationException {
    TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
    String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
    try {
        PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId);
        if (keycloakclient.createUser(isRealmAdminCredentials, gatewayId, username, emailAddress, firstName, lastName, newPassword))
            return true;
        else
            return false;
    } catch (TException | ApplicationSettingsException ex) {
        String msg = "Error while registering user into Identity Server, reason: " + ex.getMessage();
        logger.error(msg, ex);
        throw new IamAdminServicesException(msg);
    }
}
Also used : TenantManagementKeycloakImpl(org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl) TException(org.apache.thrift.TException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) PasswordCredential(org.apache.airavata.model.credential.store.PasswordCredential) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 4 with IamAdminServicesException

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

the class UserProfileServiceHandler method getIamAdminServicesClient.

private IamAdminServices.Client getIamAdminServicesClient() throws UserProfileServiceException {
    try {
        final int serverPort = Integer.parseInt(ServerSettings.getProfileServiceServerPort());
        final String serverHost = ServerSettings.getProfileServiceServerHost();
        return ProfileServiceClientFactory.createIamAdminServiceClient(serverHost, serverPort);
    } catch (IamAdminServicesException | ApplicationSettingsException e) {
        logger.error("Failed to create IAM Admin Services client", e);
        UserProfileServiceException ex = new UserProfileServiceException("Failed to create IAM Admin Services client");
        throw ex;
    }
}
Also used : ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException)

Example 5 with IamAdminServicesException

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

the class TenantManagementKeycloakImpl method updateUserProfile.

@Override
public void updateUserProfile(PasswordCredential realmAdminCreds, String tenantId, String username, UserProfile userDetails) 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()) {
            UserRepresentation userRepresentation = retrieveUserList.get(0);
            userRepresentation.setFirstName(userDetails.getFirstName());
            userRepresentation.setLastName(userDetails.getLastName());
            userRepresentation.setEmail(userDetails.getEmails().get(0));
            UserResource userResource = client.realm(tenantId).users().get(userRepresentation.getId());
            userResource.update(userRepresentation);
        } else {
            throw new IamAdminServicesException("User [" + username + "] wasn't found in Keycloak!");
        }
    } 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 updating user profile in keycloak server, reason: " + ex.getMessage(), ex);
        IamAdminServicesException exception = new IamAdminServicesException();
        exception.setMessage("Error updating user profile 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)

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