Java Code Examples for org.alfresco.service.ServiceRegistry#getAuthenticationService()

The following examples show how to use org.alfresco.service.ServiceRegistry#getAuthenticationService() . 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: ActivitiTimerExecutionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
	 ServiceRegistry registry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
     this.workflowService = registry.getWorkflowService();
     this.authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
     this.nodeService = registry.getNodeService();
     
     this.transactionHelper = (RetryingTransactionHelper) this.applicationContext
     	.getBean("retryingTransactionHelper");
     
     this.activitiProcessEngine = (ProcessEngine) this.applicationContext.getBean("activitiProcessEngine");
     
     MutableAuthenticationService authenticationService = registry.getAuthenticationService();
     PersonService personService = registry.getPersonService();

     this.personManager = new TestPersonManager(authenticationService, personService, nodeService);
     
     authenticationComponent.setSystemUserAsCurrentUser();
}
 
Example 2
Source File: JscriptWorkflowTask.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new instance of a workflow task from a WorkflowTask from the CMR workflow object model
 * 
 * @param task
 *            an instance of WorkflowTask from CMR workflow object model
 * @param serviceRegistry
 *            Service Registry object
 */
public JscriptWorkflowTask(WorkflowTask task, 
            ServiceRegistry serviceRegistry,
            Scriptable scope)
{
    this.serviceRegistry = serviceRegistry;
    this.namespaceProvider = new DefaultNamespaceProvider(serviceRegistry.getNamespaceService());
    this.workflowService = serviceRegistry.getWorkflowService();
    this.nodeService = serviceRegistry.getNodeService();
    this.dictionaryService = serviceRegistry.getDictionaryService();
    this.authenticationService = serviceRegistry.getAuthenticationService();
    this.task = task;
    this.setScope(scope);
}
 
Example 3
Source File: FFCLoadsOfFiles.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void main(String[] args)
{
	
    // initialise app content 
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    // get registry of services
    final ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

    // authenticate
    AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
    authenticationService.authenticate(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());

    
    // use TransactionWork to wrap service calls in a user transaction
    TransactionService transactionService = serviceRegistry.getTransactionService();
    RetryingTransactionCallback<Object> exampleWork = new RetryingTransactionCallback<Object>()
    {
        public Object execute() throws Exception
        {
            doExample(serviceRegistry);
            return null;
        }
    };
    currentDoc = 0;
    while (currentDoc < totalNumDocs)
    {
        transactionService.getRetryingTransactionHelper().doInTransaction(exampleWork);
    }
    System.exit(0);
}
 
Example 4
Source File: OAuth1CredentialsStoreServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void before() throws Exception
{
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    authenticationService = serviceRegistry.getAuthenticationService();
    personService = serviceRegistry.getPersonService();
    oauth1CredentialsStoreService = (OAuth1CredentialsStoreService) applicationContext.getBean("oauth1CredentialsStoreService");

    AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
    createUser(TEST_USER_ONE);
    createUser(TEST_USER_TWO);
}
 
Example 5
Source File: OAuth2CredentialsStoreServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    transactionHelper = serviceRegistry.getTransactionService().getRetryingTransactionHelper();
    authenticationService = serviceRegistry.getAuthenticationService();
    personService = serviceRegistry.getPersonService();
    oauth2CredentialsStoreService = (OAuth2CredentialsStoreService) applicationContext.getBean("oauth2CredentialsStoreService");

    AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
    createUser(TEST_USER_ONE);
    createUser(TEST_USER_TWO);
}
 
Example 6
Source File: HttpAlfrescoStore.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void doTest(ApplicationContext ctx, String baseUrl, String contentUrl) throws Exception
{
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    TransactionService transactionService = serviceRegistry.getTransactionService();
    AuthenticationService authenticationService = serviceRegistry.getAuthenticationService();
    // Construct the store
    HttpAlfrescoStore store = new HttpAlfrescoStore();
    store.setTransactionService(transactionService);
    store.setAuthenticationService(authenticationService);
    store.setBaseHttpUrl(baseUrl);
    
    // Now test
    System.out.println(
            "   Retrieving reader for URL " + contentUrl);
    ContentReader reader = store.getReader(contentUrl);
    System.out.println(
            "   Retrieved reader for URL " + contentUrl);
    // Check if the content exists
    boolean exists = reader.exists();
    if (!exists)
    {
        System.out.println(
                "   Content doesn't exist: " + contentUrl);
        return;
    }
    else
    {
        System.out.println(
                "   Content exists: " + contentUrl);
    }
    // Get the content data
    ContentData contentData = reader.getContentData();
    System.out.println(
            "   Retrieved content data: " + contentData);
    
    // Now get the content
    ByteBuffer buffer = ByteBuffer.allocate((int)reader.getSize());
    FileChannel channel = reader.getFileChannel();
    try
    {
        int count = channel.read(buffer);
        if (count != reader.getSize())
        {
            System.err.println("The number of bytes read was " + count + " but expected " + reader.getSize());
            return;
        }
    }
    finally
    {
        channel.close();
    }
}
 
