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

The following examples show how to use org.alfresco.service.cmr.security.MutableAuthenticationService. 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: 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 #2
Source File: FileImporterTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void setUp()
{
    ctx = ApplicationContextHelper.getApplicationContext();
    serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);

    nodeService = serviceRegistry.getNodeService();
    searchService = serviceRegistry.getSearchService();
    dictionaryService = serviceRegistry.getDictionaryService();
    contentService = serviceRegistry.getContentService();
    authenticationService = (MutableAuthenticationService) ctx.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    permissionService = serviceRegistry.getPermissionService();
    mimetypeService = serviceRegistry.getMimetypeService();
    namespaceService = serviceRegistry.getNamespaceService();
    transactionService = serviceRegistry.getTransactionService();

    authenticationComponent.setSystemUserAsCurrentUser();
    StoreRef storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    rootNodeRef = nodeService.getRootNode(storeRef);
}
 
Example #3
Source File: MessageServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    applicationContext = ApplicationContextHelper.getApplicationContext();
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        fail("Detected a leaked transaction from a previous test.");
    }
    
    // Get the services by name from the application context
    messageService = (MessageService)applicationContext.getBean("messageService");
    nodeService = (NodeService)applicationContext.getBean("NodeService");
    authenticationService = (MutableAuthenticationService)applicationContext.getBean("AuthenticationService");
    contentService = (ContentService) applicationContext.getBean("ContentService");
    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    dictionaryDAO = (DictionaryDAO) applicationContext.getBean("dictionaryDAO");
    
    // Re-set the current locale to be the default
    Locale.setDefault(Locale.ENGLISH);
    messageService.setLocale(Locale.getDefault());
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();
    authenticationComponent.setSystemUserAsCurrentUser();
}
 
Example #4
Source File: FeedControlTest.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.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    
    // Create users
    createUser(TEST_USER);
    
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(TEST_USER);
}
 
Example #5
Source File: TestWithUserUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Authenticate as the given user.  If the user does not exist, then authenticate as the system user
 * and create the authentication first.
 */
public static void authenticateUser(
        String userName,
        String password,
        MutableAuthenticationService authenticationService,
        AuthenticationComponent authenticationComponent)
{
    // go system
    try
    {
        authenticationComponent.setSystemUserAsCurrentUser();
        if (!authenticationService.authenticationExists(userName))
        {
            authenticationService.createAuthentication(userName, password.toCharArray());
        }
    }
    finally
    {
        authenticationComponent.clearCurrentSecurityContext();
    }
    authenticationService.authenticate(userName, password.toCharArray());
}
 
Example #6
Source File: CommentsTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@BeforeClass public static void initBasicServices() throws Exception
{
    behaviourFilter = (BehaviourFilter)APP_CONTEXT_INIT.getApplicationContext().getBean("policyBehaviourFilter");
    contentService = (ContentService)APP_CONTEXT_INIT.getApplicationContext().getBean("ContentService");
    nodeService = (NodeService)APP_CONTEXT_INIT.getApplicationContext().getBean("NodeService");
    repositoryHelper = (Repository)APP_CONTEXT_INIT.getApplicationContext().getBean("repositoryHelper");
    siteService = (SiteService)APP_CONTEXT_INIT.getApplicationContext().getBean("SiteService");
    transactionHelper = (RetryingTransactionHelper)APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper");

    authenticationComponent = (AuthenticationComponent)APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationComponent");
    commentService = (CommentService)APP_CONTEXT_INIT.getApplicationContext().getBean("commentService");
    authenticationService = (MutableAuthenticationService)APP_CONTEXT_INIT.getApplicationContext().getBean("AuthenticationService");
    personService = (PersonService)APP_CONTEXT_INIT.getApplicationContext().getBean("PersonService");
    postDAO = (ActivityPostDAO)APP_CONTEXT_INIT.getApplicationContext().getBean("postDAO");
    permissionServiceImpl = (PermissionServiceImpl)APP_CONTEXT_INIT.getApplicationContext().getBean("permissionServiceImpl");
    permissionModelDAO = (ModelDAO)APP_CONTEXT_INIT.getApplicationContext().getBean("permissionsModelDAO");
    lockService = (LockService)APP_CONTEXT_INIT.getApplicationContext().getBean("lockService");

    COMPANY_HOME = repositoryHelper.getCompanyHome();
}
 
