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; }
@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; }
cred = requestContext.getContextCredentialsProvider().getDefaultCredentials(requestContext); userID = ((SimpleCredentials) cred).getUserID();