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

The following examples show how to use org.alfresco.repo.security.authentication.AuthenticationUtil#getFullAuthentication() . 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: DownloadServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
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
Source File: RepositoryContainer.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Add Repository specific parameters
 * 
 * @param params Map<String, Object>
 */
private void addRepoParameters(Map<String, Object> params)
{
    if (AlfrescoTransactionSupport.getTransactionId() != null &&
        AuthenticationUtil.getFullAuthentication() != null)
    {
        NodeRef rootHome = repository.getRootHome();
        if (rootHome != null)
        {
            params.put("roothome", rootHome);
        }
        NodeRef companyHome = repository.getCompanyHome();
        if (companyHome != null)
        {
            params.put("companyhome", companyHome);
        }
        NodeRef person = repository.getFullyAuthenticatedPerson();
        if (person != null)
        {
            params.put("person", person);
            NodeRef userHome = repository.getUserHome(person);
            if (userHome != null)
            {
                params.put("userhome", userHome);
            }
        }
    }
}
 
Example 3
Source File: AlfrescoCmisServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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 4
Source File: DownloadServiceIntegrationTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 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());
}