use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class GroupBookmarkServiceImpl method countTotalGroupBookmarks.
@Override
public Integer countTotalGroupBookmarks(String user, String additionalInfo) throws DataGridConnectionRefusedException, DataNotFoundException, JargonException {
Integer totalGroupBookmarks = 0;
if (user == null || additionalInfo == null || user.isEmpty() || additionalInfo.isEmpty()) {
logger.error("Could not get groups bookmarks. Username or zone empty");
return 0;
}
logger.info("Get groups bookmarks for {}", user);
UserAO userAO = adminServices.getUserAO();
User iRodsUser = userAO.findByName(user);
if (iRodsUser != null) {
String[] groupIds = userService.getGroupIdsForUser(user, additionalInfo);
totalGroupBookmarks = groupBookmarkDao.countGroupBookmarksByGroupsIds(groupIds).intValue();
}
return totalGroupBookmarks;
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class IRODSAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String username = authentication.getName();
String password = authentication.getCredentials().toString();
AuthResponse authResponse;
UsernamePasswordAuthenticationToken authObject;
logger.debug("Setting username {}", username);
try {
authResponse = this.authenticateAgainstIRODS(username, password);
// Settings iRODS account
this.irodsAccount = authResponse.getAuthenticatedIRODSAccount();
// Retrieving logging user
User irodsUser = new User();
try {
irodsUser = this.irodsAccessObjectFactory.getUserAO(this.irodsAccount).findByName(username);
} catch (JargonException e) {
logger.error("Could not find user: " + e.getMessage());
}
GrantedAuthority grantedAuth;
if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN)) {
grantedAuth = new IRODSAdminGrantedAuthority();
} else {
grantedAuth = new IRODSUserGrantedAuthority();
}
// Settings granted authorities
List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();
grantedAuths.add(grantedAuth);
// Returning authentication token with the access object factory injected
authObject = new UsernamePasswordAuthenticationToken(username, password, grantedAuths);
// Creating UserTokenDetails instance for the current authenticated user
UserTokenDetails userDetails = new UserTokenDetails();
userDetails.setIrodsAccount(this.irodsAccount);
userDetails.setUser(this.user);
// Settings the user details object into the authentication object
authObject.setDetails(userDetails);
} catch (TransactionException e) {
logger.error("Database not responding");
throw new DataGridDatabaseException(e.getMessage());
} catch (InvalidUserException | org.irods.jargon.core.exception.AuthenticationException e) {
logger.error("Could not authenticate user: ", username);
throw new DataGridAuthenticationException(e.getMessage());
} catch (JargonException e) {
logger.error("Server not responding");
throw new DataGridServerException(e.getMessage());
}
return authObject;
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class SyncJobs method executeUsersSync.
private void executeUsersSync() {
try {
// Gets all users existing in iRODS
List<User> irodsUsers = this.findAllIRODSUsers();
HashMap<Long, User> hashMapIRodsUsers = new HashMap<Long, User>();
for (User user : irodsUsers) {
if (user.getUserType() != UserTypeEnum.RODS_GROUP) {
hashMapIRodsUsers.put(Long.valueOf(user.getId()), user);
}
}
// Gets all users existing in our database
List<DataGridUser> dbUsers = userDao.findAll(DataGridUser.class);
HashMap<Long, DataGridUser> hashMapDBUsers = new HashMap<Long, DataGridUser>();
for (DataGridUser dataGridUser : dbUsers) {
hashMapDBUsers.put(dataGridUser.getDataGridId(), dataGridUser);
}
Set<Long> irodsUserIDs = hashMapIRodsUsers.keySet();
Set<Long> dbDataGridUserIDs = hashMapDBUsers.keySet();
// action: remove this user from our database
for (Long id : dbDataGridUserIDs) {
if (!irodsUserIDs.contains(id)) {
String usernameDeleted = hashMapDBUsers.get(id).getUsername();
long userID = hashMapDBUsers.get(id).getId();
long dataGridID = hashMapDBUsers.get(id).getDataGridId();
userDao.deleteByDataGridId(id);
logger.info("[DELETE] User " + usernameDeleted + " (iRODS id: " + userID + ") " + " (DataGrid id: " + dataGridID + ") " + " was deleted from database.");
}
}
// action: add this user to our database
for (Long id : irodsUserIDs) {
if (!dbDataGridUserIDs.contains(id)) {
User irodsUserMissingInDB = hashMapIRodsUsers.get(id);
DataGridUser userMissingInDB = new DataGridUser();
userMissingInDB.setDataGridId(Long.valueOf(irodsUserMissingInDB.getId()));
userMissingInDB.setUsername(irodsUserMissingInDB.getName());
userMissingInDB.setAdditionalInfo(irodsUserMissingInDB.getZone());
userMissingInDB.setUserType(irodsUserMissingInDB.getUserType().getTextValue());
userMissingInDB.setEnabled(true);
userDao.save(userMissingInDB);
logger.info("[INSERT] User " + userMissingInDB.getUsername() + " (iRODS id: " + userMissingInDB.getDataGridId() + ") " + " was added to database.");
}
}
} catch (Exception e) {
logger.error("Could not synchronize database and iRODS (users): ", e);
}
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class GroupServiceImpl method getMemberList.
@Override
public String[] getMemberList(DataGridGroup group) throws DataGridConnectionRefusedException {
UserGroupAO userGroupAO = irodsServices.getGroupAO();
try {
List<User> groupMembers = userGroupAO.listUserGroupMembers(group.getGroupname());
String[] dataGridIds = new String[groupMembers.size()];
for (int i = 0; i < groupMembers.size(); i++) {
dataGridIds[i] = groupMembers.get(i).getId();
}
return dataGridIds;
} catch (JargonException e) {
logger.error("Could not get members list for group [" + group.getGroupname() + "]: ", e);
}
return new String[0];
}
use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class SyncJobs method executeGroupSync.
private void executeGroupSync() {
try {
// Gets all groups existing in iRODS
// OBS: we're using User to find Groups because UserGroup doesn't
// have the get type
// method and if we don't use such method we'll get a list of users
// and groups,
// rather than list containing only groups
List<User> irodsGroups = this.findAllIRODSUsers();
HashMap<Long, User> hashMapIRodsGroups = new HashMap<Long, User>();
for (User group : irodsGroups) {
if (group.getUserType() == UserTypeEnum.RODS_GROUP) {
hashMapIRodsGroups.put(Long.valueOf(group.getId()), group);
}
}
// Gets all groups existing in our database
List<DataGridGroup> dbGroups = groupDao.findAll(DataGridGroup.class);
HashMap<Long, DataGridGroup> hashMapDBGroups = new HashMap<Long, DataGridGroup>();
for (DataGridGroup dataGridGroup : dbGroups) {
hashMapDBGroups.put(dataGridGroup.getDataGridId(), dataGridGroup);
}
Set<Long> irodsGroupIDs = hashMapIRodsGroups.keySet();
Set<Long> dbDataGridGroupIDs = hashMapDBGroups.keySet();
// action: remove this Group from our database
for (Long id : dbDataGridGroupIDs) {
if (!irodsGroupIDs.contains(id)) {
String groupnameDeleted = hashMapDBGroups.get(id).getGroupname();
long groupID = hashMapDBGroups.get(id).getId();
long dataGridID = hashMapDBGroups.get(id).getDataGridId();
groupDao.deleteByDataGridGroupId(id);
logger.info("[DELETE] Group " + groupnameDeleted + " (iRODS id: " + groupID + ") " + " (DataGrid id: " + dataGridID + ") " + " was deleted from database.");
}
}
// action: add this Group to our database
for (Long id : irodsGroupIDs) {
if (!dbDataGridGroupIDs.contains(id)) {
// users and groups are dealt the same way by iRODS
User irodsGroupMissingInDB = hashMapIRodsGroups.get(id);
DataGridGroup groupMissingInDB = new DataGridGroup();
groupMissingInDB.setDataGridId(Long.valueOf(irodsGroupMissingInDB.getId()));
groupMissingInDB.setGroupname(irodsGroupMissingInDB.getName());
groupMissingInDB.setAdditionalInfo(irodsGroupMissingInDB.getZone());
groupDao.save(groupMissingInDB);
logger.info("[INSERT] Group " + groupMissingInDB.getGroupname() + " (iRODS id: " + groupMissingInDB.getDataGridId() + ") " + " was added to database");
}
}
} catch (Exception e) {
logger.error("Could not synchronize database and iRODS (Groups): ", e);
}
}
Aggregations