public static Session createSessionFromCurrentSession() {
    if (_session == null) {
      throw new IllegalStateException("You need to be logged in to get a session");
    }

    return new SessionImpl(LiferayServerContext.getServer(), _session.getAuthentication());
  }
  public static Session createBasicSession(String username, String password) {
    Authentication authentication = new BasicAuthentication(username, password);

    _session = new SessionImpl(LiferayServerContext.getServer(), authentication);

    return _session;
  }
  public static Session createOAuthSession(OAuthConfig config) {
    OAuth oAuth = new OAuthAuthentication(config);

    _session = new SessionImpl(LiferayServerContext.getServer(), oAuth);

    return _session;
  }
  public static void loadSessionFromStore(CredentialsStoreBuilder.StorageType storageType)
      throws IllegalStateException {

    CredentialsStore storage =
        new CredentialsStoreBuilder()
            .setContext(LiferayScreensContext.getContext())
            .setStorageType(storageType)
            .build();

    checkIfStorageTypeIsSupported(storageType, storage);

    if (storage.loadStoredCredentials()) {
      _session = new SessionImpl(LiferayServerContext.getServer(), storage.getAuthentication());
      _loggedUser = storage.getUser();
    }
  }