org.alfresco.service.cmr.security.AuthorityService Java Examples

The following examples show how to use org.alfresco.service.cmr.security.AuthorityService. 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: AuditAppTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setup() throws Exception 
{
    super.setup();

    permissionService = applicationContext.getBean("permissionService", PermissionService.class);
    authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
    auditService = applicationContext.getBean("AuditService", AuditService.class);

    AuditModelRegistryImpl auditModelRegistry = (AuditModelRegistryImpl) applicationContext.getBean("auditModel.modelRegistry");

    // Register the test model
    URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/audit/alfresco-audit-access.xml");
    auditModelRegistry.registerModel(testModelUrl);
    auditModelRegistry.loadAuditModels();
}
 
Example #2
Source File: GetPeopleCannedQuery.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public GetPeopleCannedQuery(
        NodeDAO nodeDAO,
        QNameDAO qnameDAO,
        CannedQueryDAO cannedQueryDAO,
        TenantService tenantService,
        NodeService nodeService,
        AuthorityService authorityService,
        CannedQueryParameters params)
{
    super(params);
    
    this.nodeDAO = nodeDAO;
    this.qnameDAO = qnameDAO;
    this.cannedQueryDAO = cannedQueryDAO;
    this.tenantService = tenantService;
    this.nodeService = nodeService;
    this.authorityService = authorityService;
    
}
 
Example #3
Source File: AuthoritiesDataCollector.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public List<HBData> collectData()
{
    this.logger.debug("Preparing repository usage (authorities) data...");

    Map<String, Object> authoritiesUsageValues = new HashMap<>();
    authoritiesUsageValues.put("numUsers", new Integer(this.authorityService.getAllAuthoritiesInZone(
            AuthorityService.ZONE_APP_DEFAULT, AuthorityType.USER).size()));
    authoritiesUsageValues.put("numGroups", new Integer(this.authorityService.getAllAuthoritiesInZone(
            AuthorityService.ZONE_APP_DEFAULT, AuthorityType.GROUP).size()));
    HBData authoritiesUsageData = new HBData(
            this.currentRepoDescriptorDAO.getDescriptor().getId(),
            this.getCollectorId(),
            this.getCollectorVersion(),
            new Date(),
            authoritiesUsageValues);

    return Arrays.asList(authoritiesUsageData);
}
 
Example #4
Source File: ChainingUserRegistrySynchronizerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Tests synchronization of group associations in a zone with a larger volume of authorities.
 * 
 * @throws Exception
 *             the exception
 */
public void dontTestAssocs() throws Exception
{
    List<NodeDescription> groups = this.retryingTransactionHelper.doInTransaction(
            new RetryingTransactionCallback<List<NodeDescription>>()
            {

                public List<NodeDescription> execute() throws Throwable
                {
                    return new ArrayList<NodeDescription>(new RandomGroupCollection(1000,
                            ChainingUserRegistrySynchronizerTest.this.authorityService.getAllAuthoritiesInZone(
                                    AuthorityService.ZONE_AUTH_EXT_PREFIX + "Z0", null)));
                }
            }, true, true);
    ChainingUserRegistrySynchronizerTest.this.applicationContextManager.setUserRegistries(new MockUserRegistry(
            "Z0", Collections.<NodeDescription> emptyList(), groups));
    ChainingUserRegistrySynchronizerTest.this.synchronizer.synchronize(true, true);
    tearDownTestUsersAndGroups();
}
 
Example #5
Source File: AuthorityBridgeTableAsynchronouslyRefreshedCacheTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
    authorityService = (AuthorityService) ctx.getBean(ServiceRegistry.AUTHORITY_SERVICE.getLocalName());
    tenantAdminService = ctx.getBean("tenantAdminService", TenantAdminService.class);
    personService = (PersonService) ctx.getBean(ServiceRegistry.PERSON_SERVICE.getLocalName());
    tenantService = (TenantService) ctx.getBean("tenantService");
    authorityBridgeTableCache = (AuthorityBridgeTableAsynchronouslyRefreshedCache) ctx.getBean("authorityBridgeTableCache");
}
 
