org.alfresco.repo.policy.PolicyComponent Java Examples

The following examples show how to use org.alfresco.repo.policy.PolicyComponent. 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: ScriptBehaviourTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Before
   public void before() throws Exception
   {
	// Get the required services
	this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
	this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
	this.serviceRegistry = (ServiceRegistry)this.applicationContext.getBean("ServiceRegistry");
	
	AuthenticationComponent authenticationComponent = (AuthenticationComponent)this.applicationContext.getBean("authenticationComponent");
	authenticationComponent.setCurrentUser(AuthenticationUtil.getAdminUserName());
	
	// Create the store and get the root node reference
	this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
	NodeRef rootNodeRef = this.nodeService.getRootNode(storeRef);
	
	// Create folder node
	Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
	props.put(ContentModel.PROP_NAME, "TestFolder");
	ChildAssociationRef childAssocRef = this.nodeService.createNode(
			rootNodeRef,
			ContentModel.ASSOC_CHILDREN,
			QName.createQName("{test}TestFolder"),
			ContentModel.TYPE_FOLDER,
			props);
	this.folderNodeRef = childAssocRef.getChildRef();
}
 
Example #2
Source File: NodeMonitor.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Class constructor
 * 
 * @param filesysCtx ContentContext
 * @param nodeService NodeService
 * @param policyComponent PolicyComponent
 * @param fileFolderService FileFolderService
 * @param permissionService PermissionService
 * @param transService TransactionService
 */
protected NodeMonitor(ContentContext filesysCtx, NodeService nodeService, PolicyComponent policyComponent,
		FileFolderService fileFolderService, PermissionService permissionService, TransactionService transService) {
	m_filesysCtx    = filesysCtx;
	
	// Set various services

	m_nodeService       = nodeService;
	m_policyComponent   = policyComponent;
	m_fileFolderService = fileFolderService;
	m_permissionService = permissionService;
	m_transService      = transService;
	
	// Initialize the node monitor
	
	init();
}
 
Example #3
Source File: WebDAVonContentUpdateTest.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
{
    searchService = ctx.getBean("SearchService", SearchService.class);
    fileFolderService = ctx.getBean("FileFolderService", FileFolderService.class);
    nodeService = ctx.getBean("NodeService", NodeService.class);
    transactionService = ctx.getBean("transactionService", TransactionService.class);
    webDAVHelper = ctx.getBean("webDAVHelper", WebDAVHelper.class);
    lockService = ctx.getBean("LockService", LockService.class);
    policyComponent = ctx.getBean("policyComponent", PolicyComponent.class);
    namespaceService = ctx.getBean("namespaceService", NamespaceService.class);

    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());

    repositoryHelper = (Repository)ctx.getBean("repositoryHelper");
    companyHomeNodeRef = repositoryHelper.getCompanyHome();

    InputStream testDataIS = getClass().getClassLoader().getResourceAsStream(TEST_DATA_FILE_NAME);
    InputStream davLockInfoIS = getClass().getClassLoader().getResourceAsStream(DAV_LOCK_INFO_XML);
    testDataFile = IOUtils.toByteArray(testDataIS);
    davLockInfoFile = IOUtils.toByteArray(davLockInfoIS);
    testDataIS.close();
    davLockInfoIS.close();

    txn = transactionService.getUserTransaction();
    txn.begin();
}
 
