java - Creating Guest Session -
is there way create guest session in aem?
our project e-commerce website built on aem , need track session of incoming guest , generate token out of it, in case there saving of items on cart. need track guest session/token in case user decides log in our site checkout items, back-end services can map on ownership of cart based on session/token.
by default if user not logged in , content viewed, aem internally logs user "anonymous", may consider guest.
you can value below:
import org.apache.jackrabbit.api.security.user.authorizable; import org.apache.jackrabbit.api.security.user.usermanager; import org.apache.sling.api.resource.resourceresolver; import javax.jcr.session; ... usermanager usermanager = resourceresolver.adaptto(usermanager.class); session session = resourceresolver.adaptto(session.class); // getting current user authorizable auth = usermanager.getauthorizable(session.getuserid()); log.info("\n--- user, principal="+auth.getid()+","+auth.getprincipal().getname()); // not try token if no user logged in - anonymous if (auth.getid().equals(anonymous_user)) { // write logic here } else { // user logged }
Comments
Post a Comment