Example #7
Source File: BaseAlfrescoSpringTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Before
public void before() throws Exception
{
    // Get a reference to the node service
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) this.applicationContext.getBean("authenticationService");
    this.actionService = (ActionService)this.applicationContext.getBean("actionService");
    this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");

    // Authenticate as the system user
    authenticationComponent = (AuthenticationComponent) this.applicationContext
            .getBean("authenticationComponent");
    authenticationComponent.setSystemUserAsCurrentUser();
    
    // Create the store and get the root node
    this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.storeRef);
}
 
Example #8
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 #9
Source File: PersonSearchTest.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.authenticationComponent.setSystemUserAsCurrentUser();
    
    // Create users
    createUser(USER_ONE);
    createUser(USER_TWO);
    createUser(USER_THREE);
    
    // Do tests as user one
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example #10
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 #11
Source File: BlogServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
public void before() throws Exception
{
    AUTHENTICATION_SERVICE = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
    BEHAVIOUR_FILTER       = (BehaviourFilter)applicationContext.getBean("policyBehaviourFilter");
    BLOG_SERVICE           = (BlogService)applicationContext.getBean("blogService");
    DICTIONARY_SERVICE     = (DictionaryService)applicationContext.getBean("dictionaryService");
    NODE_SERVICE           = (NodeService)applicationContext.getBean("nodeService");
    PERSON_SERVICE         = (PersonService)applicationContext.getBean("personService");
    TRANSACTION_HELPER     = (RetryingTransactionHelper)applicationContext.getBean("retryingTransactionHelper");
    SITE_SERVICE           = (SiteService)applicationContext.getBean("siteService");
    TAGGING_SERVICE        = (TaggingService)applicationContext.getBean("TaggingService");

    AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
    createUser(TEST_USER);

    // We need to create the test site as the test user so that they can contribute content to it in tests below.
    AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER);
    createTestSiteWithBlogContainer();
    AuthenticationUtil.setFullyAuthenticatedUser(ADMIN_USER);
}
 
Example #12
Source File: NodeWebScripTest.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();
    
    AbstractRefreshableApplicationContext ctx = (AbstractRefreshableApplicationContext)getServer().getApplicationContext();
    this.retryingTransactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
    this.authenticationService = (MutableAuthenticationService)ctx.getBean("AuthenticationService");
    this.personService = (PersonService)ctx.getBean("PersonService");
    this.siteService = (SiteService)ctx.getBean("SiteService");
    this.nodeService = (NodeService)ctx.getBean("NodeService");
    this.nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
    this.checkOutCheckInService = (CheckOutCheckInService)ctx.getBean("checkOutCheckInService");
    this.permissionService = (PermissionService)ctx.getBean("permissionService");
    
    // Do the setup as admin
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();

    // Create a site
    TEST_SITE = createSite(TEST_SITE_NAME);
    
    // Create two users, one who's a site member
    createUser(USER_ONE, true);
    createUser(USER_TWO, false);
    
    // Do our tests by default as the first user who is a contributor
    AuthenticationUtil.setFullyAuthenticatedUser(USER_ONE);
}
 
Example #13
Source File: CustomModelImportTest.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);
    customModelService = getServer().getApplicationContext().getBean("customModelService", CustomModelService.class);

    AuthenticationUtil.clearCurrentSecurityContext();

    AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
    {
        @Override
        public Void doWork() throws Exception
        {
            createUser(NON_ADMIN_USER);
            createUser(CUSTOM_MODEL_ADMIN);

            if (!authorityService.getContainingAuthorities(AuthorityType.GROUP, CUSTOM_MODEL_ADMIN, true).contains(
                        CustomModelServiceImpl.GROUP_ALFRESCO_MODEL_ADMINISTRATORS_AUTHORITY))
            {
                authorityService.addAuthority(CustomModelServiceImpl.GROUP_ALFRESCO_MODEL_ADMINISTRATORS_AUTHORITY, CUSTOM_MODEL_ADMIN);
            }
            return null;
        }
    });
    AuthenticationUtil.setFullyAuthenticatedUser(CUSTOM_MODEL_ADMIN);
}
 
