Пример #1
0
  @Override
  public void assertIdentity(SessionToken checkSession)
      throws InvalidSessionException, TeiidComponentException {
    if (checkSession == null) {
      // disassociate
      this.updateDQPContext(new SessionMetadata());
      return;
    }
    SessionMetadata sessionInfo = null;
    try {
      sessionInfo = this.service.validateSession(checkSession.getSessionID());
    } catch (SessionServiceException e) {
      throw new TeiidComponentException(RuntimePlugin.Event.TEIID40062, e);
    }

    if (sessionInfo == null) {
      throw new InvalidSessionException(RuntimePlugin.Event.TEIID40063);
    }

    SessionToken st = sessionInfo.getSessionToken();
    if (!st.equals(checkSession)) {
      throw new InvalidSessionException(RuntimePlugin.Event.TEIID40064);
    }
    this.updateDQPContext(sessionInfo);
  }
Пример #2
0
 private DQPWorkContext createWorkContext(final CommandContext context, VDBMetaData vdb) {
   SessionMetadata session =
       createTemporarySession(context.getUserName(), "asynch-mat-view-load", vdb); // $NON-NLS-1$
   session.setSubject(context.getSubject());
   session.setSecurityDomain(context.getSession().getSecurityDomain());
   session.setSecurityContext(context.getSession().getSecurityContext());
   DQPWorkContext workContext = new DQPWorkContext();
   workContext.setAdmin(true);
   DQPWorkContext current = context.getDQPWorkContext();
   workContext.setSession(session);
   workContext.setPolicies(current.getAllowedDataPolicies());
   workContext.setSecurityHelper(current.getSecurityHelper());
   return workContext;
 }
Пример #3
0
  private String updateDQPContext(SessionMetadata s) {
    String sessionID = s.getSessionId();

    DQPWorkContext workContext = DQPWorkContext.getWorkContext();
    workContext.setSession(s);
    return sessionID;
  }
Пример #4
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);
    }
  }
Пример #5
0
  @Test
  public void testAnyAuthenticated() {
    DQPWorkContext message = new DQPWorkContext();
    SessionMetadata mock = Mockito.mock(SessionMetadata.class);
    message.setSession(mock);
    VDBMetaData vdb = new VDBMetaData();
    DataPolicyMetadata dpm = new DataPolicyMetadata();
    dpm.setAnyAuthenticated(true);
    vdb.addDataPolicy(dpm);
    Mockito.stub(mock.getVdb()).toReturn(vdb);

    // unauthenticated
    Map<String, DataPolicy> map = message.getAllowedDataPolicies();
    assertEquals(0, map.size());

    // authenticated
    message = new DQPWorkContext();
    Mockito.stub(mock.getSubject()).toReturn(new Subject());
    message.setSession(mock);
    map = message.getAllowedDataPolicies();
    assertEquals(1, map.size());
  }
Пример #6
0
 /**
  * Create an unauthenticated session
  *
  * @param userName
  * @param app
  * @param vdb
  * @return
  */
 public static SessionMetadata createTemporarySession(
     String userName, String app, VDBMetaData vdb) {
   long creationTime = System.currentTimeMillis();
   SessionMetadata newSession = new SessionMetadata();
   newSession.setSessionToken(new SessionToken(userName));
   newSession.setSessionId(newSession.getSessionToken().getSessionID());
   newSession.setUserName(userName);
   newSession.setCreatedTime(creationTime);
   newSession.setApplicationName(app);
   newSession.setVDBName(vdb.getName());
   newSession.setVDBVersion(vdb.getVersion());
   newSession.setVdb(vdb);
   newSession.setEmbedded(true);
   return newSession;
 }