Hi! Thanks for posting your code, I was able to tweak it a bit and got it to work for me. Hope it'll help you.
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="org.alfresco.service.cmr.security.AuthenticationService"%>
<%@ page import="org.alfresco.web.bean.repository.*"%>
<%@ page import="org.alfresco.service.cmr.repository.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.io.*"%>
<%@ page import="org.alfresco.web.bean.*"%>
<%@ page import="org.springframework.context.ApplicationContext"%>
<%@ page import="org.alfresco.util.ApplicationContextHelper"%>
<%@ page import="org.alfresco.service.ServiceRegistry"%>
<%@ page import="org.alfresco.web.app.servlet.AuthenticationHelper"%>
<%@ page import="org.alfresco.web.app.servlet.AuthenticationFilter"%>
<%@ page import="org.alfresco.model.ContentModel"%>
<%@ page import="org.springframework.web.jsf.FacesContextUtils"%>
<%@ page import="javax.faces.context.FacesContext"%>
<%@ page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%@ page import="org.springframework.web.context.WebApplicationContext"%>
<%@ page import="org.alfresco.service.cmr.security.PersonService"%>
<%@ page import="org.alfresco.web.bean.*"%>
<%@ page import="javax.transaction.UserTransaction"%>
<%
User user = null;
String username ="joeb";
String password ="joeb";
UserTransaction tx ;
AuthenticationService authenticationService = null;
/** NodeService bean reference */
NodeService nodeService = null;
WebApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(application);
ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
tx = serviceRegistry.getTransactionService().getUserTransaction();
tx.begin();
// get individual, required services
nodeService = (NodeService)serviceRegistry.getNodeService();
authenticationService=(AuthenticationService)ctx.getBean("authenticationService");
PersonService personService = (PersonService)ctx.getBean("personService");
//logout first
// invalidate User ticket
try
{
try
{
user = (User)session.getValue(AuthenticationHelper.AUTHENTICATION_USER);
out.println("User is : " + user.toString());
if (user != null)
{
out.println("user was not null");
authenticationService.invalidateTicket(user.getTicket());
Enumeration em= session.getAttributeNames();
while(em.hasMoreElements())
{
String name=(String)em.nextElement();
session.removeAttribute(name);
}
}
}
catch (NullPointerException e)
{
out.println("User was null!");
authenticationService.authenticate(username, password.toCharArray());
// setup User object and Home space ID
user = new User(authenticationService.getCurrentUserName(), authenticationService.getCurrentTicket(),personService.getPerson(username));
out.println("New user is " + user);
NodeRef homeSpaceRef = (NodeRef) nodeService.getProperty(personService.getPerson(username), ContentModel.PROP_HOMEFOLDER);
// check that the home space node exists - else user cannot login
if (nodeService.exists(homeSpaceRef) == false)
{
throw new InvalidNodeRefException(homeSpaceRef);
}
user.setHomeSpaceId(homeSpaceRef.getId());
tx.commit();
tx = null;
//inintialize the authentication session
session.putValue(AuthenticationHelper.AUTHENTICATION_USER, user);
String homeSpaceName = Repository.getNameForNode((NodeService)serviceRegistry.getNodeService(), homeSpaceRef);
// move to actuale working service area
response.sendRedirect(request.getContextPath() + "/faces/jsp/browse/browse.jsp");
}
}
catch (Exception ex)
{
out.println("something is wrong." + ex.getMessage());
}
%>