private JSONObject getPreferencesObject(String userName) throws JSONException { JSONObject jsonPrefs = null; // Get the user node reference NodeRef personNodeRef = this.personService.getPerson(userName); if (personNodeRef == null) { throw new AlfrescoRuntimeException( "Cannot get preferences for " + userName + " because he/she does not exist."); } String currentUserName = AuthenticationUtil.getFullyAuthenticatedUser(); boolean isSystem = AuthenticationUtil.isRunAsUserTheSystemUser() || authenticationContext.isSystemUserName(currentUserName); if (isSystem || userName.equals(currentUserName) || personService .getUserIdentifier(userName) .equals(personService.getUserIdentifier(currentUserName)) || authorityService.isAdminAuthority(currentUserName)) { // Check for preferences aspect if (this.nodeService.hasAspect(personNodeRef, ContentModel.ASPECT_PREFERENCES) == true) { // Get the preferences for this user ContentReader reader = this.contentService.getReader(personNodeRef, ContentModel.PROP_PREFERENCE_VALUES); if (reader != null) { jsonPrefs = new JSONObject(reader.getContentString()); } } } else { // The current user does not have sufficient permissions to get // the preferences for this user throw new AccessDeniedException( "The current user " + currentUserName + " does not have sufficient permissions to get the preferences of the user " + userName); } return jsonPrefs; }
public void traiteGroupAgentSHD(Integer idAgent, String nameFolderAgent) { List<PersonInfo> listPersonSHD = new ArrayList<PersonInfo>(); List<Integer> listeSuperieurHierarchique = sirhWsConsumer.getListSuperieurOfAgent(idAgent); String groupSHD = PREFIXE_GROUP + nameFolderAgent + SHD; for (Integer idSup : listeSuperieurHierarchique) { if (null != idSup) { PersonInfo personSHD = alfrescoUtilsService.getPersonInfoByIdAgent(idSup); // AJOUT if (null != personSHD) { Set<String> listGroup = authorityService.getAuthoritiesForUser(personSHD.getUserName()); if (!alfrescoUtilsService.isExistGroupForUser(listGroup, groupSHD) && authorityService.authorityExists(personSHD.getUserName())) { authorityService.addAuthority(groupSHD, personSHD.getUserName()); if (!listPersonSHD.contains(personSHD)) { listPersonSHD.add(personSHD); } logger.debug("User " + personSHD.getUserName() + " adding in Group " + groupSHD); } else if (alfrescoUtilsService.isExistGroupForUser(listGroup, groupSHD) && authorityService.authorityExists(personSHD.getUserName())) { if (!listPersonSHD.contains(personSHD)) { listPersonSHD.add(personSHD); } logger.debug("User " + personSHD.getUserName() + " existing in Group " + groupSHD); } } } } // SUPPRESSION Set<String> listUsersGoupSHD = authorityService.getContainedAuthorities(AuthorityType.USER, groupSHD, true); if (null != listUsersGoupSHD) { for (String userGroupSHD : listUsersGoupSHD) { if (!alfrescoUtilsService.isExistUserInListPersonInfo(listPersonSHD, userGroupSHD)) { authorityService.removeAuthority(groupSHD, userGroupSHD); logger.debug("User " + userGroupSHD + " deleted in Group " + groupSHD); } } } }