Search in sources :

Example 1 with IRODSAccount

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());
    }
}
Also used : DataProfile(org.irods.jargon.extensions.dataprofiler.DataProfile) DataGridException(com.emc.metalnx.core.domain.exceptions.DataGridException) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) JargonException(org.irods.jargon.core.exception.JargonException) DataProfilerService(org.irods.jargon.extensions.dataprofiler.DataProfilerService)

Example 2 with IRODSAccount

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);
}
Also used : UserTokenDetails(com.emc.metalnx.services.auth.UserTokenDetails) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) Authentication(org.springframework.security.core.Authentication) TestTicketUtils(com.emc.metalnx.services.tests.tickets.TestTicketUtils) SecurityContext(org.springframework.security.core.context.SecurityContext) Before(org.junit.Before)

Example 3 with IRODSAccount

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);
}
Also used : IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) File(java.io.File) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 4 with IRODSAccount

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";
}
Also used : IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) DataGridUser(com.emc.metalnx.core.domain.entity.DataGridUser) DataGridCollectionAndDataObject(com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject) FileNotFoundException(org.irods.jargon.core.exception.FileNotFoundException) CollectionOrDataObjectForm(com.emc.metalnx.modelattribute.collection.CollectionOrDataObjectForm)

Example 5 with IRODSAccount

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);
}
Also used : EnvironmentalInfoAO(org.irods.jargon.core.pub.EnvironmentalInfoAO) AdminServices(com.emc.metalnx.services.interfaces.AdminServices) DataGridMetadataSearch(com.emc.metalnx.core.domain.entity.DataGridMetadataSearch) IRODSAccount(org.irods.jargon.core.connection.IRODSAccount) ArrayList(java.util.ArrayList) IRODSServices(com.emc.metalnx.services.interfaces.IRODSServices) SpecificQueryAO(org.irods.jargon.core.pub.SpecificQueryAO) Test(org.junit.Test)

Aggregations

IRODSAccount (org.irods.jargon.core.connection.IRODSAccount)19 Test (org.junit.Test)10 AdminServices (com.emc.metalnx.services.interfaces.AdminServices)9 IRODSServices (com.emc.metalnx.services.interfaces.IRODSServices)9 EnvironmentalInfoAO (org.irods.jargon.core.pub.EnvironmentalInfoAO)9 SpecificQueryAO (org.irods.jargon.core.pub.SpecificQueryAO)9 ArrayList (java.util.ArrayList)8 DataGridFilePropertySearch (com.emc.metalnx.core.domain.entity.DataGridFilePropertySearch)4 DataGridMetadataSearch (com.emc.metalnx.core.domain.entity.DataGridMetadataSearch)4 SpecificQueryResultSet (org.irods.jargon.core.query.SpecificQueryResultSet)4 DataGridCollectionAndDataObject (com.emc.metalnx.core.domain.entity.DataGridCollectionAndDataObject)3 File (java.io.File)3 DataGridException (com.emc.metalnx.core.domain.exceptions.DataGridException)2 AuthResponse (org.irods.jargon.core.connection.auth.AuthResponse)2 JargonException (org.irods.jargon.core.exception.JargonException)2 DataTransferOperations (org.irods.jargon.core.pub.DataTransferOperations)2 IRODSFile (org.irods.jargon.core.pub.io.IRODSFile)2 IRODSFileFactory (org.irods.jargon.core.pub.io.IRODSFileFactory)2 IRODSTestSetupUtilities (org.irods.jargon.testutils.IRODSTestSetupUtilities)2 TestingPropertiesHelper (org.irods.jargon.testutils.TestingPropertiesHelper)2