Java Code Examples for org.alfresco.repo.tenant.TenantService#DEFAULT_DOMAIN

The following examples show how to use org.alfresco.repo.tenant.TenantService#DEFAULT_DOMAIN . 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: ModelValidatorImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void validateDeleteProperty(QName modelName, QName propertyQName, boolean sharedModel)
{
    String tenantDomain = TenantService.DEFAULT_DOMAIN;
    if (sharedModel)
    {
        tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
    }

    PropertyDefinition prop = dictionaryDAO.getProperty(propertyQName);
    if(prop != null && prop.getName().equals(propertyQName) && prop.getModel().getName().equals(modelName))
    {
        validateDeleteProperty(tenantDomain, prop);
    }
    else
    {
        throw new AlfrescoRuntimeException("Cannot delete model " + modelName + " in tenant " + tenantDomain
                + " - property definition '" + propertyQName + "' not defined in model '" + modelName + "'");
    }
}
 
Example 2
Source File: AbstractBaseApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * TODO implement as remote api call
 */
protected String deleteUser(final String username, final TestNetwork network)
{
    final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);

    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>()
    {
        @Override
        public String doWork() throws Exception
        {
            return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<String>()
            {
                public String doWork() throws Exception
                {
                    repoService.deleteUser(username, network);
                    return null;
                }
            }, tenantDomain);
        }
    }, networkAdmin);
}
 
Example 3
Source File: AbstractBaseApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * TODO implement as remote api call
 */
protected String getOrCreateUser(String usernameIn, String password, TestNetwork network)
{
    final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);

    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>()
    {
        @Override
        public String doWork() throws Exception
        {
            return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<String>()
            {
                public String doWork() throws Exception
                {
                    String username = repoService.getPublicApiContext().createUserName(usernameIn, tenantDomain);
                    PersonInfo personInfo = new PersonInfo(username, username, username, password, null, null, null, null, null, null, null);
                    RepoService.TestPerson person = repoService.getOrCreateUser(personInfo, username, network);
                    return person.getId();
                }
            }, tenantDomain);
        }
    }, networkAdmin);
}
 
Example 4
Source File: AbstractBaseApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * TODO implement as remote api call
 */
protected String createUser(final PersonInfo personInfo, final TestNetwork network)
{
    final String tenantDomain = (network != null ? network.getId() : TenantService.DEFAULT_DOMAIN);
    
    return AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<String>()
    {
        @Override
        public String doWork() throws Exception
        {
            return TenantUtil.runAsTenant(new TenantUtil.TenantRunAsWork<String>()
            {
                public String doWork() throws Exception
                {
                    String username = repoService.getPublicApiContext().createUserName(personInfo.getUsername(), tenantDomain);
                    personInfo.setUsername(username);
                    RepoService.TestPerson person = repoService.createUser(personInfo, username, network);
                    return person.getId();

                }
            }, tenantDomain);
        }
    }, networkAdmin);
}
 
Example 5
Source File: PublicApiAlfrescoCmisService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 6
Source File: AbstractMailActionExecuterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static String getUsersHomeTenant(String userName)
{
    boolean thisIsCloud = false;
    try
    {
        thisIsCloud = (Class.forName("org.alfresco.module.org_alfresco_module_cloud.registration.RegistrationService") != null);
    }
    catch (ClassNotFoundException ignoreIfThrown)
    {
        // Intentionally empty
    }

    String result = TenantService.DEFAULT_DOMAIN;

    // Even if we get email address-style user names in an enterprise system, those are not to be given home tenants.
    if (thisIsCloud)
    {
        String[] elems = userName.split("@");
        result = elems[1];
    }

    return result;

}
 
Example 7
Source File: InviteResponse.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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 8
Source File: WebDAVHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public String determineTenantDomain()
{
    TenantService tenantService = getTenantService();
    String tenantDomain = tenantService.getCurrentUserDomain();
    if (tenantDomain == null)
    {
        return TenantService.DEFAULT_DOMAIN;
    }
    return tenantDomain;
}
 