Example #4
Source File: ImapServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
protected void bindBehaviour()
{
    if (logger.isDebugEnabled())
    {
        logger.debug("[bindBeahaviour] Binding behaviours");
    }
    PolicyComponent policyComponent = (PolicyComponent) serviceRegistry.getService(QName.createQName(NamespaceService.ALFRESCO_URI, "policyComponent"));

    // Only listen to folders we've tagged with imap properties - not all folders or we'll really slow down the repository!
    policyComponent.bindAssociationBehaviour(
            OnCreateChildAssociationPolicy.QNAME,
            ImapModel.ASPECT_IMAP_FOLDER,
            ContentModel.ASSOC_CONTAINS,
            new JavaBehaviour(this, "onCreateChildAssociation", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindAssociationBehaviour(
            OnDeleteChildAssociationPolicy.QNAME,
            ImapModel.ASPECT_IMAP_FOLDER,
            ContentModel.ASSOC_CONTAINS,
            new JavaBehaviour(this, "onDeleteChildAssociation", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindClassBehaviour(
            OnUpdatePropertiesPolicy.QNAME,
            ContentModel.TYPE_CONTENT,
            new JavaBehaviour(this, "onUpdateProperties", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindClassBehaviour(
            BeforeDeleteNodePolicy.QNAME,
            ContentModel.TYPE_CONTENT,
            new JavaBehaviour(this, "beforeDeleteNode", NotificationFrequency.EVERY_EVENT));
    policyComponent.bindClassBehaviour(
            OnRestoreNodePolicy.QNAME,
            ContentModel.TYPE_CONTENT,
            new JavaBehaviour(this, "onRestoreNode", NotificationFrequency.EVERY_EVENT));
}
 
Example #5
Source File: AbstractFeedCleanerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    JobLockService jobLockService = (JobLockService) ctx.getBean("JobLockService");
    PolicyComponent policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    NodeService nodeService = (NodeService) ctx.getBean("NodeService");

    siteService = (SiteService) ctx.getBean("SiteService");
    personService = (PersonService) ctx.getBean("PersonService");
    feedDAO = (ActivityFeedDAO) ctx.getBean("feedDAO");
    transactionHelper = (RetryingTransactionHelper)ctx.getBean("retryingTransactionHelper");
    nodeArchiveService = (NodeArchiveService)ctx.getBean("nodeArchiveService");
    
    // Let's shut down the scheduler so that we aren't competing with the scheduled versions of jobs (ie. feed cleaner)
    Scheduler scheduler = (Scheduler) ctx.getBean("schedulerFactory");
    scheduler.shutdown();
    
    tearDown();
    
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    for (int i = 1; i <= 7; i++)
    {
        siteService.createSite("myPreset", "testSite"+i, null, null, SiteVisibility.PUBLIC);
    }
    
    AuthenticationUtil.setRunAsUserSystem();
    
    // construct the test cleaner
    cleaner = new FeedCleaner();
    cleaner.setFeedDAO(feedDAO);
    cleaner.setPolicyComponent(policyComponent);
    cleaner.setJobLockService(jobLockService);
    cleaner.setNodeService(nodeService);
}
 
Example #6
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();
}
 
Example #7
Source File: RoutingContentServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setUp() throws Exception
{
    ctx = ApplicationContextHelper.getApplicationContext();
    transactionService = (TransactionService) ctx.getBean("TransactionService");
    nodeService = (NodeService) ctx.getBean("NodeService");
    contentService = (ContentService) ctx.getBean(ServiceRegistry.CONTENT_SERVICE.getLocalName());
    copyService = (CopyService) ctx.getBean("CopyService");
    this.policyComponent = (PolicyComponent) ctx.getBean("policyComponent");
    this.authenticationComponent = (AuthenticationComponent) ctx.getBean("authenticationComponent");
    
    // authenticate
    this.authenticationComponent.setSystemUserAsCurrentUser();
    
    // start the transaction
    txn = getUserTransaction();
    txn.begin();
    
    // create a store and get the root node
    StoreRef storeRef = new StoreRef(StoreRef.PROTOCOL_WORKSPACE, getName());
    if (!nodeService.exists(storeRef))
    {
        storeRef = nodeService.createStore(storeRef.getProtocol(), storeRef.getIdentifier());
    }
    rootNodeRef = nodeService.getRootNode(storeRef);

    ChildAssociationRef assocRef = nodeService.createNode(
            rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName(TEST_NAMESPACE, GUID.generate()),
            ContentModel.TYPE_CONTENT);
    contentNodeRef = assocRef.getChildRef();

    ContentWriter writer = contentService.getWriter(contentNodeRef, ContentModel.PROP_CONTENT, true);
    writer.setEncoding("UTF-16");
    writer.setLocale(Locale.CHINESE);
    writer.setMimetype("text/plain");
    writer.putContent("sample content");
}
 
Example #8
Source File: CheckOutCheckInServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param policyComponent   policy component
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #9
Source File: IncompleteNodeTagger.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param policyComponent the component to register behaviour with
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #10
Source File: IntegrityChecker.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param policyComponent the component to register behaviour with
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #11
Source File: NodeAuditor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Set the component used to bind to behaviour callbacks
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #12
Source File: AbstractPermissionTest.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());
    }
    
    nodeService = (NodeService) applicationContext.getBean("nodeService");
    dictionaryService = (DictionaryService) applicationContext.getBean(ServiceRegistry.DICTIONARY_SERVICE
            .getLocalName());
    permissionService = (PermissionServiceSPI) applicationContext.getBean("permissionService");
    permissionServiceImpl = (PermissionServiceImpl) applicationContext.getBean("permissionServiceImpl");
    namespacePrefixResolver = (NamespacePrefixResolver) applicationContext
            .getBean(ServiceRegistry.NAMESPACE_SERVICE.getLocalName());
    authenticationService = (MutableAuthenticationService) applicationContext.getBean("authenticationService");
    authenticationComponent = (AuthenticationComponent) applicationContext.getBean("authenticationComponent");
    serviceRegistry = (ServiceRegistry) applicationContext.getBean(ServiceRegistry.SERVICE_REGISTRY);
    permissionModelDAO = (ModelDAO) applicationContext.getBean("permissionsModelDAO");
    personService = (PersonService) applicationContext.getBean("personService");
    authorityService = (AuthorityService) applicationContext.getBean("authorityService");
    authorityDAO = (AuthorityDAO) applicationContext.getBean("authorityDAO");
    siteService = (SiteService) applicationContext.getBean("SiteService"); // Big 'S'
    
    authenticationComponent.setCurrentUser(authenticationComponent.getSystemUserName());
    authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
    nodeDAO = (NodeDAO) applicationContext.getBean("nodeDAO");
    aclDaoComponent = (AclDAO) applicationContext.getBean("aclDAO");
    
    publicServiceAccessService = (PublicServiceAccessService) applicationContext.getBean("publicServiceAccessService");
    policyComponent = (PolicyComponent) applicationContext.getBean("policyComponent");
    
    retryingTransactionHelper = (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper");
    
    transactionService = (TransactionService) applicationContext.getBean("transactionComponent");
    
    testTX = transactionService.getUserTransaction();
    testTX.begin();


    testStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.nanoTime());
    rootNodeRef = nodeService.getRootNode(testStoreRef);

    QName children = ContentModel.ASSOC_CHILDREN;
    QName system = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "system");
    QName container = ContentModel.TYPE_CONTAINER;
    QName types = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "people");

    systemNodeRef = nodeService.createNode(rootNodeRef, children, system, container).getChildRef();
    NodeRef typesNodeRef = nodeService.createNode(systemNodeRef, children, types, container).getChildRef();
    Map<QName, Serializable> props = createPersonProperties(USER1_ANDY);
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();
    props = createPersonProperties(USER2_LEMUR);
    nodeService.createNode(typesNodeRef, children, ContentModel.TYPE_PERSON, container, props).getChildRef();

    // create an authentication object e.g. the user
    if(authenticationDAO.userExists(USER1_ANDY))
    {
        authenticationService.deleteAuthentication(USER1_ANDY);
    }
    authenticationService.createAuthentication(USER1_ANDY, USER1_ANDY.toCharArray());

    if(authenticationDAO.userExists(USER2_LEMUR))
    {
        authenticationService.deleteAuthentication(USER2_LEMUR);
    }
    authenticationService.createAuthentication(USER2_LEMUR, USER2_LEMUR.toCharArray());
    
    if(authenticationDAO.userExists(USER3_PAUL))
    {
        authenticationService.deleteAuthentication(USER3_PAUL);
    }
    authenticationService.createAuthentication(USER3_PAUL, USER3_PAUL.toCharArray());
    
    if(authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
    {
        authenticationService.deleteAuthentication(AuthenticationUtil.getAdminUserName());
    }
    authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), "admin".toCharArray());
    
    authenticationComponent.clearCurrentSecurityContext();
    
    assertTrue(permissionServiceImpl.getAnyDenyDenies());
}
 