Example #14
Source File: SubsystemChainingAuthenticationService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public MutableAuthenticationService getMutableAuthenticationService()
{
    this.lock.readLock().lock();
    try
    {
        refreshBeans();
        for (String instance : this.instanceIds)
        {
            AuthenticationService authenticationService = (AuthenticationService) this.sourceBeans.get(instance);
            // Only add active authentication services. E.g. we might have an ldap context that is only used for
            // synchronizing
            if (authenticationService instanceof MutableAuthenticationService
                    && (!(authenticationService instanceof ActivateableBean) || ((ActivateableBean) authenticationService)
                            .isActive()))
            {

                return (MutableAuthenticationService) authenticationService;
            }
        }
        return null;
    }
    finally
    {
        this.lock.readLock().unlock();
    }
}
 
Example #15
Source File: ResetPasswordServiceImplTest.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
{
    resetPasswordService = APP_CONTEXT_INIT.getApplicationContext().getBean("resetPasswordService", ResetPasswordServiceImpl.class);
    resetPasswordService.setSendEmailAsynchronously(false);
    resetPasswordService.setDefaultEmailSender(DEFAULT_SENDER);
    authenticationService = APP_CONTEXT_INIT.getApplicationContext().getBean("authenticationService", MutableAuthenticationService.class);
    transactionHelper = APP_CONTEXT_INIT.getApplicationContext().getBean("retryingTransactionHelper", RetryingTransactionHelper.class);
    personService = APP_CONTEXT_INIT.getApplicationContext().getBean("personService", PersonService.class);
    globalProperties = APP_CONTEXT_INIT.getApplicationContext().getBean("global-properties", Properties.class);
    workflowService = APP_CONTEXT_INIT.getApplicationContext().getBean("WorkflowService", WorkflowService.class);
    emailUtil = new EmailUtil(APP_CONTEXT_INIT.getApplicationContext());
    emailUtil.reset();

    String userName = "jane.doe" + System.currentTimeMillis();
    testPerson = new TestPerson()
                .setUserName(userName)
                .setFirstName("Jane")
                .setLastName("doe")
                .setPassword("password")
                .setEmail(userName + "@example.com");

    transactionHelper.doInTransaction((RetryingTransactionCallback<Void>) () ->
    {
        createUser(testPerson);
        return null;
    });

}
 
Example #16
Source File: InvitationWebScriptTest.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();

    this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean(
                "AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent) getServer().getApplicationContext().getBean(
                "authenticationComponent");
    this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    this.transactionService = (TransactionService) getServer().getApplicationContext().getBean("TransactionService");
    this.invitationServiceImpl = (InvitationServiceImpl) getServer().getApplicationContext().getBean("invitationService");
    
    // turn off email sending to prevent errors during unit testing 
    // (or sending out email by accident from tests)
    InviteServiceTest.configureMailExecutorForTestMode(this.getServer());
    
    this.authenticationComponent.setSystemUserAsCurrentUser();

    // Create users
    createUser(userOne, "Joe", "Bloggs");
    createUser(userTwo, "Jane", "Doe");
    createUser(userThree, "Nick", "Smith");

    // Do tests as user one
    this.authenticationComponent.setCurrentUser(userOne);
}
 
Example #17
Source File: AbstractChainingAuthenticationService.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean isAuthenticationCreationAllowed()
{
    MutableAuthenticationService mutableAuthenticationService = getMutableAuthenticationService();
    return mutableAuthenticationService == null ? false : mutableAuthenticationService
            .isAuthenticationCreationAllowed();
}
 
Example #18
Source File: TransactionCleanupTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
  @Before
  public void before()
  {
  	ServiceRegistry serviceRegistry = (ServiceRegistry)ctx.getBean("ServiceRegistry");
      NamespaceService namespaceService = serviceRegistry.getNamespaceService();
this.transactionService = serviceRegistry.getTransactionService();
this.authenticationService = (MutableAuthenticationService)ctx.getBean("authenticationService");
this.nodeService = serviceRegistry.getNodeService();
this.searchService = serviceRegistry.getSearchService();
this.nodeDAO = (NodeDAO)ctx.getBean("nodeDAO");
this.nodesCache = (SimpleCache<Serializable, Serializable>) ctx.getBean("node.nodesSharedCache");
      this.worker = (DeletedNodeCleanupWorker)ctx.getBean("nodeCleanup.deletedNodeCleanup");
      this.worker.setMinPurgeAgeDays(0);

  	this.helper = transactionService.getRetryingTransactionHelper();
      authenticationService.authenticate("admin", "admin".toCharArray());
      
StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, "SpacesStore");
NodeRef storeRoot = nodeService.getRootNode(storeRef);
List<NodeRef> nodeRefs = searchService.selectNodes(
        storeRoot, "/app:company_home", null, namespaceService, false);
