Search in sources :

Example 26 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class ODBCServerRemoteImpl method setConnectionProperties.

public static void setConnectionProperties(ConnectionImpl conn) throws SQLException {
    SessionMetadata sm = ((LocalServerConnection) conn.getServerConnection()).getWorkContext().getSession();
    VDB vdb = sm.getVdb();
    Properties p = vdb.getProperties();
    setConnectionProperties(conn, p);
}
Also used : VDB(org.teiid.adminapi.VDB) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) Properties(java.util.Properties)

Example 27 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class TestSessionServiceImpl method testSecurityDomain.

@Test
public void testSecurityDomain() throws Exception {
    VDBRepository repo = Mockito.mock(VDBRepository.class);
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("name");
    vdb.setVersion(1);
    vdb.setStatus(Status.ACTIVE);
    vdb.addProperty(SessionServiceImpl.SECURITY_DOMAIN_PROPERTY, "domain");
    Mockito.stub(repo.getLiveVDB("name", "1")).toReturn(vdb);
    ssi.setVDBRepository(repo);
    Properties properties = new Properties();
    properties.setProperty(TeiidURL.JDBC.VDB_NAME, "name.1");
    SessionMetadata s = ssi.createSession("name", "1", AuthenticationType.USERPASSWORD, "x", new Credentials(new char[] { 'y' }), "z", properties);
    assertEquals("domain", s.getSecurityDomain());
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Credentials(org.teiid.security.Credentials) Test(org.junit.Test)

Example 28 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class TestSessionServiceImpl method testLegacySecurityDomain.

@Test
public void testLegacySecurityDomain() throws Exception {
    VDBRepository repo = Mockito.mock(VDBRepository.class);
    VDBMetaData vdb = new VDBMetaData();
    vdb.setName("name");
    vdb.setVersion(1);
    vdb.setStatus(Status.ACTIVE);
    Mockito.stub(repo.getLiveVDB("name", "1")).toReturn(vdb);
    ssi.setVDBRepository(repo);
    ssi.setSecurityDomain("sd");
    Properties properties = new Properties();
    properties.setProperty(TeiidURL.JDBC.VDB_NAME, "name.1");
    SessionMetadata s = ssi.createSession("name", "1", AuthenticationType.USERPASSWORD, "x@sd", new Credentials(new char[] { 'y' }), "z", properties);
    assertEquals("sd", s.getSecurityDomain());
    s = ssi.createSession("name", "1", AuthenticationType.USERPASSWORD, "x", new Credentials(new char[] { 'y' }), "z", properties);
    assertEquals("sd", s.getSecurityDomain());
    ssi.setAllowSecurityDomainQualifier(true);
    ssi.setSecurityDomain("sd");
    s = ssi.createSession("name", "1", AuthenticationType.USERPASSWORD, "x@sd", new Credentials(new char[] { 'y' }), "z", properties);
    assertEquals("sd", s.getSecurityDomain());
    assertEquals("x", s.getUserName());
    ssi.setAllowSecurityDomainQualifier(false);
    s = ssi.createSession("name", "1", AuthenticationType.USERPASSWORD, "x@sd", new Credentials(new char[] { 'y' }), "z", properties);
    assertEquals("sd", s.getSecurityDomain());
    assertEquals("x@sd", s.getUserName());
}
Also used : VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Credentials(org.teiid.security.Credentials) Test(org.junit.Test)

Example 29 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class TestLogonImpl method testLogonResult.

@Test
public void testLogonResult() throws Exception {
    SessionService ssi = Mockito.mock(SessionService.class);
    Mockito.stub(ssi.getAuthenticationType(Mockito.anyString(), Mockito.anyString(), Mockito.anyString())).toReturn(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    String userName = "Fred";
    // $NON-NLS-1$
    String applicationName = "test";
    Properties p = new Properties();
    p.setProperty(TeiidURL.CONNECTION.USER_NAME, userName);
    p.setProperty(TeiidURL.CONNECTION.APP_NAME, applicationName);
    p.setProperty(TeiidURL.JDBC.VDB_NAME, "x");
    p.setProperty(TeiidURL.JDBC.VDB_VERSION, "1");
    SessionMetadata session = new SessionMetadata();
    session.setUserName(userName);
    session.setApplicationName(applicationName);
    session.setSessionId(String.valueOf(1));
    session.setSessionToken(new SessionToken(1, userName));
    Mockito.stub(ssi.createSession("x", "1", AuthenticationType.USERPASSWORD, userName, null, applicationName, p)).toReturn(session);
    // $NON-NLS-1$
    LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
    LogonResult result = impl.logon(p);
    assertEquals(userName, result.getUserName());
    assertEquals(String.valueOf(1), result.getSessionID());
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionService(org.teiid.dqp.service.SessionService) SessionToken(org.teiid.client.security.SessionToken) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) Test(org.junit.Test)

Example 30 with SessionMetadata

use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.

the class SessionCheckingProxy method invoke.

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    Throwable exception = null;
    try {
        DQPWorkContext workContext = DQPWorkContext.getWorkContext();
        if (workContext.getSession().isClosed() || workContext.getSessionId() == null) {
            if (method.getName().equals("closeRequest")) {
                // there's no need for this to raise an exception
                return ResultsFuture.NULL_FUTURE;
            }
            String sessionID = workContext.getSession().getSessionId();
            if (sessionID == null) {
                throw new InvalidSessionException(RuntimePlugin.Event.TEIID40041, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40041));
            }
            workContext.setSession(new SessionMetadata());
            throw new InvalidSessionException(RuntimePlugin.Event.TEIID40042, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40042, sessionID));
        }
        return super.invoke(proxy, method, args);
    } catch (InvocationTargetException e) {
        exception = e.getTargetException();
    } catch (Throwable t) {
        exception = t;
    }
    throw ExceptionUtil.convertException(method, exception);
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)35 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)9 Properties (java.util.Properties)6 InvalidSessionException (org.teiid.client.security.InvalidSessionException)6 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)5 SessionServiceException (org.teiid.dqp.service.SessionServiceException)5 List (java.util.List)4 LoginException (javax.security.auth.login.LoginException)4 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)4 LogonException (org.teiid.client.security.LogonException)4 SessionToken (org.teiid.client.security.SessionToken)4 Credentials (org.teiid.security.Credentials)4 ArrayList (java.util.ArrayList)3 Subject (javax.security.auth.Subject)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 SQLException (java.sql.SQLException)2 LogonResult (org.teiid.client.security.LogonResult)2 CompositeVDB (org.teiid.deployers.CompositeVDB)2 VDBLifeCycleListener (org.teiid.deployers.VDBLifeCycleListener)2