use of org.irods.jargon.core.exception.JargonException 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.exception.JargonException in project metalnx-web by irods-contrib.
the class UploadController method upload.
@RequestMapping(value = "/", method = RequestMethod.POST, produces = { "text/plain" })
@ResponseStatus(value = HttpStatus.OK)
public ResponseEntity<?> upload(final HttpServletRequest request) throws DataGridException {
logger.info("upload()");
String uploadMessage = "File Uploaded. ";
String errorType = "";
if (!(request instanceof MultipartHttpServletRequest)) {
logger.warn("Request is not a multipart request.");
uploadMessage = "Request is not a multipart request.";
errorType = FATAL;
return getUploadResponse(uploadMessage, errorType);
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
MultipartFile multipartFile = multipartRequest.getFile("file");
logger.info("multipartFile:{}", multipartFile);
boolean isRuleDeployment = Boolean.parseBoolean(multipartRequest.getParameter("ruleDeployment"));
boolean checksum = Boolean.parseBoolean(multipartRequest.getParameter("checksum"));
boolean replica = Boolean.parseBoolean(multipartRequest.getParameter("replica"));
boolean overwrite = Boolean.parseBoolean(multipartRequest.getParameter("overwriteDuplicateFiles"));
String resources = multipartRequest.getParameter("resources");
String resourcesToUpload = multipartRequest.getParameter("resourcesToUpload");
String destPath = multipartRequest.getParameter("uploadDestinationPath");
logger.info("parsed parameters...");
try {
if (isRuleDeployment) {
ruleDeploymentService.deployRule(multipartFile);
} else {
us.upload(multipartFile, destPath, checksum, replica, resources, resourcesToUpload, overwrite);
}
} catch (DataGridReplicateException e) {
uploadMessage += e.getMessage();
errorType = WARNING;
logger.warn("DataGridReplicateException during upload, will pass back as a warning", e);
} catch (DataGridRuleException e) {
uploadMessage += METADATA_EXTRACTION_FAILED_MSG;
errorType = WARNING;
logger.warn("DataGridRule exception extracting metadata, will pass back as warning", e);
} catch (DataGridException e) {
uploadMessage = e.getMessage();
errorType = FATAL;
logger.error("DataGridException uploading file", e);
logger.warn("DataGridException uplaoding file, will pass back as warning", e);
// throw e;
} catch (JargonException e) {
uploadMessage = e.getMessage();
errorType = FATAL;
logger.error("JargonException uploading file", e);
logger.warn("JargonException uplaoding file, will pass back as warning", e);
} catch (Throwable t) {
logger.error("unexpected exception in upload", t);
errorType = FATAL;
throw t;
}
return getUploadResponse(uploadMessage, errorType);
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class PermissionsServiceImpl method setPermissionOnPath.
@Override
public boolean setPermissionOnPath(DataGridPermType permType, String uName, boolean recursive, boolean inAdminMode, String... paths) throws DataGridConnectionRefusedException {
logger.info("Setting {} permission on path {} for user/group {}", permType, paths, uName);
boolean operationResult = true;
for (String path : paths) {
try {
IRODSFile irodsFile = irodsServices.getIRODSFileFactory().instanceIRODSFile(path);
if (irodsFile.isDirectory()) {
operationResult = chmodCollection(permType, path, recursive, uName, inAdminMode);
} else {
operationResult = chmodDataObject(permType, path, uName, inAdminMode);
}
// If the permissions is NONE, remove all bookmarks associated to the group and the path
if (permType.equals(DataGridPermType.NONE)) {
DataGridGroup group = groupDao.findByGroupnameAndZone(uName, irodsServices.getCurrentUserZone());
if (group != null)
groupBookmarkDao.removeByGroupAndPath(group, path);
}
logger.info("Permission {} for user {} on path {} set successfully", permType, uName, paths);
} catch (JargonException e) {
logger.error("Could not set {} permission on path {} for user/group {}", permType, path, uName, e);
operationResult = false;
}
}
return operationResult;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class SpecQueryServiceImpl method countItemsMatchingFileProperties.
/**
* Counts the number of items matching a file properties search criteria.
*
* @param filePropertiesSearch
* filePropertiesSearch criteria
* @param zone
* zone name
* @param searchAgainstColls
* flag set to true when searching collections and false when
* searching data data objects
* @return total number of items matching a file properties search criteria
* @throws DataGridConnectionRefusedException
* @throws UnsupportedDataGridFeatureException
* @throws JargonException
*/
private int countItemsMatchingFileProperties(List<DataGridFilePropertySearch> filePropertiesSearch, String zone, boolean searchAgainstColls) throws DataGridConnectionRefusedException, UnsupportedDataGridFeatureException, JargonException {
logger.info("countItemsMatchingFileProperties()");
int totalItems = 0;
SpecificQueryAO specificQueryAO = null;
SpecificQuery specQuery = null;
SpecificQueryResultSet queryResultSet = null;
String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
try {
specificQueryAO = adminServices.getSpecificQueryAO();
ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
String query = provider.buildQueryCountItemsMatchingPropertiesSearch(filePropertiesSearch, zone, searchAgainstColls);
logger.debug("query:{}", query);
// Creating Specific Query instance
SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
queryDef.setAlias(userSQLAlias);
queryDef.setSql(query);
// Creating spec query on iRODS
specificQueryAO.addSpecificQuery(queryDef);
specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
logger.info("Specific query: {}", query.toString());
queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
// after running the user specific query, we need to remove from the database
specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
totalItems = DataGridUtils.mapCountQueryResultSetToInteger(queryResultSet);
} catch (JargonException e) {
logger.error("Could not get specific query: ", e);
throw e;
} catch (JargonQueryException e) {
logger.error("Could not get specific query: ", e);
throw new JargonException(e);
}
return totalItems;
}
use of org.irods.jargon.core.exception.JargonException in project metalnx-web by irods-contrib.
the class SpecQueryServiceImpl method searchByFileProperties.
@Override
public SpecificQueryResultSet searchByFileProperties(List<DataGridFilePropertySearch> filePropertySearch, String zone, boolean searchAgainstColls, DataGridPageContext pageContext, int offset, int limit) throws DataGridConnectionRefusedException, JargonException {
SpecificQueryAO specificQueryAO = null;
SpecificQuery specQuery = null;
SpecificQueryResultSet queryResultSet = null;
String userSQLAlias = "metalnxUserQuery_" + System.currentTimeMillis();
try {
specificQueryAO = adminServices.getSpecificQueryAO();
ClientHints clientHints = this.irodsServices.getEnvironmentalInfoAO().retrieveClientHints(false);
SpecificQueryProvider provider = specificQueryProviderFactory.instance(clientHints.whatTypeOfIcatIsIt());
String query = provider.buildQueryForFilePropertiesSearch(filePropertySearch, zone, searchAgainstColls, offset, limit);
// Creating Specific Query instance
SpecificQueryDefinition queryDef = new SpecificQueryDefinition();
queryDef.setAlias(userSQLAlias);
queryDef.setSql(query);
// Creating spec query on iRODS
specificQueryAO.addSpecificQuery(queryDef);
specQuery = SpecificQuery.instanceWithNoArguments(userSQLAlias, 0, zone);
logger.info("Specific query: {}", query);
queryResultSet = specificQueryAO.executeSpecificQueryUsingAlias(specQuery, 99999, 0);
} catch (JargonException e) {
logger.error("Could not get specific query: ", e);
throw e;
} catch (JargonQueryException e) {
logger.error("Could not get specific query: ", e);
throw new JargonException(e);
} catch (UnsupportedDataGridFeatureException e) {
logger.error("Could not get specific query: ", e);
throw new JargonException(e);
} finally {
try {
// after running the user specific query, we need to remove from the database
specificQueryAO.removeSpecificQueryByAlias(userSQLAlias);
} catch (JargonException e) {
logger.error("Could not remove specific query {}: ", userSQLAlias, e.getMessage());
}
}
return queryResultSet;
}
Aggregations