final NodeRef companyHome = nodeRefs.get(0);

  	RetryingTransactionHelper.RetryingTransactionCallback<NodeRef> createNode = new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
  	{
	@Override
	public NodeRef execute() throws Throwable
	{
		return nodeService.createNode(companyHome, ContentModel.ASSOC_CONTAINS, QName.createQName("test", GUID.generate()), ContentModel.TYPE_CONTENT).getChildRef();
	}
  	};
  	this.nodeRef1 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef2 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef3 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef4 = helper.doInTransaction(createNode, false, true);
  	this.nodeRef5 = helper.doInTransaction(createNode, false, true);
  }
 
Example #19
Source File: NodeArchiveServiceRestApiTest.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();

    // Initialise the required services.
    nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    nodeArchiveService = (NodeArchiveService) getServer().getApplicationContext().getBean("nodeArchiveService"); // Intentionally small 'n'.
    transactionHelper = (RetryingTransactionHelper) getServer().getApplicationContext().getBean("retryingTransactionHelper");
    personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    authenticationService = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    archiveMap = (StoreArchiveMap) getServer().getApplicationContext().getBean("storeArchiveMap");

    // Create Root node for the tests
    workStoreRootNodeRef = createTestStoreAndGetRootNode();

    // Create users
    createUser(USER_ONE);
    createUser(USER_TWO);

    // Create some nodes which we will delete as part of later test methods.
    adminUndeletedTestNode = createTestNode(AuthenticationUtil.getAdminUserName(), createNodeName(), false);
    createdNodes.add(adminUndeletedTestNode);
    // We need to remember the StoreRef where this node originally lived. i.e. workspace://SpacesStore
    nodesOriginalStoreRef = adminUndeletedTestNode.getStoreRef();
    // This will ensure that there is always at least some NodeRefs in the 'trash' i.e. the archive store.
    adminDeletedTestNode = createTestNode(AuthenticationUtil.getAdminUserName(), createNodeName(), true);
    createdNodes.add(adminDeletedTestNode);

    // User_1 creates and deletes a node
    user1_DeletedTestNode = createTestNode(USER_ONE, createNodeName(), true);
    createdNodes.add(user1_DeletedTestNode);

    // User_2 creates and deletes a node
    user2_DeletedTestNode = createTestNode(USER_TWO, createNodeName(), true);
    createdNodes.add(user2_DeletedTestNode);
}
 
Example #20
Source File: CalendarRestApiTest.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();
    
    this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
    this.permissionService = (PermissionService)getServer().getApplicationContext().getBean("PermissionService");
    this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
    this.nodeService = (NodeService)getServer().getApplicationContext().getBean("NodeService");
    this.siteService = (SiteService)getServer().getApplicationContext().getBean("SiteService");
    this.nodeArchiveService = (NodeArchiveService)getServer().getApplicationContext().getBean("nodeArchiveService");
    
    // Authenticate as user
    this.authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
    
    // Create test site
    // - only create the site if it doesn't already exist
    SiteInfo siteInfo = this.siteService.getSite(SITE_SHORT_NAME_CALENDAR);
    if (siteInfo == null)
    {
        this.siteService.createSite("CalendarSitePreset", SITE_SHORT_NAME_CALENDAR, "CalendarSiteTitle", "BlogSiteDescription", SiteVisibility.PUBLIC);
    }
    
    // Ensure the calendar container is there
    if (!siteService.hasContainer(SITE_SHORT_NAME_CALENDAR, CalendarServiceImpl.CALENDAR_COMPONENT))
    {
        siteService.createContainer(SITE_SHORT_NAME_CALENDAR, CalendarServiceImpl.CALENDAR_COMPONENT, null, null);
    }
    
    // Create users
    createUser(USER_ONE, SiteModel.SITE_COLLABORATOR);
    createUser(USER_TWO, SiteModel.SITE_COLLABORATOR);
    createUser(USER_THREE, SiteModel.SITE_CONTRIBUTOR);
    createUser(USER_FOUR, SiteModel.SITE_CONSUMER);

    // Do tests as inviter user
    this.authenticationComponent.setCurrentUser(USER_ONE);
}
 
