Search in sources :

Example 6 with Role

use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.

the class RMv22RemoveInPlaceRolesFromAllPatchUnitTest method getMockedRole.

/**
 * Helper method to create a mocked role.
 */
private Role getMockedRole(String name) {
    Role mockedRole = mock(Role.class);
    doReturn(name).when(mockedRole).getRoleGroupName();
    return mockedRole;
}
Also used : Role(org.alfresco.module.org_alfresco_module_rm.role.Role)

Example 7 with Role

use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.

the class NotificationServiceHelperSystemTest method setupTestData.

@Override
protected void setupTestData() {
    super.setupTestData();
    retryingTransactionHelper.doInTransaction(new RetryingTransactionCallback<Object>() {

        @Override
        public Object execute() throws Throwable {
            AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
            // Create a user
            userName = GUID.generate();
            authenticationService.createAuthentication(userName, "".toCharArray());
            PropertyMap props = new PropertyMap();
            props.put(PROP_USERNAME, userName);
            props.put(PROP_FIRSTNAME, "Test");
            props.put(PROP_LASTNAME, "User");
            props.put(PROP_EMAIL, EMAIL_ADDRESS);
            person = personService.createPerson(props);
            // Find the authority for the given role
            Role role = filePlanRoleService.getRole(filePlan, NOTIFICATION_ROLE);
            assertNotNull("Notification role could not be retrieved", role);
            String roleGroup = role.getRoleGroupName();
            assertNotNull("Notification role group can not be null.", roleGroup);
            // Add user to notification role group
            authorityService.addAuthority(roleGroup, userName);
            return null;
        }
    });
}
Also used : Role(org.alfresco.module.org_alfresco_module_rm.role.Role) PropertyMap(org.alfresco.util.PropertyMap)

Example 8 with Role

use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.

the class UserAndGroupsUtils method addUserToRole.

/**
 * Add a user to an RM role
 *
 * @param userName the username of the user to add to the role
 * @param role the role to add the user to
 */
public void addUserToRole(NodeRef filePlan, String userName, RMRole role) {
    // Find the authority for the given role
    Role roleObj = filePlanRoleService.getRole(filePlan, role.getGroupName());
    assertNotNull("Notification role " + role.getGroupName() + " could not be retrieved", roleObj);
    String roleGroup = roleObj.getRoleGroupName();
    assertNotNull("Notification role group " + roleGroup + " can not be null.", roleGroup);
    // Add user to notification role group
    authorityService.addAuthority(roleGroup, userName);
}
Also used : Role(org.alfresco.module.org_alfresco_module_rm.role.Role)

Example 9 with Role

use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.

the class DataSetServiceImpl method patchLoadedData.

/**
 * Temp method to patch AMP'ed data
 */
private void patchLoadedData() {
    AuthenticationUtil.RunAsWork<Object> runAsWork = new AuthenticationUtil.RunAsWork<Object>() {

        public Object doWork() {
            Set<NodeRef> rmRoots = filePlanService.getFilePlans();
            logger.info("Bootstraping " + rmRoots.size() + " rm roots ...");
            for (NodeRef rmRoot : rmRoots) {
                if (permissionService.getInheritParentPermissions(rmRoot)) {
                    logger.info("Updating permissions for rm root: " + rmRoot);
                    permissionService.setInheritParentPermissions(rmRoot, false);
                }
                String allRoleShortName = RMAuthority.ALL_ROLES_PREFIX + rmRoot.getId();
                String allRoleGroupName = authorityService.getName(AuthorityType.GROUP, allRoleShortName);
                if (!authorityService.authorityExists(allRoleGroupName)) {
                    logger.info("Creating all roles group for root node: " + rmRoot.toString());
                    // Create "all" role group for root node
                    String allRoles = authorityService.createAuthority(AuthorityType.GROUP, allRoleShortName, RMAuthority.ALL_ROLES_DISPLAY_NAME, new HashSet<String>(Arrays.asList(RMAuthority.ZONE_APP_RM)));
                    // Put all the role groups in it
                    Set<Role> roles = filePlanRoleService.getRoles(rmRoot);
                    for (Role role : roles) {
                        logger.info("   - adding role group " + role.getRoleGroupName() + " to all roles group");
                        authorityService.addAuthority(allRoles, role.getRoleGroupName());
                    }
                    // Set the permissions
                    permissionService.setPermission(rmRoot, allRoles, RMPermissionModel.READ_RECORDS, true);
                }
            }
            // Make sure all the containers do not inherit permissions
            ResultSet rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_FTS_ALFRESCO, "TYPE:\"rma:recordsManagementContainer\"");
            try {
                logger.info("Bootstraping " + rs.length() + " record containers ...");
                for (NodeRef container : rs.getNodeRefs()) {
                    String containerName = (String) nodeService.getProperty(container, ContentModel.PROP_NAME);
                    // Set permissions
                    if (permissionService.getInheritParentPermissions(container)) {
                        logger.info("Updating permissions for record container: " + containerName);
                        permissionService.setInheritParentPermissions(container, false);
                    }
                }
            } finally {
                rs.close();
            }
            // fix up the test dataset to fire initial events for
            // disposition
            // schedules
            rs = searchService.query(SPACES_STORE, SearchService.LANGUAGE_FTS_ALFRESCO, "TYPE:\"rma:recordFolder\"");
            try {
                logger.info("Bootstraping " + rs.length() + " record folders ...");
                for (NodeRef recordFolder : rs.getNodeRefs()) {
                    String folderName = (String) nodeService.getProperty(recordFolder, ContentModel.PROP_NAME);
                    // Set permissions
                    if (permissionService.getInheritParentPermissions(recordFolder)) {
                        logger.info("Updating permissions for record folder: " + folderName);
                        permissionService.setInheritParentPermissions(recordFolder, false);
                    }
                    if (!nodeService.hasAspect(recordFolder, ASPECT_DISPOSITION_LIFECYCLE)) {
                        // See if the folder has a disposition schedule that
                        // needs
                        // to be applied
                        DispositionSchedule ds = dispositionService.getDispositionSchedule(recordFolder);
                        if (ds != null) {
                            // Fire action to "set-up" the folder correctly
                            logger.info("Setting up bootstraped record folder: " + folderName);
                            recordFolderService.setupRecordFolder(recordFolder);
                        }
                    }
                    // fixup the search behaviour aspect for the record
                    // folder
                    logger.info("Setting up search aspect for record folder: " + folderName);
                    recordsManagementSearchBehaviour.fixupSearchAspect(recordFolder);
                }
            } finally {
                rs.close();
            }
            return null;
        }
    };
    AuthenticationUtil.runAs(runAsWork, AuthenticationUtil.getAdminUserName());
}
Also used : Role(org.alfresco.module.org_alfresco_module_rm.role.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) AuthenticationUtil(org.alfresco.repo.security.authentication.AuthenticationUtil) ResultSet(org.alfresco.service.cmr.search.ResultSet) DispositionSchedule(org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule)