Example #13
Source File: ReferenceableAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param policyComponent the policy component to register behaviour with
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #14
Source File: CascadeUpdateAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #15
Source File: ActionTrackingServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected void setUp() throws Exception
{
    // Detect any dangling transactions as there is a lot of direct UserTransaction manipulation
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
       throw new IllegalStateException(
               "There should not be any transactions when starting test: " +
               AlfrescoTransactionSupport.getTransactionId() + " started at " +
               new Date(AlfrescoTransactionSupport.getTransactionStartTime()));
    }

    // Grab our beans
    this.nodeService = (NodeService)ctx.getBean("nodeService");
    this.scriptService = (ScriptService)ctx.getBean("scriptService");
    this.actionService = (ActionService)ctx.getBean("actionService");
    this.runtimeActionService = (RuntimeActionService)ctx.getBean("actionService");
    this.actionTrackingService = (ActionTrackingService)ctx.getBean("actionTrackingService");
    this.transactionService = (TransactionService)ctx.getBean("transactionService");
    this.executingActionsCache = (SimpleCache<String, ExecutionDetails>)ctx.getBean("executingActionsCache");

    AuthenticationUtil.setRunAsUserSystem();
    
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    
    // Where to put things
    this.storeRef = this.nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
    this.rootNodeRef = this.nodeService.getRootNode(this.storeRef);
    
    // Create the node used for tests
    this.nodeRef = this.nodeService.createNode(
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}testnode"),
            ContentModel.TYPE_CONTENT).getChildRef();
    this.nodeService.setProperty(
            this.nodeRef,
            ContentModel.PROP_CONTENT,
            new ContentData(null, MimetypeMap.MIMETYPE_TEXT_PLAIN, 0L, null));
    this.folder = this.nodeService.createNode(
            this.rootNodeRef,
            ContentModel.ASSOC_CHILDREN,
            QName.createQName("{test}testFolder"),
            ContentModel.TYPE_FOLDER).getChildRef();
    
    txn.commit();
    
    // Cache should start empty each time
    executingActionsCache.clear();
    
    // Reset the execution instance IDs, so we
    //  can predict what they'll be
    ((ActionTrackingServiceImpl)actionTrackingService).resetNextExecutionId();
    
    // Register the test executor, if needed
    SleepActionExecuter.registerIfNeeded(ctx);
    
    // We want to know when async actions occur
    asyncOccurs = new AsyncOccurs();
    ((PolicyComponent)ctx.getBean("policyComponent")).bindClassBehaviour(
          AsynchronousActionExecutionQueuePolicies.OnAsyncActionExecute.QNAME,
          ActionModel.TYPE_ACTION,
          new JavaBehaviour(asyncOccurs, "onAsyncActionExecute", NotificationFrequency.EVERY_EVENT)
    );
}
 
