use of org.apache.airavata.model.user.UserProfile in project airavata by apache.
the class TenantManagementKeycloakImpl method convertUserRepresentationToUserProfile.
private UserProfile convertUserRepresentationToUserProfile(UserRepresentation userRepresentation, String tenantId) {
UserProfile profile = new UserProfile();
profile.setAiravataInternalUserId(userRepresentation.getUsername() + "@" + tenantId);
profile.setGatewayId(tenantId);
profile.setUserId(userRepresentation.getUsername());
profile.setFirstName(userRepresentation.getFirstName());
profile.setLastName(userRepresentation.getLastName());
profile.setEmails(Arrays.asList(new String[] { userRepresentation.getEmail() }));
// Just default these. UserProfile isn't a great data model for this data since it isn't actually the Airavata UserProfile
profile.setLastAccessTime(0);
profile.setCreationTime(0);
profile.setValidUntil(0);
// Use state field to indicate whether user has been enabled in Keycloak
if (userRepresentation.isEnabled()) {
profile.setState(Status.CONFIRMED);
} else {
profile.setState(Status.PENDING_CONFIRMATION);
}
return profile;
}
use of org.apache.airavata.model.user.UserProfile in project airavata by apache.
the class TenantManagementKeycloakImpl method getUsersWithRole.
@Override
public List<UserProfile> getUsersWithRole(PasswordCredential realmAdminCreds, String tenantId, String roleName) throws IamAdminServicesException {
Keycloak client = null;
try {
client = TenantManagementKeycloakImpl.getClient(ServerSettings.getIamServerUrl(), tenantId, realmAdminCreds);
// FIXME: this only searches through the most recent 100 users for the given role (assuming there are no more than 10,000 users in the gateway)
int totalUserCount = client.realm(tenantId).users().count();
logger.debug("getUsersWithRole: totalUserCount=" + totalUserCount);
// Load all users in batches
List<UserRepresentation> allUsers = new ArrayList<>();
int userBatchSize = 100;
for (int start = 0; start < totalUserCount; start = start + userBatchSize) {
logger.debug("getUsersWithRole: fetching " + userBatchSize + " users...");
allUsers.addAll(client.realm(tenantId).users().search(null, null, null, null, start, userBatchSize));
}
logger.debug("getUsersWithRole: all users count=" + allUsers.size());
allUsers.sort((a, b) -> a.getCreatedTimestamp() - b.getCreatedTimestamp() > 0 ? -1 : 1);
// The 100 most recently created users
List<UserRepresentation> mostRecentUsers = allUsers.subList(0, Math.min(allUsers.size(), 100));
logger.debug("getUsersWithRole: most recent users count=" + mostRecentUsers.size());
List<UserProfile> usersWithRole = new ArrayList<>();
for (UserRepresentation user : mostRecentUsers) {
UserResource userResource = client.realm(tenantId).users().get(user.getId());
List<RoleRepresentation> roleRepresentations = userResource.roles().realmLevel().listAll();
for (RoleRepresentation roleRepresentation : roleRepresentations) {
if (roleRepresentation.getName().equals(roleName)) {
usersWithRole.add(convertUserRepresentationToUserProfile(user, tenantId));
break;
}
}
}
logger.debug("getUsersWithRole: most recent users with role count=" + usersWithRole.size());
return usersWithRole;
} 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) {
logger.debug("getUsersWithRole: closing client...");
client.close();
logger.debug("getUsersWithRole: client closed");
}
}
}
use of org.apache.airavata.model.user.UserProfile 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();
}
}
use of org.apache.airavata.model.user.UserProfile 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();
}
}
use of org.apache.airavata.model.user.UserProfile in project airavata by apache.
the class MigrationManager method migrateUserProfilesToAiravata.
/* Method used to migrate User profiles to Airavata DB by making a call to User profile thrift Service */
private boolean migrateUserProfilesToAiravata(List<UserProfileDAO> ISProfileList) throws TException, ApplicationSettingsException {
System.out.println("Initiating migration to Airavata internal DB ...");
UserProfileService.Client client = ProfileServiceClientFactory.createUserProfileServiceClient(profileServiceServerHost, profileServiceServerPort);
UserProfile airavataUserProfile = new UserProfile();
// Here are the data associations...
for (UserProfileDAO ISProfile : ISProfileList) {
airavataUserProfile.setAiravataInternalUserId(ISProfile.getUserName() + "@" + ISProfile.getGatewayID());
airavataUserProfile.setFirstName(ISProfile.getFirstName());
airavataUserProfile.setLastName(ISProfile.getLastName());
airavataUserProfile.setUserId(ISProfile.getUserName());
airavataUserProfile.setGatewayId(ISProfile.getGatewayID());
List<String> emails = new ArrayList<String>();
emails.add(ISProfile.getEmail());
airavataUserProfile.setEmails(emails);
airavataUserProfile.setHomeOrganization(ISProfile.getOrganization());
airavataUserProfile.setPhones(ISProfile.getPhones());
airavataUserProfile.setCountry(ISProfile.getCountry());
airavataUserProfile.setCreationTime(new Date().getTime());
airavataUserProfile.setLastAccessTime(new Date().getTime());
airavataUserProfile.setValidUntil(-1);
airavataUserProfile.setState(Status.ACTIVE);
// TODO: fix authtzToken, for now we are using empty token, but need to properly populate claims map
AuthzToken authzToken = new AuthzToken("dummy_token");
Map<String, String> claimsMap = new HashMap<>();
claimsMap.put(Constants.USER_NAME, ISProfile.getUserName());
claimsMap.put(Constants.GATEWAY_ID, ISProfile.getGatewayID());
authzToken.setClaimsMap(claimsMap);
client.addUserProfile(authzToken, airavataUserProfile);
}
return false;
}
Aggregations