Java Code Examples for org.alfresco.repo.security.authentication.AuthenticationUtil#clearCurrentSecurityContext()

The following examples show how to use org.alfresco.repo.security.authentication.AuthenticationUtil#clearCurrentSecurityContext() . 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: ReplicationRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void tearDown() throws Exception
{
    super.tearDown();
    
    UserTransaction txn = transactionService.getUserTransaction();
    txn.begin();
    
    personManager.clearPeople();
    
    // Zap any replication definitions we created
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    for(ReplicationDefinition rd : replicationService.loadReplicationDefinitions()) {
       replicationService.deleteReplicationDefinition(rd);
    }
    AuthenticationUtil.clearCurrentSecurityContext();
    
    txn.commit();
}
 
Example 2
Source File: MultiTServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After
public void tearDown() throws Exception
{
    deleteTenant(DOMAIN);
    AuthenticationUtil.setMtEnabled(mtEnabled);
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 3
Source File: GetMethodRegressionTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@After
public void tearDown() throws Exception
{
    if ((null != transaction) && (Status.STATUS_ROLLEDBACK != transaction.getStatus()) && (Status.STATUS_COMMITTED != transaction.getStatus()))
    {
        transaction.rollback();
    }

    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 4
Source File: AuthorityServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception
{
    if ((tx.getStatus() == Status.STATUS_ACTIVE) || (tx.getStatus() == Status.STATUS_MARKED_ROLLBACK))
    {
        tx.rollback();
    }
    AuthenticationUtil.clearCurrentSecurityContext();
    super.tearDown();
}
 
Example 5
Source File: ClearSecurityContextFilter.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException
{
    try
    {
        chain.doFilter(servletRequest, servletResponse);
    }
    finally
    {
        logClearContextInfo(servletRequest);
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
 
Example 6
Source File: ArchiveAndRestoreTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void tearDown() throws Exception
{
    try
    {
        txn.rollback();
    }
    catch (Throwable e)
    {
        e.printStackTrace();
    }
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 7
Source File: ImapServiceImplTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void tearDown() throws Exception
{
    try
    {
        txn.rollback();
    }
    catch (Throwable e)
    {
        e.printStackTrace();
    }
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 8
Source File: SurfConfigTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception
{
    super.tearDown();
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    deleteUser(USER_ONE);
    deleteUser(USER_TWO);
    deleteUser(USER_THREE);

    //Delete the sites
    deleteSites();

    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 9
Source File: AlfrescoWebScriptServlet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
{
    try
    {
        super.service(req, res);
    }
    finally
    {
        AuthenticationUtil.clearCurrentSecurityContext();
    }
}
 
Example 10
Source File: AbstractPermissionTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception
{
    try
    {
        testTX.rollback();
    }
    catch (Throwable e)
    {
        e.printStackTrace();
    }
    AuthenticationUtil.clearCurrentSecurityContext();
    super.tearDown();
}
 
Example 11
Source File: PutMethodTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@After
public void tearDown() throws Exception
{
    method = null;
    request = null;
    response = null;
    testDataFile = null;
    davLockInfoAdminFile = null;

    if (txn.getStatus() == Status.STATUS_MARKED_ROLLBACK)
    {
        txn.rollback();
    }
    else
    {
        txn.commit();
    }
    
    AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
    deleteUser(USER1_NAME);
    deleteUser(USER2_NAME);

    nodeService.deleteNode(versionableDoc);

    // As per MNT-10037 try to create a node and delete it in the next txn
    txn = transactionService.getUserTransaction();
    txn.begin();

    Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
    String nodeName = "leak-session-doc-" + GUID.generate();
    properties.put(ContentModel.PROP_NAME, nodeName);

    NodeRef nodeRef = nodeService.createNode(companyHomeNodeRef, ContentModel.ASSOC_CONTAINS, QName.createQName(ContentModel.USER_MODEL_URI, nodeName),
            ContentModel.TYPE_CONTENT, properties).getChildRef();
    contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true).putContent("WebDAVTestContent");

    txn.commit();

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

    nodeService.deleteNode(nodeRef);

    txn.commit();

    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 12
Source File: ChainingUserRegistrySynchronizer.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final void afterProcess() throws Throwable
{
    // Clear authentication
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 13
Source File: AuthorityBridgeTableAsynchronouslyRefreshedCacheTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void tearDown()
{
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 14
Source File: DictionaryRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected void tearDown() throws Exception
   {
	super.tearDown();
	AuthenticationUtil.clearCurrentSecurityContext();
   }
 
Example 15
Source File: UserUsageTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected void tearDown() throws Exception
{
    boolean deltasDeleted = false;
    try
    {
        usageService.deleteDeltas(personNodeRef);
        usageService.deleteDeltas(personNodeRef2);
        deltasDeleted = true;
    }
    finally
    {
        try
        {
            testTX.commit();
        }
        catch (Throwable e)
        {
            AuthenticationUtil.clearCurrentSecurityContext();
            try { testTX.rollback(); } catch (Throwable ee) {}
            if (deltasDeleted)
            {
                // The deltas did not cause this issue.  So it's something else during commit;
                throw new Exception("Failed to commit transaction after test", e);
            }
            else
            {
                // One of the deleteDelats calls failed and an exception is passing through.
                // Do not rethrow so that we don't mask it.
                logger.error("Transaction commit failed", e);
            }
        }
    }

    // Make sure we remove all nodes created with the example model so that the model can be
    // removed.
    transactionService.getRetryingTransactionHelper().doInTransaction(new RetryingTransactionCallback<Void>()
    {
        @Override
        public Void execute() throws Throwable
        {
            for(NodeRef nodeRef : nodesToDelete)
            {
                nodeService.addAspect(nodeRef, ContentModel.ASPECT_TEMPORARY, null);
                nodeService.deleteNode(nodeRef);
            }
            return null;
        }
    }, true, true);
    
   AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 16
Source File: RetryingTransactionHelperTestCase.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Executes a test in a retrying transaction as the admin user.
 * 
 * @param <A>    type of the object resulting from the test, can be set to {@link Void} if none.
 * @param test   test object to be executed within a retrying transaction
 * @param asUser user to execute the test as
 * @return A     the result of the test
 */
protected <A> A doTestInTransaction(final Test<A> test, final String asUser)
{    
    String origUser = AuthenticationUtil.getFullyAuthenticatedUser();
    AuthenticationUtil.setFullyAuthenticatedUser(asUser);
    try
    {        
        // Execute the run() method within a retrying transaction
        RetryingTransactionCallback<A> doRun = new RetryingTransactionCallback<A>()
        {
            @Override
            public A execute() throws Throwable
            {
                // Run test as user
                return test.run();              
            }            
        };                
        final A result = getRetryingTransactionHelper().doInTransaction(doRun);
        
        // Execute the test() method within a retrying transaction
        RetryingTransactionCallback<Void> doTest = new RetryingTransactionCallback<Void>()
        {
            @Override
            public Void execute() throws Throwable
            {
                // pass the result of the run into the test
                test.test(result);
                return null;                    
            }
            
        };
        getRetryingTransactionHelper().doInTransaction(doTest);
        
        return result;
    }
    finally
    {
        if (origUser != null)
        {
            AuthenticationUtil.setFullyAuthenticatedUser(origUser);
        }
        else
        {
            AuthenticationUtil.clearCurrentSecurityContext();
        }
    }                   
}
 
Example 17
Source File: NodeArchiveServiceRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void tearDown() throws Exception
{
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    super.tearDown();

    // Tidy up any test nodes that are hanging around.
    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
                {
                    public Void execute() throws Throwable
                    {
                        AuthenticationUtil.runAs(new RunAsWork<Void>()
                        {
                            public Void doWork() throws Exception
                            {
                                for (NodeRef nodeRef : createdNodes)
                                {
                                    if (nodeRef != null && nodeService.exists(nodeRef))
                                    {
                                        nodeService.deleteNode(nodeRef);
                                    }
                                }

                                for (StoreRef store : createdStores)
                                {
                                    if (store != null && nodeService.exists(store))
                                    {
                                        nodeService.deleteStore(store);
                                    }
                                }
                                return null;
                            }
                        }, AuthenticationUtil.getSystemUserName());

                        return null;
                    }
                });

    // Delete users
    for (String userName : this.createdPeople)
    {
        personService.deletePerson(userName);
    }
    // Clear the lists
    this.createdPeople.clear();
    this.createdNodes.clear();
    this.createdStores.clear();

    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 18
Source File: ContentStoreCleanerTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void tearDown() throws Exception
{
    AuthenticationUtil.clearCurrentSecurityContext();
}
 
Example 19
Source File: CustomModelImportTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void tearDown() throws Exception
{
    for (File file : tempFiles)
    {
        file.delete();
    }

    transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
    {
        public Void execute() throws Throwable
        {
            for (String modelName : importedModels)
            {
                customModelService.deleteCustomModel(modelName);
            }
            return null;
        }
    });

    AuthenticationUtil.runAsSystem(new RunAsWork<Void>()
    {
        @Override
        public Void doWork() throws Exception
        {
            transactionHelper.doInTransaction(new RetryingTransactionHelper.RetryingTransactionCallback<Void>()
            {
                public Void execute() throws Throwable
                {
                    deleteUser(NON_ADMIN_USER);
                    deleteUser(CUSTOM_MODEL_ADMIN);
                    return null;
                }
            });
            return null;
        }
    });

    AuthenticationUtil.clearCurrentSecurityContext();

    super.tearDown();
}
 
Example 20
Source File: OAuth2CredentialsStoreServiceTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@After
public void tearDown() throws Exception
{
    AuthenticationUtil.clearCurrentSecurityContext();
}