Search in sources :

Example 11 with LogonResult

use of org.teiid.client.security.LogonResult in project teiid by teiid.

the class SocketServerConnection method logon.

private void logon(ILogon newLogon, boolean logoff) throws LogonException, TeiidComponentException, CommunicationException {
    SocketServerInstance instance = this.serverInstance;
    updateConnectionProperties(connProps, instance.getLocalAddress(), true);
    LogonResult newResult = null;
    // - if gss
    if (connProps.contains(TeiidURL.CONNECTION.JAAS_NAME)) {
        newResult = MakeGSS.authenticate(newLogon, connProps);
    } else {
        newResult = newLogon.logon(connProps);
    }
    AuthenticationType type = (AuthenticationType) newResult.getProperty(ILogon.AUTH_TYPE);
    if (type != null) {
        // server has issued an additional challange
        if (type == AuthenticationType.GSS) {
            newResult = MakeGSS.authenticate(newLogon, connProps);
        } else {
            throw new LogonException(JDBCPlugin.Event.TEIID20034, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID20034, type));
        }
    }
    if (logoff) {
        LogonResult old = this.logonResults.remove(this.serverInstance.getHostInfo());
        this.connectionFactory.disconnected(this.serverInstance, old.getSessionToken());
        logoffAll();
    }
    this.logonResult = newResult;
    this.logonResults.put(instance.getHostInfo(), this.logonResult);
    this.connectionFactory.connected(instance, this.logonResult.getSessionToken());
}
Also used : LogonException(org.teiid.client.security.LogonException) LogonResult(org.teiid.client.security.LogonResult)

Example 12 with LogonResult

use of org.teiid.client.security.LogonResult in project teiid by teiid.

the class TestFailover method createListener.

