@Test public void testLogonAuthenticationTypeByVDB() throws Exception { VDBRepository repo = Mockito.mock(VDBRepository.class); ssi.setVDBRepository(repo); ssi.setAuthenticationType(AuthenticationType.GSS); addVdb(repo, "name", "SC", AuthenticationType.USERPASSWORD.name()); DQPWorkContext.setWorkContext(new DQPWorkContext()); Properties p = buildProperties("fred", "name"); LogonImpl impl = new LogonImpl(ssi, "fakeCluster"); LogonResult result = impl.logon(p); assertEquals("fred", result.getUserName()); VDBMetaData metadata = addVdb(repo, "name1", "SC", AuthenticationType.USERPASSWORD.name()); metadata.addProperty(SessionServiceImpl.Authentication.GSS.getPatternKey(), "GSS"); DQPWorkContext.setWorkContext(new DQPWorkContext()); impl = new LogonImpl(ssi, "fakeCluster"); p = buildProperties("fred", "name1"); result = impl.logon(p); assertEquals("fred", result.getUserName()); p = buildProperties("GSS", "name1"); 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()); try { p = buildProperties("GSS", "name"); result = impl.logon(p); assertEquals("GSS", result.getUserName()); } catch(LogonException e) { } addVdb(repo, "name2", "SC", "GSS"); DQPWorkContext.setWorkContext(new DQPWorkContext()); impl = new LogonImpl(ssi, "fakeCluster"); p = buildProperties("fred", "name2"); result = impl.logon(p); assertEquals(AuthenticationType.GSS, result.getProperty("authType")); metadata.addProperty(SessionServiceImpl.Authentication.GSS.getPatternKey(), "GSS"); DQPWorkContext.setWorkContext(new DQPWorkContext()); impl = new LogonImpl(ssi, "fakeCluster"); p = buildProperties(null, "name1"); result = impl.logon(p); assertEquals("anonymous", result.getUserName()); }
public LogonResult logon(Properties connProps) throws LogonException { String vdbName = connProps.getProperty(BaseDataSource.VDB_NAME); String vdbVersion = connProps.getProperty(BaseDataSource.VDB_VERSION); String user = connProps.getProperty(TeiidURL.CONNECTION.USER_NAME, CoreConstants.DEFAULT_ANON_USERNAME); boolean onlyAllowPassthrough = Boolean.valueOf(connProps.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "false")); AuthenticationType authType = AuthenticationType.USERPASSWORD; if (!onlyAllowPassthrough) { authType = this.service.getAuthenticationType(vdbName, vdbVersion, user); } switch (authType) { case GSS: if (connProps.get(ILogon.KRB5TOKEN) != null) { Object previous = null; boolean assosiated = false; SecurityHelper securityHelper = service.getSecurityHelper(); try { byte[] krb5Token = (byte[])connProps.get(ILogon.KRB5TOKEN); Object securityContext = this.gssServiceTickets.remove(Base64.encodeBytes(MD5(krb5Token))); if (securityContext == null) { throw new LogonException(RuntimePlugin.Event.TEIID40054, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40054)); } previous = securityHelper.associateSecurityContext(securityContext); assosiated = true; LogonResult result = logon(connProps, AuthenticationType.GSS, user); result.addProperty(ILogon.KRB5TOKEN, krb5Token); return result; } finally { if (assosiated) { securityHelper.associateSecurityContext(previous); } } } Version v = DQPWorkContext.getWorkContext().getClientVersion(); if (v.compareTo(Version.EIGHT_7) >= 0) { LogonResult result = new LogonResult(); result.addProperty(ILogon.AUTH_TYPE, authType); return result; } throw new LogonException(RuntimePlugin.Event.TEIID40149, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40149)); case USERPASSWORD: case SSL: return logon(connProps, authType, user); default: throw new LogonException(RuntimePlugin.Event.TEIID40055, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40055, authType)); } }
LogonImpl implements ILogon { public LogonResult logon(Properties connProps) throws LogonException { String vdbName = connProps.getProperty(BaseDataSource.VDB_NAME); String vdbVersion = connProps.getProperty(BaseDataSource.VDB_VERSION); String user = connProps.getProperty(TeiidURL.CONNECTION.USER_NAME, CoreConstants.DEFAULT_ANON_USERNAME); boolean onlyAllowPassthrough = Boolean.valueOf(connProps.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "false")); AuthenticationType authType = AuthenticationType.USERPASSWORD; if (!onlyAllowPassthrough) { authType = this.service.getAuthenticationType(vdbName, vdbVersion, user); } switch (authType) { case GSS: if (connProps.get(ILogon.KRB5TOKEN) != null) { Object previous = null; boolean assosiated = false; SecurityHelper securityHelper = service.getSecurityHelper(); try { byte[] krb5Token = (byte[])connProps.get(ILogon.KRB5TOKEN); Object securityContext = this.gssServiceTickets.remove(Base64.encodeBytes(MD5(krb5Token))); if (securityContext == null) { throw new LogonException(RuntimePlugin.Event.TEIID40054, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40054)); } previous = securityHelper.associateSecurityContext(securityContext); assosiated = true; LogonResult result = logon(connProps, AuthenticationType.GSS, user); result.addProperty(ILogon.KRB5TOKEN, krb5Token); return result; } finally { if (assosiated) { securityHelper.associateSecurityContext(previous); } } } Version v = DQPWorkContext.getWorkContext().getClientVersion(); if (v.compareTo(Version.EIGHT_7) >= 0) { LogonResult result = new LogonResult(); result.addProperty(ILogon.AUTH_TYPE, authType); return result; } throw new LogonException(RuntimePlugin.Event.TEIID40149, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40149)); case USERPASSWORD: case SSL: return logon(connProps, authType, user); default: throw new LogonException(RuntimePlugin.Event.TEIID40055, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40055, authType)); } } }
LogonImpl implements ILogon { public LogonResult logon(Properties connProps) throws LogonException { String vdbName = connProps.getProperty(BaseDataSource.VDB_NAME); String vdbVersion = connProps.getProperty(BaseDataSource.VDB_VERSION); String user = connProps.getProperty(TeiidURL.CONNECTION.USER_NAME, CoreConstants.DEFAULT_ANON_USERNAME); boolean onlyAllowPassthrough = Boolean.valueOf(connProps.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "false")); AuthenticationType authType = AuthenticationType.USERPASSWORD; if (!onlyAllowPassthrough) { authType = this.service.getAuthenticationType(vdbName, vdbVersion, user); } switch (authType) { case GSS: if (connProps.get(ILogon.KRB5TOKEN) != null) { Object previous = null; boolean assosiated = false; SecurityHelper securityHelper = service.getSecurityHelper(); try { byte[] krb5Token = (byte[])connProps.get(ILogon.KRB5TOKEN); Object securityContext = this.gssServiceTickets.remove(Base64.encodeBytes(MD5(krb5Token))); if (securityContext == null) { throw new LogonException(RuntimePlugin.Event.TEIID40054, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40054)); } previous = securityHelper.associateSecurityContext(securityContext); assosiated = true; LogonResult result = logon(connProps, AuthenticationType.GSS, user); result.addProperty(ILogon.KRB5TOKEN, krb5Token); return result; } finally { if (assosiated) { securityHelper.associateSecurityContext(previous); } } } Version v = DQPWorkContext.getWorkContext().getClientVersion(); if (v.compareTo(Version.EIGHT_7) >= 0) { LogonResult result = new LogonResult(); result.addProperty(ILogon.AUTH_TYPE, authType); return result; } throw new LogonException(RuntimePlugin.Event.TEIID40149, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40149)); case USERPASSWORD: case SSL: return logon(connProps, authType, user); default: throw new LogonException(RuntimePlugin.Event.TEIID40055, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40055, authType)); } } LogonImpl(SessionService service, String clusterName); }
LogonImpl implements ILogon { public LogonResult logon(Properties connProps) throws LogonException { String vdbName = connProps.getProperty(BaseDataSource.VDB_NAME); String vdbVersion = connProps.getProperty(BaseDataSource.VDB_VERSION); String user = connProps.getProperty(TeiidURL.CONNECTION.USER_NAME, CoreConstants.DEFAULT_ANON_USERNAME); boolean onlyAllowPassthrough = Boolean.valueOf(connProps.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "false")); AuthenticationType authType = AuthenticationType.USERPASSWORD; if (!onlyAllowPassthrough) { authType = this.service.getAuthenticationType(vdbName, vdbVersion, user); } switch (authType) { case GSS: if (connProps.get(ILogon.KRB5TOKEN) != null) { Object previous = null; boolean assosiated = false; SecurityHelper securityHelper = service.getSecurityHelper(); try { byte[] krb5Token = (byte[])connProps.get(ILogon.KRB5TOKEN); Object securityContext = this.gssServiceTickets.remove(Base64.encodeBytes(MD5(krb5Token))); if (securityContext == null) { throw new LogonException(RuntimePlugin.Event.TEIID40054, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40054)); } previous = securityHelper.associateSecurityContext(securityContext); assosiated = true; LogonResult result = logon(connProps, AuthenticationType.GSS, user); result.addProperty(ILogon.KRB5TOKEN, krb5Token); return result; } finally { if (assosiated) { securityHelper.associateSecurityContext(previous); } } } Version v = DQPWorkContext.getWorkContext().getClientVersion(); if (v.compareTo(Version.EIGHT_7) >= 0) { LogonResult result = new LogonResult(); result.addProperty(ILogon.AUTH_TYPE, authType); return result; } throw new LogonException(RuntimePlugin.Event.TEIID40149, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40149)); case USERPASSWORD: case SSL: return logon(connProps, authType, user); default: throw new LogonException(RuntimePlugin.Event.TEIID40055, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40055, authType)); } } LogonImpl(SessionService service, String clusterName); LogonResult logon(Properties connProps); @Override LogonResult neogitiateGssLogin(Properties connProps, byte[] serviceTicket, boolean createSession); GSSResult neogitiateGssLogin(byte[] serviceTicket, String vdbName,
            String vdbVersion, String user); ResultsFuture<?> logoff(); ResultsFuture<?> ping(); @Override ResultsFuture<?> ping(Collection<String> sessions); @Override void assertIdentity(SessionToken checkSession); SessionService getSessionService(); }
