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();
}
}
}
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();
}
}
}
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();
}
}
}
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);
}
}
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());
}
}
Aggregations