Example 7
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    transactionService = serviceRegistry.getTransactionService();
    nodeService = serviceRegistry.getNodeService();
    importerService = serviceRegistry.getImporterService();
    personService = serviceRegistry.getPersonService();
    authenticationService = serviceRegistry.getAuthenticationService();
    permissionService = serviceRegistry.getPermissionService();
    imapService = serviceRegistry.getImapService();
    searchService = serviceRegistry.getSearchService();
    namespaceService = serviceRegistry.getNamespaceService();
    fileFolderService = serviceRegistry.getFileFolderService();
    contentService = serviceRegistry.getContentService();
    
    flags = new Flags();
    flags.add(Flags.Flag.SEEN);
    flags.add(Flags.Flag.FLAGGED);
    flags.add(Flags.Flag.ANSWERED);
    flags.add(Flags.Flag.DELETED);

    // start the transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());

    // downgrade integrity
    IntegrityChecker.setWarnInTransaction();
    
    anotherUserName = "user" + System.currentTimeMillis();

    PropertyMap testUser = new PropertyMap();
    testUser.put(ContentModel.PROP_USERNAME, anotherUserName);
    testUser.put(ContentModel.PROP_FIRSTNAME, anotherUserName);
    testUser.put(ContentModel.PROP_LASTNAME, anotherUserName);
    testUser.put(ContentModel.PROP_EMAIL, anotherUserName + "@alfresco.com");
    testUser.put(ContentModel.PROP_JOBTITLE, "jobTitle");

    personService.createPerson(testUser);

    // create the ACEGI Authentication instance for the new user
    authenticationService.createAuthentication(anotherUserName, anotherUserName.toCharArray());

    user = new AlfrescoImapUser(anotherUserName + "@alfresco.com", anotherUserName, anotherUserName);

    NodeRef companyHomeNodeRef = findCompanyHomeNodeRef();

    ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap");
    ApplicationContext imapCtx = imap.getApplicationContext();
    imapServiceImpl = (ImapServiceImpl)imapCtx.getBean("imapService");

    // Creating IMAP test folder for IMAP root
    LinkedList<String> folders = new LinkedList<String>();
    folders.add(TEST_IMAP_FOLDER_NAME);
    FileFolderUtil.makeFolders(fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);
    
    // Setting IMAP root
    RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
    imapHome.setStore(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE.toString());
    imapHome.setRootPath(APP_COMPANY_HOME);
    imapHome.setFolderPath(NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME);
    imapServiceImpl.setImapHome(imapHome);
    
    // Starting IMAP
    imapServiceImpl.startupInTxn(true);

    NodeRef storeRootNodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);

    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef ,
            APP_COMPANY_HOME + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME,
            null,
            namespaceService,
            false);
    testImapFolderNodeRef = nodeRefs.get(0);

    
    /* 
     * Importing test folders:
     * 
     * Test folder contains: "___-___folder_a"
     * 
     * "___-___folder_a" contains: "___-___folder_a_a",
     *                             "___-___file_a",
     *                             "Message_485.eml" (this is IMAP Message)
     *                           
     * "___-___folder_a_a" contains: "____-____file_a_a"
     * 
     */
    importInternal("imap/imapservice_test_folder_a.acp", testImapFolderNodeRef);

    reauthenticate(anotherUserName, anotherUserName);
}
 
Example 8
Source File: ImapServiceImplCacheTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    nodeService = serviceRegistry.getNodeService();
    authenticationService = serviceRegistry.getAuthenticationService();
    imapService = serviceRegistry.getImapService();
    searchService = serviceRegistry.getSearchService();
    namespaceService = serviceRegistry.getNamespaceService();
    fileFolderService = serviceRegistry.getFileFolderService();
    contentService = serviceRegistry.getContentService();
    
    authenticationService.authenticate(USER_NAME, USER_PASSWORD.toCharArray());

    String storePath = "workspace://SpacesStore";
    String companyHomePathInStore = "/app:company_home";

    StoreRef storeRef = new StoreRef(storePath);

    NodeRef storeRootNodeRef = nodeService.getRootNode(storeRef);

    List<NodeRef> nodeRefs = searchService.selectNodes(storeRootNodeRef, companyHomePathInStore, null, namespaceService, false);
    NodeRef companyHomeNodeRef = nodeRefs.get(0);

    ChildApplicationContextFactory imap = (ChildApplicationContextFactory) ctx.getBean("imap");
    ApplicationContext imapCtx = imap.getApplicationContext();
    final ImapServiceImpl imapServiceImpl = (ImapServiceImpl)imapCtx.getBean("imapService");

    // Creating IMAP test folder for IMAP root
    LinkedList<String> folders = new LinkedList<String>();
    folders.add(TEST_IMAP_FOLDER_NAME);
    FileInfo folder = FileFolderUtil.makeFolders(fileFolderService, companyHomeNodeRef, folders, ContentModel.TYPE_FOLDER);
    oldFile = fileFolderService.create(folder.getNodeRef(), "oldFile", ContentModel.TYPE_CONTENT);
    
    // Setting IMAP root
    RepositoryFolderConfigBean imapHome = new RepositoryFolderConfigBean();
    imapHome.setStore(storePath);
    imapHome.setRootPath(companyHomePathInStore);
    imapHome.setFolderPath(NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME);
    imapServiceImpl.setImapHome(imapHome);
    
    // Starting IMAP
    imapServiceImpl.startupInTxn(true);
    
    nodeRefs = searchService.selectNodes(storeRootNodeRef,
            companyHomePathInStore + "/" + NamespaceService.CONTENT_MODEL_PREFIX + ":" + TEST_IMAP_FOLDER_NAME,
            null,
            namespaceService,
            false);
    testImapFolderNodeRef = nodeRefs.get(0);

}
 
