we have been using user.properties to store data related to a certain user session. this works when a user is signed in, but not for "guest" users. I've created an extension to the AlfrescoUserFactory that seems to work. It may be helpful to someone else looking to do this.
create a definition in a bean fileCode:import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.springframework.extensions.surf.RequestContext; import org.springframework.extensions.surf.exception.UserFactoryException; import org.springframework.extensions.surf.support.AlfrescoUserFactory; import org.springframework.extensions.webscripts.connector.User; /** * override methods in AlfrescoUserFactory and AbstractUserFactory * to create unique guest users and add them to the session */ public class SpecialUserFactory extends AlfrescoUserFactory { public User initialiseUser(RequestContext context, HttpServletRequest request, String endpoint, boolean force) throws UserFactoryException { User u = super.initialiseUser(context,request,endpoint,force); if (u.isGuest() && request.getSession().getAttribute(SESSION_ATTRIBUTE_KEY_USER_ID) == null) { // add to the session if not there request.getSession().setAttribute(SESSION_ATTRIBUTE_KEY_USER_OBJECT, u); request.getSession().setAttribute(SESSION_ATTRIBUTE_KEY_USER_ID, u.getId()); } return u; } protected User getGuestUser(RequestContext context) throws UserFactoryException { Map<String, Boolean> capabilities = new HashMap<String, Boolean>(4); capabilities.put(User.CAPABILITY_ADMIN, false); capabilities.put(User.CAPABILITY_GUEST, true); capabilities.put(User.CAPABILITY_MUTABLE, false); User user = new User(USER_GUEST, capabilities); user.setFirstName("Guest"); return user; } }
and add the reference to surf.xmlCode:<bean id="webframework.factory.user.special" class="SpecialUserFactory" parent="webframework.factory.base" />
I'm interested to know if anyone is aware of problems this may cause.Code:<web-framework> .... <user-factory>webframework.factory.user.special</user-factory> </defaults> </web-framework>


Reply With Quote