@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()); String userName = "Fred"; 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); LogonImpl impl = new LogonImpl(ssi, "fakeCluster"); LogonResult result = impl.logon(p); assertEquals(userName, result.getUserName()); assertEquals(String.valueOf(1), result.getSessionID()); }
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();  }