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

The following are Jave code examples for showing how to use getFullAuthentication() of the org.alfresco.repo.security.authentication.AuthenticationUtil class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: alfresco-repository   File: DownloadServiceIntegrationTest.java   View Source Code Vote up 6 votes
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
Project: alfresco-remote-api   File: RepositoryContainer.java   View Source Code Vote up 5 votes
/**
 * 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
Project: alfresco-repository   File: AlfrescoCmisServiceImpl.java   View Source Code Vote up 4 votes
@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
Project: alfresco-repository   File: DownloadServiceIntegrationTest.java   View Source Code Vote up 4 votes
/**
 * 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());
}