Example 9
Source File: InviteByTicket.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected Map<String, Object> executeImpl(final WebScriptRequest req, final Status status)
{
    String tenantDomain = TenantService.DEFAULT_DOMAIN;
    
    if (tenantService.isEnabled())
    {
        String inviteeUserName = req.getParameter(PARAM_INVITEE_USER_NAME);
        if (inviteeUserName != null)
        {
            tenantDomain = tenantService.getUserDomain(inviteeUserName);
        }
    }
    
    // run as system user
    String mtAwareSystemUser = tenantService.getDomainUser(AuthenticationUtil.getSystemUserName(), tenantDomain);
    
    Map<String, Object> ret = TenantUtil.runAsSystemTenant(new TenantRunAsWork<Map<String, Object>>()
    {
        public Map<String, Object> doWork() throws Exception
        {
            return execute(req, status);
        }
    }, tenantDomain);
    
    // authenticate as system for the rest of the webscript
    AuthenticationUtil.setRunAsUser(mtAwareSystemUser);
    
    return ret;
}
 
Example 10
Source File: AuthenticationUtil.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Pair<String, String> getUserTenant(String userName)
{
    String tenantDomain = TenantContextHolder.getTenantDomain();
    if (tenantDomain == null)
    {
        tenantDomain = TenantService.DEFAULT_DOMAIN;
        
        if ((userName != null) && isMtEnabled())
        {
            // MT implied domain from username (for backwards compatibility)
            int idx = userName.indexOf(TenantService.SEPARATOR);
            if ((idx > 0) && (idx < (userName.length()-1)))
            {
                tenantDomain = userName.substring(idx+1);
                if (tenantDomain.indexOf(TenantService.SEPARATOR) > 0)
                {
                    throw new AlfrescoRuntimeException("Unexpected tenant: "+tenantDomain+" (contains @)");
                }

                if (logger.isDebugEnabled())
                {
                    logger.debug("Tenant domain implied: userName=" + maskUsername(userName) + ", tenantDomain=" + tenantDomain);
                }
            }
        }
    }
    return new Pair<String, String>(userName, tenantDomain);
}
 
Example 11
Source File: ActivityPosterImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String getCurrentTenantDomain()
{
    String tenantDomain = tenantService.getCurrentUserDomain();
    if (tenantDomain == null)
    {
        return TenantService.DEFAULT_DOMAIN;
    }
    return tenantDomain;
}
 
Example 12
Source File: ModelValidatorImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void validateDeleteClass(final Tenant tenant, final ClassDefinition classDef)
{
    final String classType = "TYPE";
    final QName className = classDef.getName();

    String tenantDomain = "for tenant ["
            + (tenant == null ? TenantService.DEFAULT_DOMAIN : tenant.getTenantDomain()) + "]";

    // We need a separate transaction to do the qname delete "check"
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            try
            {
                // The class QName may not have been created in the database if no
                // properties have been created that use it, so check first and then
                // try to delete it.
                if(qnameDAO.getQName(className) != null)
                {
                    qnameDAO.deleteQName(className);
                }
                throw new ModelNotInUseException("Class " + className + " not in use");
            }
            catch(DataIntegrityViolationException e)
            {
                // catch data integrity violation e.g. foreign key constraint exception
                logger.debug(e);
                throw new ModelInUseException("Cannot delete model, class "
                        + className + " is in use");
            }
        }
    }, false, true);


    // check against workflow task usage
    for (WorkflowDefinition workflowDef : workflowService.getDefinitions())
    {
        for (WorkflowTaskDefinition workflowTaskDef : workflowService.getTaskDefinitions(workflowDef.getId()))
        {
            TypeDefinition workflowTypeDef = workflowTaskDef.metadata;
            if (workflowTypeDef.getName().equals(className))
            {
                throw new AlfrescoRuntimeException("Failed to validate model delete" + tenantDomain + " - found task definition in workflow " 
                        + workflowDef.getName() + " with " + classType + " '" + className + "'");
            }
        }
    }
}
 
