Example #1
0
  private LogonResult logon(Properties connProps, byte[] krb5ServiceTicket) throws LogonException {
    // DQPWorkContext workContext = DQPWorkContext.getWorkContext();
    // String oldSessionId = workContext.getSessionId();
    String applicationName = connProps.getProperty(TeiidURL.CONNECTION.APP_NAME);
    // user may be null if using trustedToken to log on
    String user =
        connProps.getProperty(TeiidURL.CONNECTION.USER_NAME, CoreConstants.DEFAULT_ANON_USERNAME);
    // password may be null if using trustedToken to log on
    String password = connProps.getProperty(TeiidURL.CONNECTION.PASSWORD);
    Credentials credential = null;
    if (password != null) {
      credential = new Credentials(password.toCharArray());
    }

    try {
      SessionMetadata sessionInfo =
          service.createSession(user, credential, applicationName, connProps, true);
      updateDQPContext(sessionInfo);
      if (DQPWorkContext.getWorkContext().getClientAddress() == null) {
        sessionInfo.setEmbedded(true);
      }
      // if (oldSessionId != null) {
      // TODO: we should be smarter about disassociating the old sessions from the client.  we'll
      // just rely on
      // ping based clean up
      // }
      LogonResult result =
          new LogonResult(
              sessionInfo.getSessionToken(),
              sessionInfo.getVDBName(),
              sessionInfo.getVDBVersion(),
              clusterName);
      if (krb5ServiceTicket != null) {
        result.addProperty(ILogon.KRB5TOKEN, krb5ServiceTicket);
      }
      return result;
    } catch (LoginException e) {
      throw new LogonException(e);
    } catch (SessionServiceException e) {
      throw new LogonException(e);
    }
  }