/** * Creates a persistable JCR session with the default credentials * <P> * <EM>Note: The client should invoke <CODE>logout()</CODE> method on the session after use.</EM> * </P> * <P> * Internally, {@link javax.jcr.Session#impersonate(Credentials)} method will be used to create a * persistable JCR session. The method is invoked on the session from the session pooling repository. * </P> * @param request * @return */ protected Session getPersistableSession(HstRequest request) throws RepositoryException { HstRequestContext requestContext = request.getRequestContext(); Credentials credentials = requestContext.getContextCredentialsProvider().getWritableCredentials(requestContext); return getPersistableSession(request, credentials); }
/** * Creates a persistable JCR session with the default credentials * <P> * <EM>Note: The client should invoke <CODE>logout()</CODE> method on the session after use.</EM> * </P> * <P> * Internally, {@link javax.jcr.Session#impersonate(Credentials)} method will be used to create a * persistable JCR session. The method is invoked on the session from the session pooling repository. * </P> * @param request * @return */ protected Session getPersistableSession(HstRequest request) throws RepositoryException { HstRequestContext requestContext = request.getRequestContext(); Credentials credentials = requestContext.getContextCredentialsProvider().getWritableCredentials(requestContext); return getPersistableSession(request, credentials); }
try { Repository repository = HstServices.getComponentManager().getComponent(Repository.class.getName()); Credentials persistableCredentials = requestContext.getContextCredentialsProvider().getWritableCredentials(requestContext); persistableSession = repository.login(persistableCredentials); requestContext.setAttribute(PERSISTABLE_SESSION_ATTR, persistableSession);
cred = requestContext.getContextCredentialsProvider().getDefaultCredentials(requestContext); userID = ((SimpleCredentials) cred).getUserID();