Example #21
Source File: TransactionServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    transactionManager = (PlatformTransactionManager) applicationContext.getBean("transactionManager");
    transactionService = new TransactionServiceImpl();
    transactionService.setTransactionManager(transactionManager);
    transactionService.setAllowWrite(true, vetoName);

    nodeService = (NodeService) applicationContext.getBean("dbNodeService");
    authenticationService = (MutableAuthenticationService) applicationContext.getBean("AuthenticationService");
    personService = (PersonService) applicationContext.getBean("PersonService");

    dialect = (Dialect) applicationContext.getBean("dialect");
}
 
Example #22
Source File: RatingRestApiTest.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 = (MutableAuthenticationService) getServer().getApplicationContext().getBean("AuthenticationService");
    nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    repositoryHelper = (Repository) getServer().getApplicationContext().getBean("repositoryHelper");
    transactionHelper = (RetryingTransactionHelper)getServer().getApplicationContext().getBean("retryingTransactionHelper");  
    
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    
    // Create some users to rate each other's content
    // and a test node which we will rate.
    // It doesn't matter that it has no content.
    testNode = transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<NodeRef>()
            {
                public NodeRef execute() throws Throwable
                {
                    createUser(USER_ONE);
                    createUser(USER_TWO);

                    ChildAssociationRef result = nodeService.createNode(repositoryHelper.getCompanyHome(),
                                                            ContentModel.ASSOC_CONTAINS, ContentModel.ASSOC_CONTAINS,
                                                            ContentModel.TYPE_CONTENT, null);
                    return result.getChildRef();
                }          
            });        
}
 
Example #23
Source File: ContentGetTest.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();

    this.authenticationService = (MutableAuthenticationService) getServer().getApplicationContext()
            .getBean("AuthenticationService");
    this.personService = (PersonService) getServer().getApplicationContext().getBean("PersonService");
    this.nodeService = (NodeService) getServer().getApplicationContext().getBean("NodeService");
    this.contentService = (ContentService) getServer().getApplicationContext().getBean("ContentService");
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    createUser(USER_ONE);
}
 
Example #24
Source File: LoginTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
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.authenticationComponent.setSystemUserAsCurrentUser();
	createUser(USER_ONE, USER_ONE);
}
 
Example #25
Source File: RuleServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
  public void before() throws Exception
  {
      super.before();
      this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
this.authenticationService = (MutableAuthenticationService)this.applicationContext.getBean("authenticationService");
      this.searchService = (SearchService) applicationContext.getBean("SearchService");
      this.namespaceService = (NamespaceService) applicationContext.getBean("NamespaceService");
      this.fileFolderService = (FileFolderService) applicationContext.getBean("FileFolderService");
  }
 
Example #26
Source File: CheckOutCheckInServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * On setup in transaction implementation
 */
@Before
public void before()
{
    // Set the services
    this.cociService = (CheckOutCheckInService)this.applicationContext.getBean("checkOutCheckInService");
    this.contentService = (ContentService)this.applicationContext.getBean("contentService");
    this.versionService = (VersionService)this.applicationContext.getBean("versionService");
    this.authenticationService = (MutableAuthenticationService)this.applicationContext.getBean("authenticationService");
    this.lockService = (LockService)this.applicationContext.getBean("lockService");
    this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
    this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
    this.copyService = (CopyService)this.applicationContext.getBean("copyService");
    this.personService = (PersonService) this.applicationContext.getBean("PersonService");
    ServiceRegistry serviceRegistry = (ServiceRegistry) this.applicationContext.getBean("ServiceRegistry");
    this.fileFolderService = serviceRegistry.getFileFolderService();
    this.nodeService = serviceRegistry.getNodeService();
    
    // Authenticate as system to create initial test data set
    this.authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
    authenticationComponent.setSystemUserAsCurrentUser();
    
    RetryingTransactionCallback<Void> processInitWork = new RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            initTestData();
            return null;
        }
    };
    // do the init test data in a new retrying transaction because
    // there may be problems with the DB that needs to be retried; 
    // That is how Alfresco works, it relies on optimistic locking and retries
    transactionService.getRetryingTransactionHelper().doInTransaction(processInitWork, false, true);

}
 