Example #6
Source File: ChainingUserRegistrySynchronizer.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Modifies an authority's zone set from oldZones to newZones in the most efficient manner (avoiding unnecessary
 * reindexing cost).
 */
private void updateAuthorityZones(String authorityName, Set<String> oldZones, final Set<String> newZones)
{
    Set<String> zonesToRemove = new HashSet<String>(oldZones);
    zonesToRemove.removeAll(newZones);
    // Let's keep the authority in the alfresco auth zone if it was already there. Otherwise we may have to
    // regenerate all paths to this authority from site groups, which could be very expensive!
    zonesToRemove.remove(AuthorityService.ZONE_AUTH_ALFRESCO);
    if (!zonesToRemove.isEmpty())
    {
        this.authorityService.removeAuthorityFromZones(authorityName, zonesToRemove);
    }
    Set<String> zonesToAdd = new HashSet<String>(newZones);
    zonesToAdd.removeAll(oldZones);
    if (!zonesToAdd.isEmpty())
    {
        this.authorityService.addAuthorityToZones(authorityName, zonesToAdd);
    }
}
 
Example #7
Source File: AuthorityServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void testGetAuthoritiesForZone() 
{
    String role = pubAuthorityService.createAuthority(AuthorityType.ROLE, "one");
    String group = pubAuthorityService.createAuthority(AuthorityType.GROUP, "group1");
    String user = "user@" + System.currentTimeMillis();
    createUserAuthority(user);

    PagingResults<String> authorities = authorityService.getAuthorities(null, AuthorityService.ZONE_APP_DEFAULT, "*", false, false, new PagingRequest(100));
    assertTrue(authorities.getPage().contains(user));
    assertTrue(authorities.getPage().contains(role));
    assertTrue(authorities.getPage().contains(group));
    
    PagingResults<String> groups = authorityService.getAuthorities(AuthorityType.GROUP, AuthorityService.ZONE_APP_DEFAULT, "*", false, false, new PagingRequest(100));
    assertTrue(groups.getPage().contains(group));
    assertFalse(groups.getPage().contains(user));
    assertFalse(groups.getPage().contains(role));
}
 
Example #8
Source File: SiteServiceTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
    this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
    this.permissionService = (PermissionService)getServer().getApplicationContext().getBean("PermissionService");
    this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService");
    this.fileFolderService = (FileFolderService)getServer().getApplicationContext().getBean("FileFolderService");

    
    // Create users
    createUser(USER_ONE);
    createUser(USER_TWO);
    createUser(USER_THREE);
    createUser(USER_NUMERIC);
    createUser(USER_FOUR_AS_SITE_ADMIN);
    
    // Add user four as a member of the site admins group
    authorityService.addAuthority("GROUP_SITE_ADMINISTRATORS", USER_FOUR_AS_SITE_ADMIN);
    
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example #9
Source File: AuthoritiesDataCollectorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setUp()
{
    HBDataCollectorService mockCollectorService = mock(HBDataCollectorService.class);
    AuthorityService authorityService = mock(AuthorityService.class);
    mockScheduler = mock(HeartBeatJobScheduler.class);

    Descriptor mockDescriptor = mock(Descriptor.class);
    when(mockDescriptor.getId()).thenReturn("mock_id");
    DescriptorDAO descriptorDAO = mock(DescriptorDAO.class);
    when(descriptorDAO.getDescriptor()).thenReturn(mockDescriptor);

    authorityDataCollector = new AuthoritiesDataCollector("acs.repository.usage.authorities", "1.0", "0 0 0 ? * *", mockScheduler);
    authorityDataCollector.setAuthorityService(authorityService);
    authorityDataCollector.setCurrentRepoDescriptorDAO(descriptorDAO);
    authorityDataCollector.setHbDataCollectorService(mockCollectorService);
    collectedData = authorityDataCollector.collectData();
}
 
