public Session getSession() throws LoginException, RepositoryException { if (this.session == null) { this.session = this.repository.login(contextCredentialsProvider.getDefaultCredentials(this)); } else if (!this.session.isLive()) { throw new HstComponentException("Invalid session."); } return this.session; }
/** * 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); }
@Override public Session getSession(boolean create) throws RepositoryException { checkStateValidity(); if (this.session == null) { if (create) { final ContextCredentialsProvider credsProvider = getContextCredentialsProvider(); if (credsProvider != null) { final SimpleCredentials defaultCredentials = (SimpleCredentials) credsProvider.getDefaultCredentials(this); try { this.session = this.repository.login(defaultCredentials); } catch (LoginException e) { log.warn("Login Exception for session for userID {}. Cannot create session.", defaultCredentials.getUserID()); throw e; } } else { try { this.session = this.repository.login(); } catch (LoginException e) { log.warn("Login Exception for anonymous login."); throw e; } } } } else if (!this.session.isLive()) { throw new HstComponentException("Invalid session."); } return this.session; }
/** * 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); }
cred = requestContext.getContextCredentialsProvider().getDefaultCredentials(requestContext); userID = ((SimpleCredentials) cred).getUserID();
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);