Example 13
Source File: RepoService.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
public RepoService(ApplicationContext applicationContext) throws Exception
   {
   	this.applicationContext = applicationContext;
   	this.publicApiContext = new PublicApiTestContext(applicationContext);
   	this.authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService");
   	this.siteService = (SiteService)applicationContext.getBean("SiteService");
   	this.activityService = (ActivityService)applicationContext.getBean("activityService");
   	this.fileFolderService = (FileFolderService)applicationContext.getBean("FileFolderService");
   	this.contentService = (ContentService)applicationContext.getBean("ContentService");
   	this.commentService = (CommentService)applicationContext.getBean("CommentService");
   	this.nodeService = (NodeService)applicationContext.getBean("NodeService");
   	this.preferenceService = (PreferenceService)applicationContext.getBean("PreferenceService");
   	this.taggingService = (TaggingService)applicationContext.getBean("TaggingService");
   	this.ratingService = (RatingService)applicationContext.getBean("RatingService");
   	this.tenantService = (TenantService)applicationContext.getBean("tenantService");
   	this.tenantAdminService = (TenantAdminService)applicationContext.getBean("tenantAdminService");
   	this.personService = (PersonService)applicationContext.getBean("PersonService");
   	this.contentStoreCleaner = (ContentStoreCleaner)applicationContext.getBean("contentStoreCleaner");
   	this.postDAO = (ActivityPostDAO)applicationContext.getBean("postDAO");
   	this.nodeRatingSchemeRegistry = (NamedObjectRegistry<RatingScheme>)applicationContext.getBean("nodeRatingSchemeRegistry");
   	this.cociService = (CheckOutCheckInService)applicationContext.getBean("CheckoutCheckinService");
   	this.favouritesService = (FavouritesService)applicationContext.getBean("FavouritesService");
   	this.dictionaryService =  (DictionaryService)applicationContext.getBean("dictionaryService");
   	this.invitationService = (InvitationService)applicationContext.getBean("InvitationService");
   	this.lockService = (LockService)applicationContext.getBean("LockService");
   	this.cmisConnector = (CMISConnector)applicationContext.getBean("CMISConnector");
   	this.activities = (Activities)applicationContext.getBean("activities");
   	this.hiddenAspect = (HiddenAspect)applicationContext.getBean("hiddenAspect");
   	this.networksService = (NetworksService)applicationContext.getBean("networksService");
   	this.namespaceService = (NamespaceService)applicationContext.getBean("namespaceService"); 
   	this.transactionHelper = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");

       Scheduler scheduler = (Scheduler)applicationContext.getBean("schedulerFactory");

       CronTrigger contentStoreCleanerTrigger = (CronTrigger)applicationContext.getBean("contentStoreCleanerTrigger");
       scheduler.pauseJob(contentStoreCleanerTrigger.getJobKey());

       ChildApplicationContextFactory activitiesFeed = (ChildApplicationContextFactory)applicationContext.getBean("ActivitiesFeed");
       ApplicationContext activitiesFeedCtx = activitiesFeed.getApplicationContext();
       this.postLookup = (PostLookup)activitiesFeedCtx.getBean("postLookup");
       this.feedGenerator = (FeedGenerator)activitiesFeedCtx.getBean("feedGenerator");
       this.feedGeneratorJobDetail = (JobDetail)activitiesFeedCtx.getBean("feedGeneratorJobDetail");
       this.postLookupJobDetail = (JobDetail)activitiesFeedCtx.getBean("postLookupJobDetail");
       this.feedCleanerJobDetail = (JobDetail)activitiesFeedCtx.getBean("feedCleanerJobDetail");
       this.postCleanerJobDetail = (JobDetail)activitiesFeedCtx.getBean("postCleanerJobDetail");
       this.feedNotifierJobDetail = (JobDetail)activitiesFeedCtx.getBean("feedNotifierJobDetail");
   	this.feedCleaner = (FeedCleaner)activitiesFeedCtx.getBean("feedCleaner");

       // Pause activities jobs so that we aren't competing with their scheduled versions
       scheduler.pauseJob(feedGeneratorJobDetail.getKey());
       scheduler.pauseJob(postLookupJobDetail.getKey());
       scheduler.pauseJob(feedCleanerJobDetail.getKey());
       scheduler.pauseJob(postCleanerJobDetail.getKey());
       scheduler.pauseJob(feedNotifierJobDetail.getKey());

       this.systemNetwork = new TestNetwork(TenantService.DEFAULT_DOMAIN, true);
}
 