Example #10
Source File: EmailServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void setUp() throws Exception
{  
    AuthenticationUtil.setRunAsUserSystem();
    nodeService = (NodeService)ctx.getBean("NodeService");
    assertNotNull("nodeService", nodeService);
    authorityService = (AuthorityService)ctx.getBean("AuthorityService");
    assertNotNull("authorityService", authorityService);
    ChildApplicationContextFactory emailSubsystem = (ChildApplicationContextFactory) ctx.getBean("InboundSMTP");
    assertNotNull("emailSubsystem", emailSubsystem);
    ApplicationContext emailCtx = emailSubsystem.getApplicationContext();
    emailService = (EmailService)emailCtx.getBean("emailService");       
    assertNotNull("emailService", emailService);
    personService = (PersonService)emailCtx.getBean("PersonService");       
    assertNotNull("personService", personService);     
    namespaceService = (NamespaceService)emailCtx.getBean("NamespaceService");       
    assertNotNull("namespaceService", namespaceService);
    searchService = (SearchService)emailCtx.getBean("SearchService");  
    assertNotNull("searchService", searchService);
    folderEmailMessageHandler = (FolderEmailMessageHandler) emailCtx.getBean("folderEmailMessageHandler");  
    assertNotNull("folderEmailMessageHandler", folderEmailMessageHandler);
    transactionHelper = (RetryingTransactionHelper) emailCtx.getBean("retryingTransactionHelper");
    assertNotNull("transactionHelper", transactionHelper);
}
 
Example #11
Source File: BaseCustomModelApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void setup() throws Exception
{
    authenticationService = applicationContext.getBean("authenticationService", MutableAuthenticationService.class);
    personService = applicationContext.getBean("personService", PersonService.class);
    customModelService = applicationContext.getBean("customModelService", CustomModelService.class);

    final AuthorityService authorityService = applicationContext.getBean("authorityService", AuthorityService.class);

    this.nonAdminUserName = createUser("nonAdminUser" + System.currentTimeMillis(), "password", null);
    this.customModelAdmin = createUser("customModelAdmin" + System.currentTimeMillis(), "password", null);
    users.add(nonAdminUserName);
    users.add(customModelAdmin);

    // Add 'customModelAdmin' user into 'ALFRESCO_MODEL_ADMINISTRATORS' group
    AuthenticationUtil.runAsSystem((RunAsWork<Void>) () -> {
        transactionHelper.doInTransaction((RetryingTransactionCallback<Void>) () -> {
            authorityService.addAuthority(CustomModelServiceImpl.GROUP_ALFRESCO_MODEL_ADMINISTRATORS_AUTHORITY, customModelAdmin);
            return null;
        });
        return null;
    });
}
 
Example #12
Source File: People.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the groups that contain the specified authority
 * 
 * @param person       the user (cm:person) to get the containing groups for
 * 
 * @return the containing groups as a JavaScript array
 */
public Scriptable getContainerGroups(ScriptNode person)
{
    ParameterCheck.mandatory("Person", person);
    Object[] parents = null;
    Set<String> authorities = this.authorityService.getContainingAuthoritiesInZone(
            AuthorityType.GROUP,
            (String)person.getProperties().get(ContentModel.PROP_USERNAME),
            AuthorityService.ZONE_APP_DEFAULT, null, 1000);
    parents = new Object[authorities.size()];
    int i = 0;
    for (String authority : authorities)
    {
        ScriptNode group = getGroup(authority);
        if (group != null)
        {
            parents[i++] = group; 
        }
    }
    return Context.getCurrentContext().newArray(getScope(), parents);
}
 
