use of org.apache.airavata.service.security.interceptor.SecurityCheck in project airavata by apache.
the class AiravataServerHandler method getExperimentsInProject.
/**
* Get Experiments within project with pagination. Results will be sorted
* based on creation time DESC
*
* @param projectId
* Identifier of the project
* @param limit
* Amount of results to be fetched
* @param offset
* The starting point of the results to be fetched
*/
@Override
@SecurityCheck
public List<ExperimentModel> getExperimentsInProject(AuthzToken authzToken, String projectId, int limit, int offset) throws InvalidRequestException, AiravataClientException, AiravataSystemException, ProjectNotFoundException, AuthorizationException, TException {
RegistryService.Client regClient = registryClientPool.getResource();
SharingRegistryService.Client sharingClient = sharingClientPool.getResource();
try {
Project project = regClient.getProject(projectId);
if (ServerSettings.isEnableSharing() && !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.USER_NAME).equals(project.getOwner()) || !authzToken.getClaimsMap().get(org.apache.airavata.common.utils.Constants.GATEWAY_ID).equals(project.getGatewayId())) {
try {
String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
String userId = authzToken.getClaimsMap().get(Constants.USER_NAME);
if (!sharingClient.userHasAccess(gatewayId, userId + "@" + gatewayId, projectId, gatewayId + ":READ")) {
throw new AuthorizationException("User does not have permission to access this resource");
}
} catch (Exception e) {
throw new AuthorizationException("User does not have permission to access this resource");
}
}
List<ExperimentModel> result = regClient.getExperimentsInProject(projectId, limit, offset);
registryClientPool.returnResource(regClient);
sharingClientPool.returnResource(sharingClient);
return result;
} catch (Exception e) {
logger.error("Error while retrieving the experiments", e);
AiravataSystemException exception = new AiravataSystemException();
exception.setAiravataErrorType(AiravataErrorType.INTERNAL_ERROR);
exception.setMessage("Error while retrieving the experiments. More info : " + e.getMessage());
registryClientPool.returnBrokenResource(regClient);
sharingClientPool.returnBrokenResource(sharingClient);
throw exception;
}
}
use of org.apache.airavata.service.security.interceptor.SecurityCheck 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);
}
}
use of org.apache.airavata.service.security.interceptor.SecurityCheck in project airavata by apache.
the class IamAdminServicesHandler method enableUser.
@Override
@SecurityCheck
public boolean enableUser(AuthzToken authzToken, String username) throws IamAdminServicesException, AuthorizationException {
TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
try {
PasswordCredential isRealmAdminCredentials = getTenantAdminPasswordCredential(gatewayId);
if (keycloakclient.enableUserAccount(isRealmAdminCredentials, gatewayId, username))
return true;
else
return false;
} catch (TException | ApplicationSettingsException ex) {
String msg = "Error while enabling user account, reason: " + ex.getMessage();
logger.error(msg, ex);
throw new IamAdminServicesException(msg);
}
}
use of org.apache.airavata.service.security.interceptor.SecurityCheck in project airavata by apache.
the class IamAdminServicesHandler method addRoleToUser.
@Override
@SecurityCheck
public boolean addRoleToUser(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.addRoleToUser(isRealmAdminCredentials, gatewayId, username, roleName);
} catch (TException | ApplicationSettingsException ex) {
String msg = "Error while adding role to user, reason: " + ex.getMessage();
logger.error(msg, ex);
throw new IamAdminServicesException(msg);
}
}
use of org.apache.airavata.service.security.interceptor.SecurityCheck 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);
}
}
Aggregations