private SocketListener createListener(InetSocketAddress address, SSLConfiguration config) {
    ClientServiceRegistryImpl server = new ClientServiceRegistryImpl() {

        @Override
        public ClassLoader getCallerClassloader() {
            return getClass().getClassLoader();
        }
    };
    SessionService ss = mock(SessionService.class);
    server.registerClientService(ILogon.class, new // $NON-NLS-1$
    LogonImpl(// $NON-NLS-1$
    ss, // $NON-NLS-1$
    "fakeCluster") {

        @Override
        public LogonResult logon(Properties connProps) throws LogonException {
            logonAttempts++;
            return new LogonResult(new SessionToken("dummy"), "x", "z");
        }

        @Override
        public ResultsFuture<?> ping() throws InvalidSessionException, TeiidComponentException {
            return ResultsFuture.NULL_FUTURE;
        }

        @Override
        public void assertIdentity(SessionToken checkSession) throws InvalidSessionException, TeiidComponentException {
            throw new InvalidSessionException();
        }
    }, null);
    server.registerClientService(FakeService.class, new TestSocketRemoting.FakeServiceImpl(), null);
    return new SocketListener(new InetSocketAddress(address.getAddress().getHostAddress(), address.getPort()), 0, 0, 2, config, server, BufferManagerFactory.getStandaloneBufferManager());
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionToken(org.teiid.client.security.SessionToken) InetSocketAddress(java.net.InetSocketAddress) LogonResult(org.teiid.client.security.LogonResult) Properties(java.util.Properties) ResultsFuture(org.teiid.client.util.ResultsFuture) SessionService(org.teiid.dqp.service.SessionService) LogonException(org.teiid.client.security.LogonException) TeiidComponentException(org.teiid.core.TeiidComponentException)

Example 13 with LogonResult

use of org.teiid.client.security.LogonResult in project teiid by teiid.

the class TestLogonImpl method testLogonAuthenticationType.

@Test
public void testLogonAuthenticationType() throws Exception {
    VDBRepository repo = Mockito.mock(VDBRepository.class);
    VDBMetaData vdb = new VDBMetaData();
    vdb.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    vdb.setName("name");
    vdb.setVersion(1);
    vdb.setStatus(Status.ACTIVE);
    Mockito.stub(repo.getLiveVDB("name", "1")).toReturn(vdb);
    ssi.setVDBRepository(repo);
    ssi.setSecurityDomain("SC");
    // default transport - what Teiid has before TEIID-2863
    // this is transport default
    ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    Properties p = buildProperties("fred", "name");
    // $NON-NLS-1$
    LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
    LogonResult result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    // if no preference then choose USERPASSWORD
    // this is transport default
    ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    p = buildProperties("fred", "name");
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    // if user name is set to "GSS", then the preference is set to "GSS"
    // this is transport default
    ssi.setAuthenticationType(AuthenticationType.USERPASSWORD);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    p = buildProperties("GSS", "name");
    // $NON-NLS-1$
    FakeGssLogonImpl fimpl = new FakeGssLogonImpl(ssi, "fakeCluster");
    fimpl.addToken("bytes".getBytes(), new Subject());
    p.put(ILogon.KRB5TOKEN, "bytes".getBytes());
    result = fimpl.logon(p);
    assertEquals("GSS", result.getUserName());
    // if the transport default defined as GSS, then preference is USERPASSWORD, additional challenge
    ssi.setAuthenticationType(AuthenticationType.GSS);
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    p = buildProperties("fred", "name");
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    result = impl.logon(p);
    assertEquals(AuthenticationType.GSS, result.getProperty("authType"));
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LogonResult(org.teiid.client.security.LogonResult) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 14 with LogonResult

use of org.teiid.client.security.LogonResult in project teiid by teiid.

the class TestLogonImpl method testLogonAuthenticationTypeByVDB.

@Test
public void testLogonAuthenticationTypeByVDB() throws Exception {
    VDBRepository repo = Mockito.mock(VDBRepository.class);
    ssi.setVDBRepository(repo);
    // when VDB value is is avavailble this will not be used
    ssi.setAuthenticationType(AuthenticationType.GSS);
    // default transport - what Teiid has before TEIID-2863
    addVdb(repo, "name", "SC", AuthenticationType.USERPASSWORD.name());
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    Properties p = buildProperties("fred", "name");
    // $NON-NLS-1$
    LogonImpl impl = new LogonImpl(ssi, "fakeCluster");
    LogonResult result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    // if no preference then choose USERPASSWORD
    VDBMetaData metadata = addVdb(repo, "name1", "SC", AuthenticationType.USERPASSWORD.name());
    metadata.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties("fred", "name1");
    result = impl.logon(p);
    assertEquals("fred", result.getUserName());
    p = buildProperties("GSS", "name1");
    // $NON-NLS-1$
    FakeGssLogonImpl fimpl = new FakeGssLogonImpl(ssi, "fakeCluster");
    fimpl.addToken("bytes".getBytes(), new Subject());
    p.put(ILogon.KRB5TOKEN, "bytes".getBytes());
    result = fimpl.logon(p);
    assertEquals("GSS", result.getUserName());
    // here preference is GSS
    try {
        p = buildProperties("GSS", "name");
        result = impl.logon(p);
        assertEquals("GSS", result.getUserName());
    } catch (LogonException e) {
    }
    // if the transport default defined as GSS, then preference is USERPASSWORD, additional challenge
    addVdb(repo, "name2", "SC", "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties("fred", "name2");
    result = impl.logon(p);
    assertEquals(AuthenticationType.GSS, result.getProperty("authType"));
    // doesn't match gss pattern
    metadata.addProperty(SessionServiceImpl.GSS_PATTERN_PROPERTY, "GSS");
    DQPWorkContext.setWorkContext(new DQPWorkContext());
    // $NON-NLS-1$
    impl = new LogonImpl(ssi, "fakeCluster");
    p = buildProperties(null, "name1");
    result = impl.logon(p);
    assertEquals("anonymous", result.getUserName());
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LogonException(org.teiid.client.security.LogonException) LogonResult(org.teiid.client.security.LogonResult) VDBRepository(org.teiid.deployers.VDBRepository) Properties(java.util.Properties) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 15 with LogonResult

use of org.teiid.client.security.LogonResult 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)

Aggregations

LogonResult (org.teiid.client.security.LogonResult)15 LogonException (org.teiid.client.security.LogonException)9 Properties (java.util.Properties)7 Test (org.junit.Test)5 SessionToken (org.teiid.client.security.SessionToken)5 TeiidComponentException (org.teiid.core.TeiidComponentException)4 ServerConnection (org.teiid.net.ServerConnection)4 Subject (javax.security.auth.Subject)3 DQP (org.teiid.client.DQP)3 ResultsFuture (org.teiid.client.util.ResultsFuture)3 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)3 CommunicationException (org.teiid.net.CommunicationException)3 GSSCredential (org.ietf.jgss.GSSCredential)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)2 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 InvalidSessionException (org.teiid.client.security.InvalidSessionException)2 VDBRepository (org.teiid.deployers.VDBRepository)2 SessionService (org.teiid.dqp.service.SessionService)2 TeiidSQLException (org.teiid.jdbc.TeiidSQLException)2