Example #13
Source File: GroupsTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    
    this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
    this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
    this.authorityService = (AuthorityService)getServer().getApplicationContext().getBean("AuthorityService");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // Create users
    createUser(USER_ONE);
    createUser(USER_TWO);
    createUser(USER_THREE);
    
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example #14
Source File: MultiTDemoTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    super.setUp();
    ctx = ApplicationContextHelper.getApplicationContext(new String[] { ApplicationContextHelper.CONFIG_LOCATIONS[0], "classpath:tenant/mt-*context.xml" });

    nodeService = (NodeService) ctx.getBean("NodeService");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    namespaceService = (NamespaceService) ctx.getBean("NamespaceService");
    authenticationService = (MutableAuthenticationService) ctx.getBean("AuthenticationService");
    tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
    tenantService = (TenantService) ctx.getBean("tenantService");
    personService = (PersonService) ctx.getBean("PersonService");
    searchService = (SearchService) ctx.getBean("SearchService");
    contentService = (ContentService) ctx.getBean("ContentService");
    permissionService = (PermissionService) ctx.getBean("PermissionService");
    ownableService = (OwnableService) ctx.getBean("OwnableService");
    authorityService = (AuthorityService) ctx.getBean("AuthorityService");
    categoryService = (CategoryService) ctx.getBean("CategoryService");
    cociService = (CheckOutCheckInService) ctx.getBean("CheckoutCheckinService");
    repoAdminService = (RepoAdminService) ctx.getBean("RepoAdminService");
    dictionaryService = (DictionaryService) ctx.getBean("DictionaryService");
    usageService = (UsageService) ctx.getBean("usageService");
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    fileFolderService = (FileFolderService) ctx.getBean("FileFolderService");
    ownableService = (OwnableService) ctx.getBean("OwnableService");
    repositoryHelper = (Repository) ctx.getBean("repositoryHelper");
    siteService = (SiteService) ctx.getBean("SiteService");
    
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName()); // authenticate as super-admin
    
    createTenants();
    createUsers();
}
 
Example #15
Source File: FacetRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override protected void setUp() throws Exception
{
    super.setUp();
    authenticationService = getServer().getApplicationContext().getBean("AuthenticationService", MutableAuthenticationService.class);
    authorityService      = getServer().getApplicationContext().getBean("AuthorityService", AuthorityService.class);
    personService         = getServer().getApplicationContext().getBean("PersonService", PersonService.class);
    transactionHelper     = getServer().getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);

    AuthenticationUtil.clearCurrentSecurityContext();
    // Create test users. TODO Create these users @BeforeClass or at a testsuite scope.
    AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
    {
        @Override public Void doWork() throws Exception
        {
            createUser(SEARCH_ADMIN_USER);
            createUser(NON_SEARCH_ADMIN_USER);

            if ( !authorityService.getContainingAuthorities(AuthorityType.GROUP,
                                                            SEARCH_ADMIN_USER,
                                                            true)
                                .contains(SolrFacetServiceImpl.GROUP_ALFRESCO_SEARCH_ADMINISTRATORS_AUTHORITY))
            {
                authorityService.addAuthority(SolrFacetServiceImpl.GROUP_ALFRESCO_SEARCH_ADMINISTRATORS_AUTHORITY,
                                              SEARCH_ADMIN_USER);
            }
            return null;
        }
    });
}
 
