use of org.irods.jargon.core.connection.IRODSAccount in project metalnx-web by irods-contrib.
the class CollectionServiceImpl method getCollectionDataProfile.
@SuppressWarnings("unchecked")
@Override
public DataProfile<IRODSDomainObject> getCollectionDataProfile(String path) throws DataGridException {
IRODSAccount irodsAccount = irodsServices.getUserAO().getIRODSAccount();
logger.info("*****************path **************" + path);
logger.debug("got irodsAccount:{}", irodsAccount);
DataProfilerService dataProfilerService = dataProfilerFactory.instanceDataProfilerService(irodsAccount);
logger.debug("got the dataProfilerService");
// TODO: allow clone()
try {
@SuppressWarnings("rawtypes") DataProfile dataProfile = dataProfilerService.retrieveDataProfile(path);
logger.info("------CollectionInfoController getTestCollectionInfo() ends !!");
logger.info("data profile retrieved:{}", dataProfile);
/*
* TODO: after this do an if test and send to right view with the DataProfile in
* the model
*/
return dataProfile;
} catch (JargonException e) {
logger.error("Could not retrieve collection/dataobject from path: {}", path, e);
throw new DataGridException(e.getMessage());
}
}
use of org.irods.jargon.core.connection.IRODSAccount in project metalnx-web by irods-contrib.
the class TestTicketAuthenticatedAccess method setUp.
@Before
public void setUp() throws DataGridException, JargonException, IOException {
String parentPath = String.format("/%s/home", zone);
targetPath = String.format("%s/%s", parentPath, username);
ticketUtils = new TestTicketUtils(irodsServices);
ticketString = ticketUtils.createTicket(parentPath, username, TicketCreateModeEnum.WRITE);
localFile = ticketUtils.createLocalFile();
filePath = String.format("%s/%s", targetPath, localFile.getName());
IRODSAccount authIrodsAccount = IRODSAccount.instance(host, Integer.valueOf(port), username, password, targetPath, zone, RESOURCE);
UserTokenDetails userTokenDetails = Mockito.mock(UserTokenDetails.class);
Authentication authentication = Mockito.mock(Authentication.class);
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
SecurityContextHolder.setContext(securityContext);
Mockito.when(securityContext.getAuthentication()).thenReturn(authentication);
Mockito.when(authentication.getDetails()).thenReturn(userTokenDetails);
Mockito.when(userTokenDetails.getIrodsAccount()).thenReturn(authIrodsAccount);
}
use of org.irods.jargon.core.connection.IRODSAccount in project metalnx-web by irods-contrib.
the class IRODSLogoutSuccessHandler method onLogoutSuccess.
@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
logger.info("Logging out...");
try {
IRODSAccount irodsAccount = ((UserTokenDetails) authentication.getDetails()).getIrodsAccount();
String username = irodsAccount.getUserName();
logger.info("Closing session and eating all exceptions");
irodsAccessObjectFactory.closeSessionAndEatExceptions(irodsAccount);
irodsAccessObjectFactory.closeSessionAndEatExceptions();
logger.debug("Removing current session temporary directory for file upload");
try {
File tmpSessionDir = new File(username);
if (tmpSessionDir.exists()) {
FileUtils.forceDelete(tmpSessionDir);
}
} catch (Exception e) {
logger.error("User {} temporary directory for upload does not exist.", username);
}
logger.info("invalidating session");
request.getSession().invalidate();
response.sendRedirect("/emc-metalnx-web/login/");
logger.info("User {} disconnected successfully", username);
} catch (Exception e) {
logger.info("User session is already expired. There is no need to clear session.");
}
super.onLogoutSuccess(request, response, authentication);
}
use of org.irods.jargon.core.connection.IRODSAccount in project metalnx-web by irods-contrib.
the class BrowseController method getCollBrowserView.
/**
* Finds all collections and data objects existing under a certain path
*
* @param model
* @param path
* path to get all directories and data objects from
* @return collections browser template that renders all items of certain path
* (parent)
* @throws DataGridConnectionRefusedException
* if Metalnx cannot connect to the grid.
*/
private String getCollBrowserView(final Model model, String path) throws JargonException, DataGridException {
logger.info("getCollBrowserView()");
logger.info("model:{}", model);
logger.info("path:{}", path);
logger.info("find collection by name:{}", path);
DataGridCollectionAndDataObject dataGridObj = null;
try {
dataGridObj = cs.findByName(path);
} catch (FileNotFoundException fnf) {
logger.warn("file not found for:{}", path);
// I don't have a path so use the user home
logger.info("no path, so using user home directory");
// TODO: refactor into something more elegant - mcc
model.addAttribute("invalidPath", path);
IRODSAccount irodsAccount = irodsServices.getCollectionAO().getIRODSAccount();
path = MiscIRODSUtils.buildIRODSUserHomeForAccountUsingDefaultScheme(irodsAccount);
}
if (path.endsWith("/") && path.compareTo("/") != 0) {
path = path.substring(0, path.length() - 1);
}
currentPath = path;
logger.info("currentPath:{}", currentPath);
DataGridUser user = loggedUserUtils.getLoggedDataGridUser();
if (zoneTrashPath == null || zoneTrashPath.isEmpty()) {
zoneTrashPath = String.format("/%s/trash", irodsServices.getCurrentUserZone());
}
// TODO: do I really need these permission path checks? I can let iRODS worry
// about permissions - mcc
CollectionOrDataObjectForm collectionForm = new CollectionOrDataObjectForm();
String permissionType = "none";
if (dataGridObj.isProxy()) {
logger.info("this is a proxy, so fake out the options");
collectionForm.setInheritOption(false);
permissionType = "read";
} else {
logger.info("this is not a proxy, so gather permission info");
permissionType = cs.getPermissionsForPath(path);
collectionForm.setInheritOption(cs.getInheritanceOptionForCollection(currentPath));
permissionsService.resolveMostPermissiveAccessForUser(dataGridObj, user);
}
logger.debug("permission options are set");
boolean isPermissionOwn = "own".equals(permissionType);
boolean isTrash = path.contains(zoneTrashPath) && (isPermissionOwn || user.isAdmin());
boolean inheritanceDisabled = !isPermissionOwn && collectionForm.getInheritOption();
model.addAttribute("collectionAndDataObject", dataGridObj);
model.addAttribute("isTrash", isTrash);
model.addAttribute("permissionType", permissionType);
model.addAttribute("currentPath", currentPath);
model.addAttribute("encodedCurrentPath", URLEncoder.encode(currentPath));
model.addAttribute("isCurrentPathCollection", cs.isCollection(path));
model.addAttribute("user", user);
model.addAttribute("trashColl", cs.getTrashForPath(currentPath));
model.addAttribute("collection", collectionForm);
model.addAttribute("inheritanceDisabled", inheritanceDisabled);
model.addAttribute("requestMapping", "/browse/add/action/");
model.addAttribute("parentPath", parentPath);
setBreadcrumbToModel(model, dataGridObj);
logger.info("forwarding to collections/collectionsBrowser");
return "collections/collectionsBrowser";
}
use of org.irods.jargon.core.connection.IRODSAccount in project metalnx-web by irods-contrib.
the class SpecQueryServiceImplTest method testCountCollectionsMatchingMetadata.
@Test
public void testCountCollectionsMatchingMetadata() throws Exception {
SpecQueryServiceImpl specQueryService = new SpecQueryServiceImpl();
IRODSServices irodsService = Mockito.mock(IRODSServices.class);
AdminServices adminServices = Mockito.mock(AdminServices.class);
IRODSAccount irodsAccount = testingPropertiesHelper.buildIRODSAccountFromTestProperties(testingProperties);
EnvironmentalInfoAO environmentalInfoAO = irodsFileSystem.getIRODSAccessObjectFactory().getEnvironmentalInfoAO(irodsAccount);
SpecificQueryAO specificQueryAO = irodsFileSystem.getIRODSAccessObjectFactory().getSpecificQueryAO(irodsAccount);
Mockito.when(irodsService.getEnvironmentalInfoAO()).thenReturn(environmentalInfoAO);
Mockito.when(adminServices.getSpecificQueryAO()).thenReturn(specificQueryAO);
specQueryService.setIrodsServices(irodsService);
specQueryService.setAdminServices(adminServices);
List<DataGridMetadataSearch> metadataSearch = new ArrayList<DataGridMetadataSearch>();
DataGridMetadataSearch search = new DataGridMetadataSearch(COLL_AVU_ATTR1, COLL_AVU_VAL1, "", DataGridSearchOperatorEnum.EQUAL);
metadataSearch.add(search);
int count = specQueryService.countCollectionsMatchingMetadata(metadataSearch, irodsAccount.getZone());
Assert.assertTrue("no recs returned", count > 1);
}
Aggregations