Example #16
Source File: ActionsAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #17
Source File: PendingDeleteAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param policyComponent the policy component to register behaviour with
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #18
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());
    }

}
 
Example #19
Source File: RuleTriggerAbstractBase.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Set the policy component
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #20
Source File: RulesAspect.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #21
Source File: RuleServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Set the policy component to listen for various events
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #22
Source File: NodeServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
@BeforeClass public static void setup() throws Exception
{
    I18NUtil.setLocale(null);

    serviceRegistry = (ServiceRegistry) APP_CONTEXT_INIT.getApplicationContext().getBean(ServiceRegistry.SERVICE_REGISTRY);
    nodeService = serviceRegistry.getNodeService();
    personService = serviceRegistry.getPersonService();
    contentService = serviceRegistry.getContentService();
    permissionService = serviceRegistry.getPermissionService();
    nodeDAO = (NodeDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("nodeDAO");
    txnService = serviceRegistry.getTransactionService();
    policyComponent = (PolicyComponent) APP_CONTEXT_INIT.getApplicationContext().getBean("policyComponent");
    cannedQueryDAOForTesting = (CannedQueryDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("cannedQueryDAOForTesting");
    
    // Get the caches for later testing
    nodesCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.nodesSharedCache");
    propsCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.propertiesSharedCache");
    aspectsCache = (SimpleCache<Serializable, ValueHolder<Serializable>>) APP_CONTEXT_INIT.getApplicationContext().getBean("node.aspectsSharedCache");
    
    // Clear the caches to remove fluff
    nodesCache.clear();
    propsCache.clear();
    aspectsCache.clear();
    
    AuthenticationUtil.setRunAsUserSystem();
    
    // create a first store directly
    RetryingTransactionCallback<NodeRef> createStoreWork = new RetryingTransactionCallback<NodeRef>()
    {
        public NodeRef execute()
        {
            StoreRef storeRef = nodeService.createStore(
                    StoreRef.PROTOCOL_WORKSPACE,
                    "Test_" + System.nanoTime());
            return nodeService.getRootNode(storeRef);
        }
    };
    rootNodeRef = txnService.getRetryingTransactionHelper().doInTransaction(createStoreWork);
    
    final QNameDAO qnameDAO = (QNameDAO) APP_CONTEXT_INIT.getApplicationContext().getBean("qnameDAO");
    deletedTypeQNameId = txnService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Long>()
    {
        @Override
        public Long execute() throws Throwable
        {
            return qnameDAO.getOrCreateQName(ContentModel.TYPE_DELETED).getFirst();
        }
    });

}
 
Example #23
Source File: TaggingServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Policy component
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #24
Source File: ContentServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #25
Source File: ContentUsageImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #26
Source File: BaseVersionStoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
   * Called during the transaction setup
   */
  @Before
  public void before() throws Exception
  {
      // Set the multi value if required
      if (this.multiValue == null)
      {
          this.multiValue = new ArrayList<String>();
          this.multiValue.add(MULTI_VALUE_1);
          this.multiValue.add(MULTI_VALUE_2);
      }
      
      // Get the services by name from the application context
      this.dbNodeService = (NodeService)applicationContext.getBean("dbNodeService");
      this.contentService = (ContentService)applicationContext.getBean("contentService");
      this.authenticationService = (MutableAuthenticationService)applicationContext.getBean("authenticationService");
      this.transactionService = (TransactionService)this.applicationContext.getBean("transactionComponent");
      this.txnHelper = (RetryingTransactionHelper) applicationContext.getBean("retryingTransactionHelper");
      this.authenticationDAO = (MutableAuthenticationDao) applicationContext.getBean("authenticationDao");
      this.nodeArchiveService = (NodeArchiveService) applicationContext.getBean("nodeArchiveService");
      this.nodeService = (NodeService)applicationContext.getBean("nodeService");
      this.permissionService = (PermissionService)this.applicationContext.getBean("permissionService");
      this.checkOutCheckInService = (CheckOutCheckInService) applicationContext.getBean("checkOutCheckInService");
      this.versionSearchService = (SearchService)this.applicationContext.getBean("versionSearchService");
      this.dictionaryService = (DictionaryService)this.applicationContext.getBean("dictionaryService");
      this.policyComponent = (PolicyComponent)this.applicationContext.getBean("policyComponent");
      this.policyBehaviourFilter = (BehaviourFilter)this.applicationContext.getBean("policyBehaviourFilter");
      
      setVersionService((VersionService)applicationContext.getBean("versionService"));
      
      authenticationService.clearCurrentSecurityContext();
      
// Create the test model
createTestModel();

      // Create a bag of properties for later use
      this.versionProperties = new HashMap<String, Serializable>();
      versionProperties.put(VERSION_PROP_1, VALUE_1);
      versionProperties.put(VERSION_PROP_2, VALUE_2);
      versionProperties.put(VERSION_PROP_3, VALUE_3);
      
      // Create the node properties
      this.nodeProperties = new HashMap<QName, Serializable>();
      this.nodeProperties.put(PROP_1, VALUE_1);
      this.nodeProperties.put(PROP_2, VALUE_2);
      this.nodeProperties.put(PROP_3, VALUE_3);
      this.nodeProperties.put(MULTI_PROP, (Serializable)multiValue);
      this.nodeProperties.put(ContentModel.PROP_CONTENT, new ContentData(null, "text/plain", 0L, "UTF-8"));
      
      // Add mlText property
      this.mlText = new MLText(Locale.UK, "UK value");
      this.mlText.addValue(Locale.US, "Y'all US value");
      this.nodeProperties.put(MLTEXT_PROP, this.mlText);
      
      // Create a workspace that contains the 'live' nodes
      this.testStoreRef = this.dbNodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
      
      StoreRef archiveStoreRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "archive" + getName() + System.currentTimeMillis());
      
      // Map the work store to the archive store.  This will already be wired into the NodeService.
      StoreArchiveMap archiveMap = (StoreArchiveMap) applicationContext.getBean("storeArchiveMap");
      archiveMap.put(testStoreRef, archiveStoreRef);        
      
      // Get a reference to the root node
      this.rootNodeRef = this.dbNodeService.getRootNode(this.testStoreRef);
      
      // Create and authenticate the user
      
      if(!authenticationDAO.userExists(AuthenticationUtil.getAdminUserName()))
      {
          authenticationService.createAuthentication(AuthenticationUtil.getAdminUserName(), PWD.toCharArray());
      }
      
      AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
  }
 
