Search in sources :

Example 1 with DvObject

use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.

the class ReturnDatasetToAuthorCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    HttpServletRequest aHttpServletRequest = null;
    dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public AuthenticationServiceBean authentication() {
            return new AuthenticationServiceBean() {

                @Override
                public AuthenticatedUser getAuthenticatedUser(String id) {
                    return MocksFactory.makeAuthenticatedUser("First", "Last");
                }
            };
        }

        @Override
        public IndexServiceBean index() {
            return new IndexServiceBean() {

                @Override
                public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
                    return null;
                }
            };
        }

        @Override
        public EntityManager em() {
            return new NoOpTestEntityManager();
        }

        @Override
        public DatasetServiceBean datasets() {
            return new DatasetServiceBean() {

                {
                    em = new NoOpTestEntityManager();
                }

                @Override
                public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
                    return null;
                }

                @Override
                public WorkflowComment addWorkflowComment(WorkflowComment comment) {
                    return comment;
                }

                @Override
                public void removeDatasetLocks(Long datasetId, DatasetLock.Reason aReason) {
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public PermissionServiceBean permissions() {
            return new PermissionServiceBean() {

                @Override
                public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
                    // We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
                    return Collections.emptyList();
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) PermissionServiceBean(edu.harvard.iq.dataverse.PermissionServiceBean) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) WorkflowComment(edu.harvard.iq.dataverse.workflows.WorkflowComment) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) AuthenticationServiceBean(edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) Permission(edu.harvard.iq.dataverse.authorization.Permission) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Example 2 with DvObject

use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.

the class GroupServiceBean method groupTransitiveClosure.

/**
 * Given a set of groups and a DV object, return all the groups that are
 * reachable from the set. Effectively, if the initial set has an {@link ExplicitGroup},
 * recursively add all the groups it contains.
 *
 * @param groups
 * @param dvo
 * @return All the groups included in the groups in {@code groups}.
 */
private Set<Group> groupTransitiveClosure(Set<Group> groups, DvObject dvo) {
    // now, get the explicit group transitive closure.
    Set<ExplicitGroup> perimeter = new HashSet<>();
    Set<ExplicitGroup> visited = new HashSet<>();
    groups.stream().filter((g) -> (g instanceof ExplicitGroup)).forEachOrdered((g) -> perimeter.add((ExplicitGroup) g));
    visited.addAll(perimeter);
    while (!perimeter.isEmpty()) {
        ExplicitGroup g = perimeter.iterator().next();
        perimeter.remove(g);
        groups.add(g);
        Set<ExplicitGroup> discovered = explicitGroupProvider.groupsFor(g, dvo);
        // Ideally the conjunction is always empty, as we don't allow cycles.
        discovered.removeAll(visited);
        // Still, coding defensively here, in case someone gets too
        // smart on the SQL console.
        perimeter.addAll(discovered);
        visited.addAll(discovered);
    }
    return groups;
}
Also used : AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) ExplicitGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupProvider) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) HashMap(java.util.HashMap) Level(java.util.logging.Level) HashSet(java.util.HashSet) Map(java.util.Map) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) DvObject(edu.harvard.iq.dataverse.DvObject) Named(javax.inject.Named) Collectors.toSet(java.util.stream.Collectors.toSet) EJB(javax.ejb.EJB) Stateless(javax.ejb.Stateless) IpGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupProvider) ShibGroupServiceBean(edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupServiceBean) BuiltInGroupsProvider(edu.harvard.iq.dataverse.authorization.groups.impl.builtin.BuiltInGroupsProvider) Collection(java.util.Collection) Set(java.util.Set) Logger(java.util.logging.Logger) Stream(java.util.stream.Stream) ExplicitGroupServiceBean(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroupServiceBean) PostConstruct(javax.annotation.PostConstruct) IpGroupsServiceBean(edu.harvard.iq.dataverse.authorization.groups.impl.ipaddress.IpGroupsServiceBean) ShibGroupProvider(edu.harvard.iq.dataverse.authorization.groups.impl.shib.ShibGroupProvider) RoleAssigneeServiceBean(edu.harvard.iq.dataverse.RoleAssigneeServiceBean) ExplicitGroup(edu.harvard.iq.dataverse.authorization.groups.impl.explicit.ExplicitGroup) HashSet(java.util.HashSet)

Example 3 with DvObject

use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.

the class IndexAsync method indexRoles.

