Search in sources :

Example 21 with IamAdminServicesException

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

the class IamAdminServicesHandler method resetUserPassword.

@Override
@SecurityCheck
public boolean resetUserPassword(AuthzToken authzToken, String username, String newPassword) throws IamAdminServicesException, AuthorizationException, TException {
    TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
    String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
    try {
        PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId);
        if (keycloakclient.resetUserPassword(isRealmAdminCredentials, gatewayId, username, newPassword))
            return true;
        else
            return false;
    } catch (TException | ApplicationSettingsException ex) {
        String msg = "Error while resetting user password in 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 22 with IamAdminServicesException

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

the class IamAdminServicesHandler method findUsers.

@Override
@SecurityCheck
public List<UserProfile> findUsers(AuthzToken authzToken, String email, String userId) throws IamAdminServicesException, AuthorizationException, TException {
    TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
    String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
    try {
        PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId);
        return keycloakclient.findUser(isRealmAdminCredentials, gatewayId, email, userId);
    } catch (TException | ApplicationSettingsException ex) {
        String msg = "Error while retrieving users from 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 23 with IamAdminServicesException

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

the class IamAdminServicesHandler method removeRoleFromUser.

@Override
@SecurityCheck
public boolean removeRoleFromUser(AuthzToken authzToken, String username, String roleName) throws IamAdminServicesException, AuthorizationException, TException {
    TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
    String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
    try {
        PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId);
        return keycloakclient.removeRoleFromUser(isRealmAdminCredentials, gatewayId, username, roleName);
    } catch (TException | ApplicationSettingsException ex) {
        String msg = "Error while removing role from user, 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 24 with IamAdminServicesException

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

the class SetupNewGateway method findUser.

// public static void resetPassword(){
// UserProfile user = new UserProfile();
// user.setUserId("testuser");
// List<String> emails = new ArrayList<>();
// emails.add("some.man@outlook.com");
// user.setGatewayId("maven.test.gateway");
// user.setEmails(emails);
// TenantManagementKeycloakImpl client = new TenantManagementKeycloakImpl();
// try {
// PasswordCredential tenantAdminCreds = new PasswordCredential();
// tenantAdminCreds.setGatewayId(user.getGatewayId());
// tenantAdminCreds.setDescription("test credentials for tenant admin creation");
// tenantAdminCreds.setLoginUserName("mavenTest");
// tenantAdminCreds.setPassword("Test@1234");
// tenantAdminCreds.setPortalUserName("TenantAdmin");
// client.resetUserPassword(tenantAdminCreds,user,"test@123");
// } catch (IamAdminServicesException e) {
// e.printStackTrace();
// }
// }
public static void findUser() {
    UserProfile user = new UserProfile();
    List<String> emails = new ArrayList<>();
    emails.add("some.man@outlook.com");
    user.setGatewayId("maven.test.gateway");
    user.setEmails(emails);
    TenantManagementKeycloakImpl client = new TenantManagementKeycloakImpl();
    try {
        PasswordCredential tenantAdminCreds = new PasswordCredential();
        tenantAdminCreds.setGatewayId(user.getGatewayId());
        tenantAdminCreds.setDescription("test credentials for tenant admin creation");
        tenantAdminCreds.setLoginUserName("mavenTest");
        tenantAdminCreds.setPassword("Test@1234");
        tenantAdminCreds.setPortalUserName("TenantAdmin");
        List<UserProfile> list = client.findUser(tenantAdminCreds, "maven.test.gateway", "some.man@outlook.com", null);
        System.out.println(list.get(0).getUserId());
    } catch (IamAdminServicesException e) {
        e.printStackTrace();
    }
}
Also used : TenantManagementKeycloakImpl(org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl) UserProfile(org.apache.airavata.model.user.UserProfile) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) ArrayList(java.util.ArrayList) PasswordCredential(org.apache.airavata.model.credential.store.PasswordCredential)

Example 25 with IamAdminServicesException

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

the class SetupNewGateway method UserRegistration.

public static void UserRegistration() {
    UserProfile user = new UserProfile();
    user.setUserId("testuser");
    user.setFirstName("test-firstname");
    user.setLastName("test-lastname");
    List<String> emails = new ArrayList<>();
    emails.add("some.man@outlook.com");
    user.setGatewayId("maven.test.gateway");
    user.setEmails(emails);
    PasswordCredential tenantAdminCreds = new PasswordCredential();
    tenantAdminCreds.setGatewayId(user.getGatewayId());
    tenantAdminCreds.setDescription("test credentials for tenant admin creation");
    tenantAdminCreds.setLoginUserName("mavenTest");
    tenantAdminCreds.setPassword("Test@1234");
    tenantAdminCreds.setPortalUserName("TenantAdmin");
    TenantManagementKeycloakImpl client = new TenantManagementKeycloakImpl();
    try {
        client.createUser(tenantAdminCreds, user.getGatewayId(), user.getUserId(), user.getEmails().get(0), user.getFirstName(), user.getLastName(), "test@123");
        client.enableUserAccount(tenantAdminCreds, user.getGatewayId(), user.getUserId());
    } catch (IamAdminServicesException e) {
        e.printStackTrace();
    }
}
Also used : TenantManagementKeycloakImpl(org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl) UserProfile(org.apache.airavata.model.user.UserProfile) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) ArrayList(java.util.ArrayList) PasswordCredential(org.apache.airavata.model.credential.store.PasswordCredential)

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