예제 #1
0
 /**
  * The user name or null if the session has not yet been established.
  *
  * @return
  */
 public String getPrincipal() {
   Session s = getSession();
   if (s != null) {
     return s.getUserName();
   }
   return null;
 }
  @Test
  public void testSessions() throws Exception {
    deployVdb();

    Collection<? extends Session> sessions = admin.getSessions();
    assertEquals(0, sessions.size());

    Connection conn =
        TeiidDriver.getInstance()
            .connect(
                "jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user;ApplicationName=test",
                null);
    sessions = admin.getSessions();
    assertEquals(1, sessions.size());
    Session s = sessions.iterator().next();

    assertEquals("user@teiid-security", s.getUserName());
    assertEquals("test", s.getApplicationName());
    assertEquals("bqt", s.getVDBName());
    assertEquals(1, s.getVDBVersion());
    assertNotNull(s.getSessionId());

    conn.close();

    conn =
        TeiidDriver.getInstance()
            .connect(
                "jdbc:teiid:bqt@mm://localhost:31000;user=user;password=user;ApplicationName=test",
                null);
    sessions = admin.getSessions();
    assertEquals(1, sessions.size());
    s = sessions.iterator().next();

    admin.terminateSession(s.getSessionId());
    sessions = admin.getSessions();
    assertEquals(0, sessions.size());
    conn.close();
  }