Example #16
Source File: CMISTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void before()
{
    this.actionService = (ActionService)ctx.getBean("actionService");
    this.ruleService = (RuleService)ctx.getBean("ruleService");
	this.fileFolderService = (FileFolderService)ctx.getBean("FileFolderService");
	this.transactionService = (TransactionService)ctx.getBean("transactionService");
	this.nodeService = (NodeService)ctx.getBean("NodeService");
	this.contentService = (ContentService)ctx.getBean("ContentService");
    this.versionService = (VersionService) ctx.getBean("versionService");
    this.lockService = (LockService) ctx.getBean("lockService");
    this.taggingService = (TaggingService) ctx.getBean("TaggingService");
    this.namespaceService = (NamespaceService) ctx.getBean("namespaceService");
    this.repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
	this.factory = (AlfrescoCmisServiceFactory)ctx.getBean("CMISServiceFactory");
    this.versionService = (VersionService) ctx.getBean("versionService");
	this.cmisConnector = (CMISConnector) ctx.getBean("CMISConnector");
    this.nodeDAO = (NodeDAO) ctx.getBean("nodeDAO");
    this.authorityService = (AuthorityService)ctx.getBean("AuthorityService");
    this.auditSubsystem = (AuditModelRegistryImpl) ctx.getBean("Audit");
    this.permissionService = (PermissionService) ctx.getBean("permissionService");
	this.dictionaryDAO = (DictionaryDAO)ctx.getBean("dictionaryDAO");
	this.cmisDictionaryService = (CMISDictionaryService)ctx.getBean("OpenCMISDictionaryService1.1");
    this.auditDAO = (AuditDAO) ctx.getBean("auditDAO");
    this.nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    this.dictionaryService = (DictionaryService) ctx.getBean("dictionaryService");
    this.workflowService = (WorkflowService) ctx.getBean("WorkflowService");
    this.workflowAdminService = (WorkflowAdminService) ctx.getBean("workflowAdminService");
    this.authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext");
    this.tenantAdminService = (TenantAdminService) ctx.getBean("tenantAdminService");
    this.tenantService = (TenantService) ctx.getBean("tenantService");
    this.searchService = (SearchService) ctx.getBean("SearchService");
    this.auditComponent = (AuditComponentImpl) ctx.getBean("auditComponent");

    this.globalProperties = (java.util.Properties) ctx.getBean("global-properties");
    this.globalProperties.setProperty(VersionableAspectTest.AUTO_VERSION_PROPS_KEY, "true");
}
 
Example #17
Source File: ScriptAuthorityServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testGetGroups()
{
    // find all the groups that start with "test"
    ScriptGroup[] groups = service.getGroupsInZone("test", AuthorityService.ZONE_APP_DEFAULT, new ScriptPagingDetails(10,0), null);
    assertEquals(3, groups.length);
    
    // find a certain group
    groups = service.getGroupsInZone(GROUP_A, AuthorityService.ZONE_APP_DEFAULT, new ScriptPagingDetails(10,0), null);
    assertEquals(1, groups.length);
    
    // make sure a contains query falls back to lucene
    groups = service.getGroupsInZone("*Group", AuthorityService.ZONE_APP_DEFAULT, new ScriptPagingDetails(10,0), null);
    assertEquals(3, groups.length);
    
    // make sure a ? wildcard query falls back to lucene
    groups = service.getGroupsInZone("t?st", AuthorityService.ZONE_APP_DEFAULT, new ScriptPagingDetails(10,0), null);
    assertEquals(3, groups.length);
    
    // make sure we support getting all results
    groups = service.getGroupsInZone("*", AuthorityService.ZONE_APP_DEFAULT, new ScriptPagingDetails(10,0), null);
    assertEquals(6, groups.length);
    
    // ensure paging works, query for all results but just return 1 per page
    groups = service.getGroupsInZone("test", AuthorityService.ZONE_APP_DEFAULT, new ScriptPagingDetails(2,2), "displayName");
    assertEquals(1, groups.length);
    assertEquals(GROUP_C, groups[0].getShortName());
		
    // make sure search works for unicode dispaly name
    groups = service.getGroupsInZone("ั‚ะตัั‚", AuthorityService.ZONE_APP_DEFAULT, new ScriptPagingDetails(10, 0), null, true);
    assertEquals(1, groups.length);   		
}
 
Example #18
Source File: HomeFolderProviderSynchronizer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public HomeFolderProviderSynchronizer(
        TransactionService transactionService,
        AuthorityService authorityService, PersonService personService,
        FileFolderService fileFolderService, NodeService nodeService,
        PortableHomeFolderManager homeFolderManager,
        TenantAdminService tenantAdminService)
{
    this.transactionService = transactionService;
    this.authorityService = authorityService;
    this.personService = personService;
    this.fileFolderService = fileFolderService;
    this.nodeService = nodeService;
    this.homeFolderManager = homeFolderManager;
    this.tenantAdminService = tenantAdminService;
}
 