LogonImpl implements ILogon { public LogonResult logon(Properties connProps) throws LogonException { String vdbName = connProps.getProperty(BaseDataSource.VDB_NAME); String vdbVersion = connProps.getProperty(BaseDataSource.VDB_VERSION); String user = connProps.getProperty(TeiidURL.CONNECTION.USER_NAME, CoreConstants.DEFAULT_ANON_USERNAME); boolean onlyAllowPassthrough = Boolean.valueOf(connProps.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, "false")); AuthenticationType authType = AuthenticationType.USERPASSWORD; if (!onlyAllowPassthrough) { authType = this.service.getAuthenticationType(vdbName, vdbVersion, user); } switch (authType) { case GSS: if (connProps.get(ILogon.KRB5TOKEN) != null) { Object previous = null; boolean assosiated = false; SecurityHelper securityHelper = service.getSecurityHelper(); try { byte[] krb5Token = (byte[])connProps.get(ILogon.KRB5TOKEN); Object securityContext = this.gssServiceTickets.remove(Base64.encodeBytes(MD5(krb5Token))); if (securityContext == null) { throw new LogonException(RuntimePlugin.Event.TEIID40054, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40054)); } previous = securityHelper.associateSecurityContext(securityContext); assosiated = true; LogonResult result = logon(connProps, AuthenticationType.GSS, user); result.addProperty(ILogon.KRB5TOKEN, krb5Token); return result; } finally { if (assosiated) { securityHelper.associateSecurityContext(previous); } } } Version v = DQPWorkContext.getWorkContext().getClientVersion(); if (v.compareTo(Version.EIGHT_7) >= 0) { LogonResult result = new LogonResult(); result.addProperty(ILogon.AUTH_TYPE, authType); return result; } throw new LogonException(RuntimePlugin.Event.TEIID40149, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40149)); case USERPASSWORD: case SSL: return logon(connProps, authType, user); default: throw new LogonException(RuntimePlugin.Event.TEIID40055, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40055, authType)); } } LogonImpl(SessionService service, String clusterName); LogonResult logon(Properties connProps); @Override LogonResult neogitiateGssLogin(Properties connProps, byte[] serviceTicket, boolean createSession); GSSResult neogitiateGssLogin(byte[] serviceTicket, String vdbName,
            String vdbVersion, String user); ResultsFuture<?> logoff(); ResultsFuture<?> ping(); @Override ResultsFuture<?> ping(Collection<String> sessions); @Override void assertIdentity(SessionToken checkSession); SessionService getSessionService();  }