Example 9
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 10
Source File: ArchiveAndRestoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    
    ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
    nodeArchiveService = (NodeArchiveService) ctx.getBean("nodeArchiveService");
    nodeService = serviceRegistry.getNodeService();
    permissionService = serviceRegistry.getPermissionService();
    authenticationService = serviceRegistry.getAuthenticationService();
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    ownableService = (OwnableService) ctx.getBean("ownableService");
    transactionService = serviceRegistry.getTransactionService();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");

    ClassLoader cl = ArchiveAndRestoreTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/archive/archiveTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    // Start a transaction
    txn = transactionService.getUserTransaction();
    txn.begin();
    
    // downgrade integrity checks
    IntegrityChecker.setWarnInTransaction();
    
    try
    {
        authenticationComponent.setSystemUserAsCurrentUser();
        // Create the work store
        workStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, getName() + System.currentTimeMillis());
        workStoreRootNodeRef = nodeService.getRootNode(workStoreRef);
        archiveStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "archive" + getName() + System.currentTimeMillis());
        archiveStoreRootNodeRef = nodeService.getRootNode(archiveStoreRef);
        
        // Map the work store to the archive store.  This will already be wired into the NodeService.
        StoreArchiveMap archiveMap = (StoreArchiveMap) ctx.getBean("storeArchiveMap");
        archiveMap.put(workStoreRef, archiveStoreRef);
        
        TestWithUserUtils.createUser(USER_A, USER_A, workStoreRootNodeRef, nodeService, authenticationService);
        TestWithUserUtils.createUser(USER_B, USER_B, workStoreRootNodeRef, nodeService, authenticationService);
        TestWithUserUtils.createUser(USER_C, USER_C, workStoreRootNodeRef, nodeService, authenticationService);
        // grant A and B rights to the work store
        permissionService.setPermission(
                workStoreRootNodeRef,
                USER_A,
                PermissionService.ALL_PERMISSIONS,
                true);
        permissionService.setPermission(
                workStoreRootNodeRef,
                USER_B,
                PermissionService.ALL_PERMISSIONS,
                true);
        permissionService.setPermission(
                workStoreRootNodeRef,
                USER_C,
                PermissionService.ALL_PERMISSIONS,
                false);
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
    // authenticate as normal user
    authenticationService.authenticate(USER_A, USER_A.toCharArray());
    createNodeStructure();
}
 
Example 11
Source File: IncompleteNodeTaggerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setUp() throws Exception
{
    ApplicationContext ctx = ApplicationContextHelper.getApplicationContext();
    DictionaryDAO dictionaryDao = (DictionaryDAO) ctx.getBean("dictionaryDAO");
    ClassLoader cl = BaseNodeServiceTest.class.getClassLoader();
    // load the test model
    InputStream modelStream = cl.getResourceAsStream("org/alfresco/repo/node/integrity/IntegrityTest_model.xml");
    assertNotNull(modelStream);
    M2Model model = M2Model.createModel(modelStream);
    dictionaryDao.putModel(model);

    tagger = (IncompleteNodeTagger) ctx.getBean("incompleteNodeTagger");

    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    authenticationService = serviceRegistry.getAuthenticationService();
    permissionService = serviceRegistry.getPermissionService();
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    String user = getName();
    if (!authenticationService.authenticationExists(user))
    {
        authenticationService.createAuthentication(user, user.toCharArray());
    }
    
    // begin a transaction
    TransactionService transactionService = serviceRegistry.getTransactionService();
    txn = transactionService.getUserTransaction();
    txn.begin();
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
        rootNodeRef = nodeService.getRootNode(storeRef);
        // Make sure our user can do everything
        permissionService.setPermission(rootNodeRef, user, PermissionService.ALL_PERMISSIONS, true);
    }
    else
    {
        rootNodeRef = nodeService.getRootNode(storeRef);
    }
    
    properties = new PropertyMap();
    properties.put(IntegrityTest.TEST_PROP_TEXT_C, "abc");
    
    // Authenticate as a test-specific user
    authenticationComponent.setCurrentUser(user);
}