Example #19
Source File: ChainingUserRegistrySynchronizer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Date getSynchronizationLastGroupUpdateTime(String id)
{
    String zoneId = AuthorityService.ZONE_AUTH_EXT_PREFIX + id;
    long time = getMostRecentUpdateTime(ChainingUserRegistrySynchronizer.GROUP_LAST_MODIFIED_ATTRIBUTE, zoneId, false);
    Date lastGroupUpdate = time == -1 ? null : new Date(time);
    return lastGroupUpdate;
}
 
Example #20
Source File: ChainingUserRegistrySynchronizer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Date getSynchronizationLastUserUpdateTime(String id)
{
    String zoneId = AuthorityService.ZONE_AUTH_EXT_PREFIX + id;
    long time = getMostRecentUpdateTime(ChainingUserRegistrySynchronizer.PERSON_LAST_MODIFIED_ATTRIBUTE, zoneId, false);
    Date lastUserUpdate = time == -1 ? null : new Date(time);
    return lastUserUpdate;
}
 
Example #21
Source File: GroupsTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setup() throws Exception
{
    super.setup();

    authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
    AuthorityDAOImpl authorityDAOImpl = (AuthorityDAOImpl) applicationContext.getBean("authorityDAO");
    authorityDAOImpl.setSearchService(mockSearchService);
    when(mockSearchServiceQueryResultSet.iterator()).thenReturn(iterator);
}
 
Example #22
Source File: ChainingUserRegistrySynchronizer.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Set<QName> getPersonMappedProperties(String username)
{
    Set<String> authorityZones = this.authorityService.getAuthorityZones(username);
    if (authorityZones == null)
    {
        return Collections.emptySet();
    }
    Collection<String> instanceIds = this.applicationContextManager.getInstanceIds();

    // Visit the user registries in priority order and return the person mapping of the first registry that matches
    // one of the person's zones
    for (String id : instanceIds)
    {
        String zoneId = AuthorityService.ZONE_AUTH_EXT_PREFIX + id;
        if (!authorityZones.contains(zoneId))
        {
            continue;
        }
        try
        {
            ApplicationContext context = this.applicationContextManager.getApplicationContext(id);
            UserRegistry plugin = (UserRegistry) context.getBean(this.sourceBeanName);
            if (!(plugin instanceof ActivateableBean) || ((ActivateableBean) plugin).isActive())
            {
                return plugin.getPersonMappedProperties();
            }
        }
        catch (RuntimeException e)
        {
            // The bean doesn't exist or this subsystem won't start. The reason would have been logged. Ignore and continue.
        }
    }

    return Collections.emptySet();
}
 
Example #23
Source File: DuplicateAuthorityTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    retryingTransactionHelper = transactionService.getRetryingTransactionHelper();
    retryingTransactionHelper.setMaxRetryWaitMs(10);
    nodeService = serviceRegistry.getNodeService();
    fileFolderService = serviceRegistry.getFileFolderService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    personService = (PersonService) ctx.getBean("personService");

    RetryingTransactionCallback<NodeRef> callback = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute() throws Throwable
        {
            // authenticate
            authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());

            // create a test store
            StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
            rootNodeRef = nodeService.getRootNode(storeRef);

            // create a folder to import into
            NodeRef nodeRef = nodeService.createNode(rootNodeRef, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.ALFRESCO_URI, "working root"),
                    ContentModel.TYPE_FOLDER).getChildRef();
            // Done
            return nodeRef;
        }
    };
    workingRootNodeRef = retryingTransactionHelper.doInTransaction(callback, false, true);
}
 