Example 10 with Role

use of org.alfresco.module.org_alfresco_module_rm.role.Role in project records-management by Alfresco.

the class RmRolesGet method executeImpl.

/**
 * @see org.springframework.extensions.webscripts.DeclarativeWebScript#executeImpl(org.springframework.extensions.webscripts.WebScriptRequest, org.springframework.extensions.webscripts.Status, org.springframework.extensions.webscripts.Cache)
 */
@Override
public Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    Set<Role> roles = null;
    // get the file plan
    NodeRef filePlan = getFilePlan(req);
    if (filePlan == null) {
        throw new WebScriptException(Status.STATUS_FOUND, "File plan does not exist.");
    }
    // get the includesystem parameter
    boolean includeSystem = false;
    String includeSystemValue = req.getParameter("is");
    if (includeSystemValue != null && includeSystemValue.length() != 0) {
        includeSystem = Boolean.parseBoolean(includeSystemValue);
    }
    // get the user filter
    String user = req.getParameter("user");
    if (user != null && user.length() != 0) {
        roles = filePlanRoleService.getRolesByUser(filePlan, user, includeSystem);
    } else {
        roles = filePlanRoleService.getRoles(filePlan, includeSystem);
    }
    // get the auths parameter
    boolean showAuths = false;
    String auths = req.getParameter("auths");
    if (auths != null && auths.length() != 0) {
        showAuths = Boolean.parseBoolean(auths);
    }
    Set<RoleItem> items = createRoleItems(filePlan, roles, showAuths);
    model.put("roles", items);
    return model;
}
Also used : Role(org.alfresco.module.org_alfresco_module_rm.role.Role) NodeRef(org.alfresco.service.cmr.repository.NodeRef) WebScriptException(org.springframework.extensions.webscripts.WebScriptException) HashMap(java.util.HashMap)

Aggregations

Role (org.alfresco.module.org_alfresco_module_rm.role.Role)15 NodeRef (org.alfresco.service.cmr.repository.NodeRef)10 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 Capability (org.alfresco.module.org_alfresco_module_rm.capability.Capability)4 WebScriptException (org.springframework.extensions.webscripts.WebScriptException)3 IOException (java.io.IOException)2 JSONArray (org.json.JSONArray)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 JSONTokener (org.json.JSONTokener)2 Serializable (java.io.Serializable)1 AlfrescoRuntimeException (org.alfresco.error.AlfrescoRuntimeException)1 DispositionSchedule (org.alfresco.module.org_alfresco_module_rm.disposition.DispositionSchedule)1 FilePlanComponentKind (org.alfresco.module.org_alfresco_module_rm.fileplan.FilePlanComponentKind)1 AuthenticationUtil (org.alfresco.repo.security.authentication.AuthenticationUtil)1 Period (org.alfresco.service.cmr.repository.Period)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 AccessPermission (org.alfresco.service.cmr.security.AccessPermission)1 AccessStatus (org.alfresco.service.cmr.security.AccessStatus)1