Example #27
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 #28
Source File: MultiTServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    multiTServiceImpl = applicationContext.getBean("tenantService", MultiTServiceImpl.class);
    tenantAdminService = applicationContext.getBean("tenantAdminService", TenantAdminService.class);
    personService = applicationContext.getBean("PersonService", PersonService.class);
    tenantService = applicationContext.getBean("tenantService", TenantService.class);
    authenticationService = applicationContext.getBean("AuthenticationService", MutableAuthenticationService.class);
    transactionService = applicationContext.getBean("TransactionService", TransactionService.class);
    nodeService = applicationContext.getBean("NodeService", NodeService.class);
    searchService = applicationContext.getBean("SearchService", SearchService.class);
    namespaceService = applicationContext.getBean("NamespaceService", NamespaceService.class);

    DOMAIN = GUID.generate();
    USER1 = GUID.generate();
    USER2 = GUID.generate();
    USER3 = GUID.generate();
    USER2_WITH_DOMAIN = USER2 + TenantService.SEPARATOR + DOMAIN;
    STRING = GUID.generate();
    TENANT_STRING = addDomainToId(STRING, DOMAIN);
    STRING_WITH_EXISTENT_DOMAIN = TenantService.SEPARATOR + DOMAIN + TenantService.SEPARATOR;
    STRING_WITH_NONEXITENT_DOMAIN = TenantService.SEPARATOR + STRING + TenantService.SEPARATOR;
    TENANT_STORE = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, addDomainToId("SpacesStore", DOMAIN));
    TENANT_NODE_REF = new NodeRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN), ID);
    TENANT_STORE_REF = new StoreRef(PROTOCOL, addDomainToId(IDENTIFIER, DOMAIN));
    TENANT_QNAME = QName.createQName(addDomainToId(NAMESPACE_URI, DOMAIN), LOCAL_NAME);
    tenantAssocRef = new AssociationRef(TENANT_NODE_REF, QNAME, TENANT_NODE_REF);
    childAssocRef = new ChildAssociationRef(QNAME, NODE_REF, QNAME, NODE_REF);
    tenantChildAssocRef = new ChildAssociationRef(QNAME, TENANT_NODE_REF, QNAME, TENANT_NODE_REF);

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    mtEnabled = AuthenticationUtil.isMtEnabled();
    AuthenticationUtil.setMtEnabled(false);
}
 
Example #29
Source File: TransferWebScriptTest.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();       
 
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
    this.authenticationService = (MutableAuthenticationService)getServer().getApplicationContext().getBean("AuthenticationService");
    this.authenticationComponent = (AuthenticationComponent)getServer().getApplicationContext().getBean("authenticationComponent");
    this.personService = (PersonService)getServer().getApplicationContext().getBean("PersonService");
    
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // Create users
    createUser(USERNAME);
}
 
Example #30
Source File: RepoTransferReceiverImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void before() throws Exception
{
    super.before();
    System.out.println("java.io.tmpdir == " + System.getProperty("java.io.tmpdir"));

    // Get the required services
    this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
    this.contentService = (ContentService) this.applicationContext.getBean("contentService");
    this.authenticationService = (MutableAuthenticationService) this.applicationContext
            .getBean("authenticationService");
    this.actionService = (ActionService) this.applicationContext.getBean("actionService");
    this.transactionService = (TransactionService) this.applicationContext.getBean("transactionComponent");
    this.authenticationComponent = (AuthenticationComponent) this.applicationContext
            .getBean("authenticationComponent");
    this.receiver = (RepoTransferReceiverImpl) this.applicationContext.getBean("transferReceiver");
    this.policyComponent = (PolicyComponent) this.applicationContext.getBean("policyComponent");
    this.searchService = (SearchService) this.applicationContext.getBean("searchService");
    this.repositoryHelper = (Repository) this.applicationContext.getBean("repositoryHelper");
    this.namespaceService = (NamespaceService) this.applicationContext.getBean("namespaceService");
    this.dummyContent = "This is some dummy content.";        
    this.dummyContentBytes = dummyContent.getBytes("UTF-8");
    authenticationComponent.setSystemUserAsCurrentUser();

    guestHome = repositoryHelper.getGuestHome();
    TestTransaction.flagForCommit();
    TestTransaction.end();
}