Example #24
Source File: ChainingUserRegistrySynchronizerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    this.synchronizer = (UserRegistrySynchronizer) ChainingUserRegistrySynchronizerTest.context
            .getBean("testUserRegistrySynchronizer");
    this.applicationContextManager = (MockApplicationContextManager) ChainingUserRegistrySynchronizerTest.context
            .getBean("testApplicationContextManager");
    this.personService = (PersonService) ChainingUserRegistrySynchronizerTest.context.getBean("personService");
    this.authorityService = (AuthorityService) ChainingUserRegistrySynchronizerTest.context
            .getBean("authorityService");
    this.nodeService = (NodeService) ChainingUserRegistrySynchronizerTest.context.getBean("nodeService");

    this.authenticationContext = (AuthenticationContext) ChainingUserRegistrySynchronizerTest.context
            .getBean("authenticationContext");
    
    
    // this.authenticationContext.setSystemUserAsCurrentUser();
    //AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    this.authenticationContext.setSystemUserAsCurrentUser();

    this.retryingTransactionHelper = (RetryingTransactionHelper) ChainingUserRegistrySynchronizerTest.context
            .getBean("retryingTransactionHelper");
    setHomeFolderCreationEager(false); // the normal default if using LDAP
    
    this.namespaceService = (NamespaceService) ChainingUserRegistrySynchronizerTest.context
            .getBean("namespaceService");
}
 
Example #25
Source File: ScriptGroup.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * New script group
 * @param fullName String
 * @param displayName String
 * @param serviceRegistry ServiceRegistry
 * @param authorityService AuthorityService
 * @param scope Scriptable
 */
private ScriptGroup(String fullName, String displayName, ServiceRegistry serviceRegistry, AuthorityService authorityService, Scriptable scope)
{
   this.authorityService = authorityService;
   this.serviceRegistry = serviceRegistry;
   this.fullName = fullName;
   this.scope = scope;
   shortName = authorityService.getShortName(fullName);
   this.displayName = displayName;
}
 
Example #26
Source File: CustomModelServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@BeforeClass
public static void initStaticData() throws Exception
{
    customModelService = APP_CONTEXT_INIT.getApplicationContext().getBean("customModelService", CustomModelService.class);
    transactionHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    personService = APP_CONTEXT_INIT.getApplicationContext().getBean("personService", PersonService.class);
    authorityService = APP_CONTEXT_INIT.getApplicationContext().getBean("authorityService", AuthorityService.class);
    cmmDownloadTestUtil = new CMMDownloadTestUtil(APP_CONTEXT_INIT.getApplicationContext());
}
 
Example #27
Source File: MockedTestServiceRegistry.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public AuthorityService getAuthorityService()
{
    // A mock response
    return null;
}
 
Example #28
Source File: AbstractWorkflowServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Before
public void before() throws Exception
{
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    this.workflowService = serviceRegistry.getWorkflowService();
    this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    this.nodeService = serviceRegistry.getNodeService();
    this.historyService = (HistoryService) applicationContext.getBean("activitiHistoryService");
    Repository repositoryHelper = (Repository) applicationContext.getBean("repositoryHelper");
    this.companyHome = repositoryHelper.getCompanyHome();
    try
    {
        this.transactionService = (TransactionServiceImpl) serviceRegistry.getTransactionService();
    }
    catch (ClassCastException e)
    {
        throw new AlfrescoRuntimeException("The AbstractWorkflowServiceIntegrationTest needs direct access to the TransactionServiceImpl");
    }

    MutableAuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
    AuthorityService authorityService = serviceRegistry.getAuthorityService();
    PersonService personService = serviceRegistry.getPersonService();

    authenticationComponent.setSystemUserAsCurrentUser();

    WorkflowAdminServiceImpl workflowAdminService = (WorkflowAdminServiceImpl) applicationContext.getBean(WorkflowAdminServiceImpl.NAME);
    this.wfTestHelper = new WorkflowTestHelper(workflowAdminService, getEngine(), true);
    
    // create test users
    this.personManager = new TestPersonManager(authenticationService, personService, nodeService);
    this.groupManager = new TestGroupManager(authorityService);
    
    personManager.createPerson(USER1);
    personManager.createPerson(USER2);
    personManager.createPerson(USER3);
    personManager.createPerson(USER4);

    // create test groups
    groupManager.addGroupToParent(GROUP, SUB_GROUP);
    
    // add users to groups
    groupManager.addUserToGroup(GROUP, USER1);
    groupManager.addUserToGroup(SUB_GROUP, USER2);
    
    personManager.setUser(USER1);
}
 
