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

The following examples show how to use org.alfresco.repo.security.authentication.AuthenticationUtil#setFullAuthentication() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
private void validateWorkingCopyFolder(final Set<String> expectedEntries, final NodeRef folder, final String userID) throws InterruptedException
{
    Authentication previousAuthentication = AuthenticationUtil.getFullAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(userID);
    try
    {
        final NodeRef downloadNode = DOWNLOAD_SERVICE.createDownload(new NodeRef[] {folder},  true);
        testNodes.addNodeRef(downloadNode);
        
        waitForDownload(downloadNode);
        
        validateEntries(getEntries(downloadNode), expectedEntries, true);
    }
    finally
    {
        AuthenticationUtil.setFullAuthentication(previousAuthentication);
    }
}
 
Example 2
@Override
    public void beforeCall()
    {
        AuthenticationUtil.pushAuthentication();
        if (authentication != null)
        {
            // Use the previously-obtained authentication
            AuthenticationUtil.setFullAuthentication(authentication);
        }
        else
        {
        	CallContext context = getContext();
            if (context == null)
            {
                // Service not opened, yet
                return;
            }
            // Sticky sessions?
            if (connector.openHttpSession())
            {
                // create a session -> set a cookie
                // if the CMIS client supports cookies that might help in clustered environments
                ((HttpServletRequest)context.get(CallContext.HTTP_SERVLET_REQUEST)).getSession();
            }
            
            // Authenticate
            if (authentication != null)
            {
                // We have already authenticated; just reuse the authentication
                AuthenticationUtil.setFullAuthentication(authentication);
            }
            else
            {
                // First check if we already are authenticated
                if (AuthenticationUtil.getFullyAuthenticatedUser() == null)
                {
                    // We have to go to the repo and authenticate
                    String user = context.getUsername();
                    String password = context.getPassword();
                    Authorization auth = new Authorization(user, password);
                    if (auth.isTicket())
                    {
                        connector.getAuthenticationService().validate(auth.getTicket());
                    }
                    else
                    {
                        connector.getAuthenticationService().authenticate(auth.getUserName(), auth.getPasswordCharArray());
                    }
                }
                this.authentication = AuthenticationUtil.getFullAuthentication();
            }
            
//            // TODO: How is the proxy user working.
//            //       Until we know what it is meant to do, it's not available
//            String currentUser = connector.getAuthenticationService().getCurrentUserName();
//            String user = getContext().getUsername();
//            String password = getContext().getPassword();
//            if (currentUser != null && currentUser.equals(connector.getProxyUser()))
//            {
//                if (user != null && user.length() > 0)
//                {
//                    AuthenticationUtil.setFullyAuthenticatedUser(user);
//                }
//            }
        }
    }
 
Example 3
/**
 * This test verifies that a user is given the correct file, when it is checked. The user who checked out
 * the file should get the working copy, while any other user should get the default version.
 * @throws InterruptedException 
 */
@Test public void workingCopies() throws InterruptedException
{
    final Set<String> preCheckoutExpectedEntries = new TreeSet<String>();
    preCheckoutExpectedEntries.add("level1Folder2/");
    preCheckoutExpectedEntries.add("level1Folder2/level2File.txt");
    preCheckoutExpectedEntries.add("level1Folder2/fileToCheckout.txt");
    
    validateWorkingCopyFolder(preCheckoutExpectedEntries, level1Folder2, TEST_USER.getUsername());
    validateWorkingCopyFolder(preCheckoutExpectedEntries, level1Folder2, TEST_USER2.getUsername());

    Authentication previousAuth = AuthenticationUtil.getFullAuthentication();
    AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER.getUsername());
    NodeRef workingCopy;
    try
    {
        workingCopy = CHECK_OUT_CHECK_IN_SERVICE.checkout(fileToCheckout);
    }
    finally
    {
       AuthenticationUtil.setFullAuthentication(previousAuth);
    }
    
    try
    {
        validateWorkingCopyFolder(preCheckoutExpectedEntries, level1Folder2, TEST_USER2.getUsername());
        
        final Set<String> postCheckoutExpectedEntries = new TreeSet<String>();
        postCheckoutExpectedEntries.add("level1Folder2/");
        postCheckoutExpectedEntries.add("level1Folder2/level2File.txt");
        postCheckoutExpectedEntries.add("level1Folder2/fileToCheckout (Working Copy).txt");
        validateWorkingCopyFolder(postCheckoutExpectedEntries, level1Folder2, TEST_USER.getUsername());
    }
    finally
    {
        previousAuth = AuthenticationUtil.getFullAuthentication();
        AuthenticationUtil.setFullyAuthenticatedUser(TEST_USER.getUsername());
        try
        {
            CHECK_OUT_CHECK_IN_SERVICE.checkin(workingCopy, null);
        }
        finally
        {
           AuthenticationUtil.setFullAuthentication(previousAuth);
        }
    }
    validateWorkingCopyFolder(preCheckoutExpectedEntries, level1Folder2, TEST_USER.getUsername());
    validateWorkingCopyFolder(preCheckoutExpectedEntries, level1Folder2, TEST_USER2.getUsername());
}