Example 14
Source File: FeedTaskProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected String getTenantDomain(String name)
{
    // note: for MT impl, see override in LocalFeedTaskProcessor
    return TenantService.DEFAULT_DOMAIN;
}
 
Example 15
Source File: LocalFeedTaskProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected boolean canRead(RepoCtx ctx, final String connectedUser, Map<String, Object> model) throws Exception
{
    if (useRemoteCallbacks)
    {
        // note: not implemented
        throw new UnsupportedOperationException("Not implemented");
    }
    
    if (permissionService == null)
    {
        // if permission service not configured then fallback (ie. no read permission check)
        return true;
    }
    
    String nodeRefStr = (String) model.get(PostLookup.JSON_NODEREF);
    if (nodeRefStr == null)
    {
        nodeRefStr = (String) model.get(PostLookup.JSON_NODEREF_PARENT);
    }
    
    if (nodeRefStr != null)
    {
        final NodeRef nodeRef = new NodeRef(nodeRefStr);
        
        // MT share
        String tenantDomain = (String)model.get(PostLookup.JSON_TENANT_DOMAIN);
        if (tenantDomain == null) { tenantDomain = TenantService.DEFAULT_DOMAIN; }
        
        return TenantUtil.runAsSystemTenant(new TenantUtil.TenantRunAsWork<Boolean>()
        {
            public Boolean doWork() throws Exception
            {
                return canReadImpl(connectedUser, nodeRef);
            }
        }, tenantDomain);
    }
    else
    {
        // no nodeRef
        return true;
    }
}
 
Example 16
Source File: ModelValidatorImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void validateDeleteConstraint(CompiledModel compiledModel, QName constraintName, boolean sharedModel)
{
    String tenantDomain = TenantService.DEFAULT_DOMAIN;
    if (sharedModel)
    {
        tenantDomain = " for tenant [" + tenantService.getCurrentUserDomain() + "]";
    }
    
    Set<QName> referencedBy = new HashSet<QName>(0);
    
    // check for references to constraint definition
    // note: could be anon prop constraint (if no referenceable constraint)
    Collection<QName> allModels = dictionaryDAO.getModels();
    for (QName model : allModels)
    {
        Collection<PropertyDefinition> propDefs = null;
        if (compiledModel.getModelDefinition().getName().equals(model))
        {
            // TODO deal with multiple pending model updates
            propDefs = compiledModel.getProperties();
        }
        else
        {
            propDefs = dictionaryDAO.getProperties(model);
        }
        
        for (PropertyDefinition propDef : propDefs)
        {
            for (ConstraintDefinition conDef : propDef.getConstraints())
            {
                if (constraintName.equals(conDef.getRef()))
                {
                    referencedBy.add(conDef.getName());
                }
            }
        }
    }
    
    if (referencedBy.size() == 1)
    {
        throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by '" + referencedBy.toArray()[0] + "' property constraint");
    }
    else if (referencedBy.size() > 1)
    {
        throw new AlfrescoRuntimeException("Failed to validate constraint delete" + tenantDomain + " - constraint definition '" + constraintName + "' is being referenced by " + referencedBy.size() + " property constraints");
    }
}
 
Example 17
Source File: Person.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static String getNetworkId(String personId)
{
    int idx = personId.indexOf("@");
    return(idx == -1 ? TenantService.DEFAULT_DOMAIN : personId.substring(idx + 1));
}
 
Example 18
Source File: AlfrescoSolrUtils.java    From SearchServices with GNU Lesser General Public License v3.0 3 votes vote down vote up
/**
 * Get an AclReader.
 * @param aclChangeSet
 * @param acl
 * @param readers
 * @param denied
 * @param tenant
 * @return
 */
public static AclReaders getAclReaders(AclChangeSet aclChangeSet, Acl acl, List<String> readers, List<String> denied, String tenant)
{
    if(tenant == null)
    {
        tenant = TenantService.DEFAULT_DOMAIN;
    }
    return new AclReaders(acl.getId(), readers, denied, aclChangeSet.getId(), tenant);
}