Java Code Examples for org.alfresco.repo.tenant.TenantUtil#runAsSystemTenant()
The following examples show how to use
org.alfresco.repo.tenant.TenantUtil#runAsSystemTenant() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RepoService.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
public FavouriteFolder getFolder(String networkId, final NodeRef nodeRef) { return TenantUtil.runAsSystemTenant(new TenantRunAsWork<FavouriteFolder>() { @Override public FavouriteFolder doWork() throws Exception { FavouriteFolder folder = null; QName type = nodeService.getType(nodeRef); if(dictionaryService.isSubClass(type, ContentModel.TYPE_FOLDER)) { Properties properties = getProperties(nodeRef); folder = FavouriteFolder.getFolder(nodeRef.getId(), nodeRef.getId(), properties); } else { throw new IllegalArgumentException("Not a folder node"); } return folder; } }, networkId); }
Example 2
Source File: AuthenticationTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * Test for ALF-20680 * Test of the {@link RepositoryAuthenticationDao#getUserFolderLocation(String)} in multitenancy */ public void testAuthenticateMultiTenant() { // Create a tenant domain TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Object>() { public Object doWork() throws Exception { if (!tenantAdminService.existsTenant(TEST_TENANT_DOMAIN)) { tenantAdminService.createTenant(TEST_TENANT_DOMAIN, TENANT_ADMIN_PW.toCharArray(), null); } return null; } }, TenantService.DEFAULT_DOMAIN); // Use default admin authenticateMultiTenantWork(AuthenticationUtil.getAdminUserName(), DEFAULT_ADMIN_PW); // Use tenant admin authenticateMultiTenantWork(AuthenticationUtil.getAdminUserName() + TenantService.SEPARATOR + TEST_TENANT_DOMAIN, TENANT_ADMIN_PW); }
Example 3
Source File: PublicApiAlfrescoCmisService.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
private RepositoryInfo getRepositoryInfo(final Network network) { final String networkId = network.getTenantDomain(); final String tenantDomain = (networkId.equals(TenantUtil.SYSTEM_TENANT) || networkId.equals(TenantUtil.DEFAULT_TENANT)) ? TenantService.DEFAULT_DOMAIN : networkId; return TenantUtil.runAsSystemTenant(new TenantRunAsWork<RepositoryInfo>() { public RepositoryInfo doWork() { RepositoryInfoImpl repoInfo = (RepositoryInfoImpl)connector.getRepositoryInfo(getContext().getCmisVersion()); repoInfo.setId(!networkId.equals("") ? networkId : TenantUtil.SYSTEM_TENANT); repoInfo.setName(tenantDomain); repoInfo.setDescription(tenantDomain); return repoInfo; } }, tenantDomain); }
Example 4
Source File: RepoService.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
public List<TestSite> getAllSites() { List<TestSite> sites = TenantUtil.runAsSystemTenant(new TenantRunAsWork<List<TestSite>>() { @Override public List<TestSite> doWork() throws Exception { List<SiteInfo> results = siteService.listSites(null, null); TreeMap<String, TestSite> ret = new TreeMap<String, TestSite>(); for(SiteInfo siteInfo : results) { TestSite site = new TestSite(TestNetwork.this, siteInfo/*, null*/); ret.put(site.getSiteId(), site); } return new ArrayList<TestSite>(ret.values()); } }, getId()); return sites; }
Example 5
Source File: QuickShareLinksImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 6 votes |
/** * Returns limited metadata regarding the shared (content) link. * <p> * Note: does *not* require authenticated access for (public) shared link. */ public QuickShareLink readById(final String sharedId, final Parameters parameters) { checkEnabled(); try { Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId); String networkTenantDomain = pair.getFirst(); return TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<QuickShareLink>() { public QuickShareLink doWork() throws Exception { // note: assume noAuth here (rather than rely on getRunAsUser which will be null in non-MT) return getQuickShareInfo(sharedId, true, parameters.getInclude()); } }, networkTenantDomain); } catch (InvalidSharedIdException ex) { logger.warn("Unable to find: " + sharedId); throw new EntityNotFoundException(sharedId); } }
Example 6
Source File: SiteServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 6 votes |
/** * @see org.alfresco.service.cmr.site.SiteService#listSites(java.lang.String, int) */ public List<SiteInfo> listSites(final String userName, final int size) { // MT share - for activity service remote system callback (deprecated) if (tenantService.isEnabled() && TenantUtil.isCurrentDomainDefault() && (AuthenticationUtil.SYSTEM_USER_NAME.equals(AuthenticationUtil.getRunAsUser())) && tenantService.isTenantUser(userName)) { final String tenantDomain = tenantService.getUserDomain(userName); return TenantUtil.runAsSystemTenant(new TenantRunAsWork<List<SiteInfo>>() { public List<SiteInfo> doWork() throws Exception { return listSitesImpl(userName, size); } }, tenantDomain); } else { return listSitesImpl(userName, size); } }
Example 7
Source File: LocalFeedTaskProcessor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Set<String> getSiteMembers(final RepoCtx ctx, String siteIdIn, final String tenantDomain) throws Exception { if (useRemoteCallbacks) { // as per 3.0, 3.1 return super.getSiteMembers(ctx, siteIdIn, tenantDomain); } else { final String siteId = tenantService.getBaseName(siteIdIn, true); // optimise for non-remote implementation - override remote repo callback (to "List Site Memberships" web script) with embedded call return TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Set<String>>() { public Set<String> doWork() throws Exception { Set<String> members = new HashSet<String>(); if ((siteId != null) && (siteId.length() != 0)) { Map<String, String> mapResult = siteService.listMembers(siteId, null, null, 0, true); if ((mapResult != null) && (mapResult.size() != 0)) { for (String userName : mapResult.keySet()) { if (!ctx.isUserNamesAreCaseSensitive()) { userName = userName.toLowerCase(); } members.add(userName); } } } return members; } }, tenantDomain); } }
Example 8
Source File: LocalFeedTaskProcessor.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
protected Set<String> getFollowers(final String userId, String tenantDomain) throws Exception { if (useRemoteCallbacks) { // note: not implemented throw new UnsupportedOperationException("Not implemented"); } final Set<String> result = new HashSet<String>(); if (subscriptionService.isActive()) { TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Void>() { public Void doWork() throws Exception { PagingFollowingResults fr = subscriptionService.getFollowers(userId, new PagingRequest(1000000, null)); if (fr.getPage() != null) { result.addAll(fr.getPage()); } return null; } }, tenantDomain); } return result; }
Example 9
Source File: RepoService.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
public TestSite getSiteNonMember(final String personId) { return TenantUtil.runAsSystemTenant(new TenantRunAsWork<TestSite>() { @Override public TestSite doWork() throws Exception { TestSite ret = null; SiteInfo match = null; for(SiteInfo info : siteService.listSites(null, null)) { boolean isMember = siteService.isMember(info.getShortName(), personId); if(!isMember) { match = info; break; } } if(match != null) { ret = new TestSite(TestNetwork.this, match); } return ret; } }, getId()); }
Example 10
Source File: HomeFolderProviderSynchronizerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
private Set<NodeRef> deleteNonAdminGuestUsers() { final Set<NodeRef> adminGuestUserHomeFolders = new HashSet<NodeRef>(); for (final NodeRef nodeRef : personService.getAllPeople()) { final String username = DefaultTypeConverter.INSTANCE.convert(String.class, nodeService.getProperty(nodeRef, ContentModel.PROP_USERNAME)); final String domainUsername = tenantService.getBaseNameUser(username); String tenantDomain = tenantService.getUserDomain(username); boolean disabled = !TenantService.DEFAULT_DOMAIN.equals(tenantDomain) && !tenantAdminService.isEnabledTenant(tenantDomain); try { if (disabled) { tenantAdminService.enableTenant(tenantDomain); } TenantUtil.runAsSystemTenant(new TenantRunAsWork<Object>() { public Object doWork() throws Exception { deleteUser(adminGuestUserHomeFolders, nodeRef, username, domainUsername); return null; } }, tenantDomain); } finally { if (disabled) { tenantAdminService.disableTenant(tenantDomain); } } } return adminGuestUserHomeFolders; }
Example 11
Source File: InviteResponse.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status) { String tenantDomain = TenantService.DEFAULT_DOMAIN; final String inviteeUserName = req.getParameter(PARAM_INVITEE_USER_NAME); if (tenantService.isEnabled()) { if (inviteeUserName != null) { tenantDomain = tenantService.getUserDomain(inviteeUserName); } } // run as system user return TenantUtil.runAsSystemTenant(new TenantRunAsWork<Map<String, Object>>() { public Map<String, Object> doWork() throws Exception { String oldUser = null; try { if (inviteeUserName != null && !inviteeUserName.equals(oldUser)) { oldUser = AuthenticationUtil.getFullyAuthenticatedUser(); AuthenticationUtil.setFullyAuthenticatedUser(inviteeUserName); } return execute(req, status); } finally { if (oldUser != null && !oldUser.equals(inviteeUserName)) { AuthenticationUtil.setFullyAuthenticatedUser(oldUser); } } } }, tenantDomain); }
Example 12
Source File: QuickShareServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
@Override public Map<String, Object> getMetaData(String sharedId) { checkEnabled(); Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(sharedId); final String tenantDomain = pair.getFirst(); final NodeRef nodeRef = pair.getSecond(); Map<String, Object> model = TenantUtil.runAsSystemTenant(new TenantRunAsWork<Map<String, Object>>() { public Map<String, Object> doWork() throws Exception { checkQuickShareNode(nodeRef); return getMetaData(nodeRef); } }, tenantDomain); if (logger.isDebugEnabled()) { logger.debug("QuickShare - retrieved metadata: "+sharedId+" ["+nodeRef+"]["+model+"]"); } //model.put("nodeRef", nodeRef) return model; }
Example 13
Source File: AuthenticationTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Tests creating a user with a Hashed password */ public void testCreateUserWithHashedPassword() throws Exception { String SOME_PASSWORD = "1 passw0rd"; String defaultencoding = compositePasswordEncoder.getPreferredEncoding(); String user1 = "uzer"+GUID.generate(); String user2 = "uzer"+GUID.generate(); List<String> encs = Arrays.asList("bcrypt10", "md4"); final String myTestDomain = TEST_TENANT_DOMAIN+"my.test"; TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Object>() { public Object doWork() throws Exception { if (!tenantAdminService.existsTenant(myTestDomain)) { tenantAdminService.createTenant(myTestDomain, TENANT_ADMIN_PW.toCharArray(), null); } return null; } }, TenantService.DEFAULT_DOMAIN); for (String enc : encs) { compositePasswordEncoder.setPreferredEncoding(enc); String hash = compositePasswordEncoder.encodePreferred(SOME_PASSWORD,null); assertCreateHashed(SOME_PASSWORD, hash, null, user1+ TenantService.SEPARATOR + myTestDomain); assertCreateHashed(SOME_PASSWORD, null, SOME_PASSWORD.toCharArray(), user2+ TenantService.SEPARATOR + myTestDomain); } compositePasswordEncoder.setPreferredEncoding(defaultencoding); }
Example 14
Source File: QuickShareContentGet.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void execute(final WebScriptRequest req, final WebScriptResponse res) throws IOException { if (! isEnabled()) { throw new WebScriptException(HttpServletResponse.SC_FORBIDDEN, "QuickShare is disabled system-wide"); } // create map of template vars (params) final Map<String, String> params = req.getServiceMatch().getTemplateVars(); final String sharedId = params.get("shared_id"); if (sharedId == null) { throw new WebScriptException(HttpServletResponse.SC_BAD_REQUEST, "A valid sharedId must be specified !"); } try { Pair<String, NodeRef> pair = quickShareSerivce.getTenantNodeRefFromSharedId(sharedId); final String tenantDomain = pair.getFirst(); final NodeRef nodeRef = pair.getSecond(); TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() { public Void doWork() throws Exception { if (! nodeService.getAspects(nodeRef).contains(QuickShareModel.ASPECT_QSHARE)) { throw new InvalidNodeRefException(nodeRef); } // MNT-21118 (XSS prevention) // Force the attachment in case of asking for the content file only // (will be overridden for thumbnails) executeImpl(nodeRef, params, req, res, null, true); return null; } }, tenantDomain); if (logger.isDebugEnabled()) { logger.debug("QuickShare - retrieved content: "+sharedId+" ["+nodeRef+"]"); } } catch (InvalidSharedIdException ex) { logger.error("Unable to find: "+sharedId); throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId); } catch (InvalidNodeRefException inre) { logger.error("Unable to find: "+sharedId+" ["+inre.getNodeRef()+"]"); throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND, "Unable to find: "+sharedId); } }
Example 15
Source File: HomeFolderProviderSynchronizerTest.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
private NodeRef createUser(String tenantDomain, final String parentPath, final String username, final String homeFolderProviderName, final boolean createHomeDirectory) throws Exception { final String domainUsername = tenantService.getDomainUser(username, tenantDomain); return TenantUtil.runAsSystemTenant(new TenantRunAsWork<NodeRef>() { public NodeRef doWork() throws Exception { String firstName = username; String lastName = "Smith"; String emailAddress = String.format("%s.%[email protected]", firstName, lastName); PropertyMap properties = new PropertyMap(); properties.put(ContentModel.PROP_USERNAME, domainUsername); properties.put(ContentModel.PROP_FIRSTNAME, firstName); properties.put(ContentModel.PROP_LASTNAME, lastName); properties.put(ContentModel.PROP_EMAIL, emailAddress); if (parentPath != null) { properties.put(ContentModel.PROP_HOME_FOLDER_PROVIDER, testHomeFolderProviderName); properties.put(PROP_PARENT_PATH, parentPath); } else { properties.put(ContentModel.PROP_HOME_FOLDER_PROVIDER, homeFolderProviderName); } personService.setHomeFolderCreationEager(createHomeDirectory); NodeRef person = personService.createPerson(properties); assertNotNull("The person nodeRef for "+domainUsername+" should have been created", person); NodeRef homeFolder = DefaultTypeConverter.INSTANCE.convert( NodeRef.class, nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER)); if (createHomeDirectory && parentPath != null) { assertNotNull("The homeFolder for "+domainUsername+" should have been created", homeFolder); } else { assertNull("The homeFolder for "+domainUsername+" should NOT have been created", homeFolder); } if (!testHomeFolderProviderName.equals(homeFolderProviderName)) { if (homeFolderProviderName == null) { nodeService.removeProperty(person, ContentModel.PROP_HOME_FOLDER_PROVIDER); } else { nodeService.setProperty(person, ContentModel.PROP_HOME_FOLDER_PROVIDER, homeFolderProviderName); } } return person; } }, tenantDomain); }
Example 16
Source File: UserUsageTrackingComponent.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
/** * Collapse usages - note: for MT environment, will collapse all tenants */ private void collapseUsages() { if (logger.isDebugEnabled()) { logger.debug("Collapse usages ..."); } // Collapse usage deltas (if a person has initial usage set) RetryingTransactionCallback<Set<NodeRef>> getUsageNodeRefs = new RetryingTransactionCallback<Set<NodeRef>>() { public Set<NodeRef> execute() throws Throwable { // Get distinct candidates return usageService.getUsageDeltaNodes(); } }; // execute in READ-ONLY txn Set<NodeRef> usageNodeRefs = transactionService.getRetryingTransactionHelper().doInTransaction(getUsageNodeRefs, true); int collapseCount = 0; for (final NodeRef usageNodeRef : usageNodeRefs) { Boolean collapsed = TenantUtil.runAsSystemTenant(new TenantRunAsWork<Boolean>() { public Boolean doWork() throws Exception { return collapseUsage(usageNodeRef); } }, tenantService.getDomain(usageNodeRef.getStoreRef().getIdentifier())); if (collapsed) { collapseCount++; } } if (logger.isDebugEnabled()) { logger.debug("... collapsed usages for " + collapseCount + " users"); } }
Example 17
Source File: QuickShareServiceImpl.java From alfresco-repository with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void unshareContent(final String sharedId) { Pair<String, NodeRef> pair = getTenantNodeRefFromSharedId(sharedId); final String tenantDomain = pair.getFirst(); final NodeRef nodeRef = pair.getSecond(); TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() { public Void doWork() throws Exception { QName typeQName = nodeService.getType(nodeRef); if (! isSharable(typeQName)) { throw new InvalidNodeRefException(nodeRef); } String nodeSharedId = (String)nodeService.getProperty(nodeRef, QuickShareModel.PROP_QSHARE_SHAREDID); if (! EqualsHelper.nullSafeEquals(nodeSharedId, sharedId)) { logger.warn("SharedId mismatch: expected="+sharedId+",actual="+nodeSharedId); } // Disable audit to preserve modifier and modified date // And not to create version // see MNT-15654 behaviourFilter.disableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE); try { nodeService.removeAspect(nodeRef, QuickShareModel.ASPECT_QSHARE); } finally { behaviourFilter.enableBehaviour(nodeRef, ContentModel.ASPECT_AUDITABLE); } return null; } }, tenantDomain); removeSharedId(sharedId); if (logger.isInfoEnabled()) { logger.info("QuickShare - unshared content: "+sharedId+" ["+nodeRef+"]"); } }
Example 18
Source File: TestPersonSites.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private void initializePersonAndNetwork4WithSites() throws Exception { if (network4 == null) { network4 = getRepoService().createNetwork(this.getClass().getSimpleName().toLowerCase() + "-3-" + GUID.generate(), true); network4.create(); // Create some users TenantUtil.runAsSystemTenant(new TenantRunAsWork<Void>() { @Override public Void doWork() throws Exception { person41 = network4.createUser(); person42 = network4.createUser(); return null; } }, network4.getId()); // ...and some sites TenantUtil.runAsUserTenant(new TenantRunAsWork<Void>() { @Override public Void doWork() throws Exception { site41 = network4.createSite("A", SiteVisibility.PRIVATE); site41.inviteToSite(person41.getId(), SiteRole.SiteContributor); site42 = network4.createSite("B", SiteVisibility.PUBLIC); site42.inviteToSite(person41.getId(), SiteRole.SiteContributor); site43 = network4.createSite("C", SiteVisibility.PUBLIC); site43.inviteToSite(person41.getId(), SiteRole.SiteContributor); site44 = network4.createSite("D", SiteVisibility.MODERATED); site44.inviteToSite(person41.getId(), SiteRole.SiteContributor); return null; } }, person42.getId(), network4.getId()); } }
Example 19
Source File: SharedLinkApiTest.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
private int getSchedules() { return TenantUtil.runAsSystemTenant(() -> scheduledPersistedActionService.listSchedules().size(), TenantUtil.getCurrentDomain()); }
Example 20
Source File: QuickShareLinksImpl.java From alfresco-remote-api with GNU Lesser General Public License v3.0 | 4 votes |
/** * Download content via shared link. * <p> * Note: does *not* require authenticated access for (public) shared link. * * @param sharedId * @param renditionId - optional * @param parameters {@link Parameters} * @return * @throws EntityNotFoundException */ public BinaryResource readProperty(String sharedId, final String renditionId, final Parameters parameters) throws EntityNotFoundException { checkEnabled(); checkValidShareId(sharedId); try { Pair<String, NodeRef> pair = quickShareService.getTenantNodeRefFromSharedId(sharedId); String networkTenantDomain = pair.getFirst(); final NodeRef nodeRef = pair.getSecond(); return TenantUtil.runAsSystemTenant(() -> { // belt-and-braces (similar to QuickShareContentGet) if (!nodeService.hasAspect(nodeRef, QuickShareModel.ASPECT_QSHARE)) { throw new InvalidNodeRefException(nodeRef); } if (renditionId != null) { return renditions.getContent(nodeRef, renditionId, parameters); } else { return nodes.getContent(nodeRef, parameters, false); } }, networkTenantDomain); } catch (InvalidSharedIdException ex) { logger.warn("Unable to find: " + sharedId); throw new EntityNotFoundException(sharedId); } catch (InvalidNodeRefException inre) { logger.warn("Unable to find: " + sharedId + " [" + inre.getNodeRef() + "]"); throw new EntityNotFoundException(sharedId); } }