Example #29
Source File: AbstractSiteWebScript.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setAuthorityService(AuthorityService authorityService)
{
    this.authorityService = authorityService;
}
 
Example #30
Source File: AuthorityServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new AlfrescoRuntimeException(
                "A previous tests did not clean up transaction: " +
                AlfrescoTransactionSupport.getTransactionId());
    }
    
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authorityService = (AuthorityService) ctx.getBean("authorityService");
    pubAuthorityService = (AuthorityService) ctx.getBean("AuthorityService");
    personService = (PersonService) ctx.getBean("personService");
    authenticationDAO = (MutableAuthenticationDao) ctx.getBean("authenticationDao");
    aclDaoComponent = (AclDAO) ctx.getBean("aclDAO");
    nodeService = (NodeService) ctx.getBean("nodeService");
    authorityBridgeTableCache = (AuthorityBridgeTableAsynchronouslyRefreshedCache) ctx.getBean("authorityBridgeTableCache");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    transactionService = (TransactionService) ctx.getBean(ServiceRegistry.TRANSACTION_SERVICE.getLocalName());
    authorityDAO = ctx.getBean("authorityDAO", AuthorityDAO.class);
    
    String defaultAdminUser = AuthenticationUtil.getAdminUserName();
    AuthenticationUtil.setFullyAuthenticatedUser(defaultAdminUser);
    
    // cleanup trashcan
    nodeArchiveService.purgeAllArchivedNodes(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
    
    // note: currently depends on any existing (and/or bootstrap) group data - eg. default site "swsdp" (Sample Web Site Design Project)
    SiteService siteService = (SiteService) ctx.getBean("SiteService");
    SITE_CNT = siteService.listSites(defaultAdminUser).size();
    GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_GRP_CNT * SITE_CNT);
    ROOT_GRP_CNT = DEFAULT_GRP_CNT + (DEFAULT_SITE_ROOT_GRP_CNT * SITE_CNT);
    
    tx = transactionService.getUserTransaction();
    tx.begin();
    for (String user : getAllAuthorities(AuthorityType.USER))
    {
        if (user.equals(AuthenticationUtil.getGuestUserName()))
        {
            continue;
        }
        else if (user.equals(AuthenticationUtil.getAdminUserName()))
        {
            continue;
        }
        else
        {
            if (personService.personExists(user))
            {
                NodeRef person = personService.getPerson(user);
                NodeRef hf = DefaultTypeConverter.INSTANCE.convert(NodeRef.class, nodeService.getProperty(person, ContentModel.PROP_HOMEFOLDER));
                if (hf != null)
                {
                    nodeService.deleteNode(hf);
                }
                aclDaoComponent.deleteAccessControlEntries(user);
                personService.deletePerson(user);
            }
            if (authenticationDAO.userExists(user))
            {
                authenticationDAO.deleteUser(user);
            }
        }

    }
    tx.commit();

    tx = transactionService.getUserTransaction();
    tx.begin();

    if (!authenticationDAO.userExists("andy"))
    {
        authenticationService.createAuthentication("andy", "andy".toCharArray());
    }

    if (!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    }

    if (!authenticationDAO.userExists("administrator"))
    {
        authenticationService.createAuthentication("administrator", "administrator".toCharArray());
    }

}