Example #27
Source File: ContentMetadataExtracterTagMappingTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void setUp() throws Exception
{
    // Detect any dangling transactions as there is a lot of direct UserTransaction manipulation
    if (AlfrescoTransactionSupport.getTransactionReadState() != TxnReadState.TXN_NONE)
    {
        throw new IllegalStateException(
                "There should not be any transactions when starting test: " +
                AlfrescoTransactionSupport.getTransactionId() + " started at " +
                new Date(AlfrescoTransactionSupport.getTransactionStartTime()));
    }
    
    // Get services
    this.taggingService = (TaggingService)ctx.getBean("TaggingService");
    this.nodeService = (NodeService) ctx.getBean("NodeService");
    this.contentService = (ContentService) ctx.getBean("ContentService");
    
    this.transactionService = (TransactionService)ctx.getBean("transactionComponent");
    this.auditService = (AuditService)ctx.getBean("auditService");
    this.authenticationComponent = (AuthenticationComponent)ctx.getBean("authenticationComponent");
    
    this.executer = (ContentMetadataExtracter) ctx.getBean("extract-metadata");
    executer.setEnableStringTagging(true);
    executer.setTaggingService(taggingService);
    
    if (init == false)
    {
        this.transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>(){

            @Override
            public Void execute() throws Throwable
            {
                // Authenticate as the system user
                authenticationComponent.setSystemUserAsCurrentUser();
                
                // Create the store and get the root node
                ContentMetadataExtracterTagMappingTest.storeRef = nodeService.createStore(StoreRef.PROTOCOL_WORKSPACE, "Test_" + System.currentTimeMillis());
                ContentMetadataExtracterTagMappingTest.rootNode = nodeService.getRootNode(ContentMetadataExtracterTagMappingTest.storeRef);
            
                // Create the required tagging category
                NodeRef catContainer = nodeService.createNode(ContentMetadataExtracterTagMappingTest.rootNode, ContentModel.ASSOC_CHILDREN, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "categoryContainer"), ContentModel.TYPE_CONTAINER).getChildRef();        
                NodeRef catRoot = nodeService.createNode(
                        catContainer, 
                        ContentModel.ASSOC_CHILDREN, 
                        QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "categoryRoot"), 
                        ContentModel.TYPE_CATEGORYROOT).getChildRef();
                nodeService.createNode(
                       catRoot, 
                       ContentModel.ASSOC_CATEGORIES, 
                       ContentModel.ASPECT_TAGGABLE, 
                       ContentModel.TYPE_CATEGORY).getChildRef();
                
                MetadataExtracterRegistry registry = (MetadataExtracterRegistry) ctx.getBean("metadataExtracterRegistry");
                extractor = new TagMappingMetadataExtracter();
                extractor.setRegistry(registry);
                extractor.register();
                
                init = true;
                return null;
            }});
        
    }
    
    // We want to know when tagging actions have finished running
    asyncOccurs = (new TaggingServiceImplTest()).new AsyncOccurs();
    ((PolicyComponent)ctx.getBean("policyComponent")).bindClassBehaviour(
          AsynchronousActionExecutionQueuePolicies.OnAsyncActionExecute.QNAME,
          ActionModel.TYPE_ACTION,
          new JavaBehaviour(asyncOccurs, "onAsyncActionExecute", NotificationFrequency.EVERY_EVENT)
    );

    // We do want action tracking whenever the tag scope updater runs
    UpdateTagScopesActionExecuter updateTagsAction = 
        (UpdateTagScopesActionExecuter)ctx.getBean("update-tagscope");
    updateTagsAction.setTrackStatus(true);
}
 
Example #28
Source File: AnnotatedBehaviourPostProcessor.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @param policyComponent   policy component
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #29
Source File: RenditionServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Injects the PolicyComponent bean.
 * @param policyComponent PolicyComponent
 */
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}
 
Example #30
Source File: DocumentLinkServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setPolicyComponent(PolicyComponent policyComponent)
{
    this.policyComponent = policyComponent;
}