use of org.irods.jargon.core.connection.auth.AuthResponse 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.connection.auth.AuthResponse in project metalnx-web by irods-contrib.
the class SyncJobs method authenticateIRODSAccount.
private void authenticateIRODSAccount() throws JargonException {
AuthResponse authResponse = null;
if (this.irodsAccount == null) {
// Getting iRODS protocol set
IRODSAccount tempAccount = IRODSAccount.instance(irodsHost, Integer.parseInt(irodsPort), irodsJobUser, irodsJobPassword, "", irodsZone, "demoResc");
tempAccount.setAuthenticationScheme(AuthScheme.findTypeByString(irodsAuthScheme));
authResponse = irodsAccessObjectFactory.authenticateIRODSAccount(tempAccount);
if (authResponse.isSuccessful()) {
this.irodsAccount = authResponse.getAuthenticatedIRODSAccount();
}
}
}
use of org.irods.jargon.core.connection.auth.AuthResponse in project metalnx-web by irods-contrib.
the class AdminServicesImpl method authenticateIRODSAccount.
private void authenticateIRODSAccount() throws JargonException {
String host = configService.getIrodsHost();
int port = Integer.parseInt(configService.getIrodsPort());
String zone = configService.getIrodsZone();
String user = configService.getIrodsJobUser();
String password = configService.getIrodsJobPassword();
String authScheme = configService.getIrodsAuthScheme();
String resc = "demoResc";
String homeDir = "";
if (irodsAccount == null) {
IRODSAccount tempAccount = IRODSAccount.instance(host, port, user, password, homeDir, zone, resc);
tempAccount.setAuthenticationScheme(AuthScheme.findTypeByString(authScheme));
AuthResponse authResponse = irodsAccessObjectFactory.authenticateIRODSAccount(tempAccount);
if (authResponse.isSuccessful()) {
irodsAccount = authResponse.getAuthenticatedIRODSAccount();
}
}
}
use of org.irods.jargon.core.connection.auth.AuthResponse 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