use of org.apache.airavata.common.exception.ApplicationSettingsException 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.common.exception.ApplicationSettingsException 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.common.exception.ApplicationSettingsException 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.common.exception.ApplicationSettingsException in project airavata by apache.
the class SecurityInterceptor method authorize.
private void authorize(AuthzToken authzToken, Map<String, String> metaData) throws AuthorizationException {
try {
boolean isAPISecured = ServerSettings.isAPISecured();
if (isAPISecured) {
AiravataSecurityManager securityManager = SecurityManagerFactory.getSecurityManager();
boolean isAuthz = securityManager.isUserAuthorized(authzToken, metaData);
if (!isAuthz) {
throw new AuthorizationException("User is not authenticated or authorized.");
}
}
} catch (AiravataSecurityException e) {
logger.error(e.getMessage(), e);
throw new AuthorizationException("Error in authenticating or authorizing user.");
} catch (ApplicationSettingsException e) {
logger.error(e.getMessage(), e);
throw new AuthorizationException("Internal error in authenticating or authorizing user.");
}
}
use of org.apache.airavata.common.exception.ApplicationSettingsException in project airavata by apache.
the class AppEnvironmentResource method isExists.
@Override
public boolean isExists(Object identifier) throws AppCatalogException {
HashMap<String, String> ids;
if (identifier instanceof Map) {
ids = (HashMap) identifier;
} else {
logger.error("Identifier should be a map with the field name and it's value");
throw new AppCatalogException("Identifier should be a map with the field name and it's value");
}
EntityManager em = null;
try {
em = AppCatalogJPAUtils.getEntityManager();
AppEnvironment appEnvironment = em.find(AppEnvironment.class, new AppEnvironment_PK(ids.get(AppEnvironmentConstants.DEPLOYMENT_ID), ids.get(AppEnvironmentConstants.NAME)));
em.close();
return appEnvironment != null;
} catch (ApplicationSettingsException e) {
logger.error(e.getMessage(), e);
throw new AppCatalogException(e);
} finally {
if (em != null && em.isOpen()) {
if (em.getTransaction().isActive()) {
em.getTransaction().rollback();
}
em.close();
}
}
}
Aggregations