use of org.irods.jargon.core.pub.domain.User in project metalnx-web by irods-contrib.
the class IRODSAuthenticationProvider method authenticateAgainstIRODS.
private AuthResponse authenticateAgainstIRODS(String username, String password) throws JargonException {
if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
throw new DataGridAuthenticationException("Username or password invalid: null or empty value(s) provided");
} else if (username.equalsIgnoreCase(IRODS_ANONYMOUS_ACCOUNT)) {
throw new DataGridAuthenticationException("Cannot log in as anonymous");
}
AuthResponse authResponse;
// Getting iRODS protocol set
logger.debug("Creating IRODSAccount object.");
this.irodsAccount = IRODSAccount.instance(this.irodsHost, Integer.parseInt(this.irodsPort), username, password, "", this.irodsZoneName, "demoResc");
this.irodsAccount.setAuthenticationScheme(AuthScheme.findTypeByString(this.irodsAuthScheme));
logger.debug("Done.");
logger.debug("Authenticating IRODSAccount:\n\tusername: {}\n\tpassword: ***********\n\tirodsHost: {}\n\tirodsZone: {}", username, this.irodsHost, this.irodsZoneName);
authResponse = this.irodsAccessObjectFactory.authenticateIRODSAccount(this.irodsAccount);
logger.debug("Done.");
if (authResponse.isSuccessful()) {
if (StringUtils.isEmpty(authResponse.getAuthMessage())) {
logger.debug("AuthMessage: {}", authResponse.getAuthMessage());
}
// Settings iRODS account
this.irodsAccount = authResponse.getAuthenticatingIRODSAccount();
// Retrieving logging user
UserAO userAO = this.irodsAccessObjectFactory.getUserAO(this.irodsAccount);
User irodsUser = userAO.findByName(username);
// If the user is found and has administrator permissions
if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN) || irodsUser.getUserType().equals(UserTypeEnum.RODS_USER)) {
// If the user is not yet persisted in our database
DataGridUser user = this.userDao.findByUsernameAndZone(irodsUser.getName(), irodsUser.getZone());
if (user == null) {
user = new DataGridUser();
user.setUsername(irodsUser.getName());
user.setAdditionalInfo(irodsUser.getZone());
user.setDataGridId(Long.parseLong(irodsUser.getId()));
user.setEnabled(true);
user.setFirstName("");
user.setLastName("");
if (irodsUser.getUserType().equals(UserTypeEnum.RODS_ADMIN)) {
user.setUserType(UserTypeEnum.RODS_ADMIN.getTextValue());
} else {
user.setUserType(UserTypeEnum.RODS_USER.getTextValue());
}
this.userDao.save(user);
}
this.user = user;
}
}
return authResponse;
}
Aggregations