@Asynchronous
public void indexRoles(Collection<DvObject> dvObjects) {
    for (DvObject dvObject : dvObjects) {
        IndexResponse indexResponse = solrIndexService.indexPermissionsOnSelfAndChildren(dvObject);
        logger.fine("output from permission indexing operations (dvobject " + dvObject.getId() + ": " + indexResponse);
    }
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Asynchronous(javax.ejb.Asynchronous)

Example 4 with DvObject

use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.

the class Index method searchPermsDebug.

/**
 * This method is for integration tests of search.
 */
@GET
@Path("permsDebug")
public Response searchPermsDebug(@QueryParam("key") String apiToken, @QueryParam("id") Long dvObjectId) {
    User user = findUserByApiToken(apiToken);
    if (user == null) {
        return error(Response.Status.UNAUTHORIZED, "Invalid apikey '" + apiToken + "'");
    }
    DvObject dvObjectToLookUp = dvObjectService.findDvObject(dvObjectId);
    if (dvObjectToLookUp == null) {
        return error(Status.BAD_REQUEST, "Could not find DvObject based on id " + dvObjectId);
    }
    List<DvObjectSolrDoc> solrDocs = SolrIndexService.determineSolrDocs(dvObjectToLookUp);
    JsonObjectBuilder data = Json.createObjectBuilder();
    JsonArrayBuilder permissionsData = Json.createArrayBuilder();
    for (DvObjectSolrDoc solrDoc : solrDocs) {
        JsonObjectBuilder dataDoc = Json.createObjectBuilder();
        dataDoc.add(SearchFields.ID, solrDoc.getSolrId());
        dataDoc.add(SearchFields.NAME_SORT, solrDoc.getNameOrTitle());
        JsonArrayBuilder perms = Json.createArrayBuilder();
        for (String perm : solrDoc.getPermissions()) {
            perms.add(perm);
        }
        dataDoc.add(SearchFields.DISCOVERABLE_BY, perms);
        permissionsData.add(dataDoc);
    }
    data.add("perms", permissionsData);
    DvObject dvObject = dvObjectService.findDvObject(dvObjectId);
    NullSafeJsonBuilder timestamps = jsonObjectBuilder();
    timestamps.add(contentChanged, SearchUtil.getTimestampOrNull(dvObject.getModificationTime()));
    timestamps.add(contentIndexed, SearchUtil.getTimestampOrNull(dvObject.getIndexTime()));
    timestamps.add(permsChanged, SearchUtil.getTimestampOrNull(dvObject.getPermissionModificationTime()));
    timestamps.add(permsIndexed, SearchUtil.getTimestampOrNull(dvObject.getPermissionIndexTime()));
    Set<RoleAssignment> roleAssignments = rolesSvc.rolesAssignments(dvObject);
    JsonArrayBuilder roleAssignmentsData = Json.createArrayBuilder();
    for (RoleAssignment roleAssignment : roleAssignments) {
        roleAssignmentsData.add(roleAssignment.getRole() + " has been granted to " + roleAssignment.getAssigneeIdentifier() + " on " + roleAssignment.getDefinitionPoint());
    }
    data.add("timestamps", timestamps);
    data.add("roleAssignments", roleAssignmentsData);
    return ok(data);
}
Also used : DvObjectSolrDoc(edu.harvard.iq.dataverse.search.DvObjectSolrDoc) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) GuestUser(edu.harvard.iq.dataverse.authorization.users.GuestUser) DvObject(edu.harvard.iq.dataverse.DvObject) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) JsonArrayBuilder(javax.json.JsonArrayBuilder) NullSafeJsonBuilder(edu.harvard.iq.dataverse.util.json.NullSafeJsonBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with DvObject

use of edu.harvard.iq.dataverse.DvObject in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser.

@Test
public void testGetPrivateUrlUserFromRoleAssignmentAndAssigneeNonPrivateUrlUser() {
    DataverseRole aRole = null;
    RoleAssignee assignee = GuestUser.get();
    DvObject dataset = new Dataset();
    String privateUrlToken = "cd71e9d7-73a7-4ec8-b890-3d00499e8693";
    RoleAssignment assignment = new RoleAssignment(aRole, assignee, dataset, privateUrlToken);
    PrivateUrlUser privateUrl = PrivateUrlUtil.getPrivateUrlUserFromRoleAssignment(assignment, assignee);
    assertNull(privateUrl);
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Aggregations

DvObject (edu.harvard.iq.dataverse.DvObject)32 Dataset (edu.harvard.iq.dataverse.Dataset)16 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)14 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)12 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)12 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 Dataverse (edu.harvard.iq.dataverse.Dataverse)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)7 IOException (java.io.IOException)6 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)5 DataFile (edu.harvard.iq.dataverse.DataFile)4 DatasetVersionUser (edu.harvard.iq.dataverse.DatasetVersionUser)4 Permission (edu.harvard.iq.dataverse.authorization.Permission)4 User (edu.harvard.iq.dataverse.authorization.users.User)4 Timestamp (java.sql.Timestamp)4 HashMap (java.util.HashMap)4 DatasetField (edu.harvard.iq.dataverse.DatasetField)3