use of org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl 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;
}
}
use of org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl 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());
}
}
use of org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl 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);
}
}
use of org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl 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.core.impl.TenantManagementKeycloakImpl in project airavata by apache.
the class IamAdminServicesHandler method getUsersWithRole.
@Override
@SecurityCheck
public List<UserProfile> getUsersWithRole(AuthzToken authzToken, 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.getUsersWithRole(isRealmAdminCredentials, gatewayId, roleName);
} catch (Exception ex) {
String msg = "Error while retrieving users with role, reason: " + ex.getMessage();
logger.error(msg, ex);
throw new IamAdminServicesException(msg);
}
}
Aggregations