use of org.teiid.security.SecurityHelper in project teiid by teiid.
the class TestDQPWorkContext method testRestoreSecurityContext.
@Test
public void testRestoreSecurityContext() {
final SecurityHelper sc = new SecurityHelper() {
Object mycontext = null;
@Override
public Object getSecurityContext() {
return this.mycontext;
}
@Override
public void clearSecurityContext() {
this.mycontext = null;
}
@Override
public Object associateSecurityContext(Object context) {
Object old = mycontext;
this.mycontext = context;
return old;
}
@Override
public Subject getSubjectInContext(Object context) {
return null;
}
@Override
public Subject getSubjectInContext(String securityDomain) {
return null;
}
@Override
public Object authenticate(String securityDomain, String baseUserName, Credentials credentials, String applicationName) throws LoginException {
return null;
}
@Override
public GSSResult negotiateGssLogin(String securityDomain, byte[] serviceTicket) throws LoginException {
return null;
}
};
Object previousSC = "testSC";
sc.associateSecurityContext(previousSC);
DQPWorkContext message = new DQPWorkContext() {
@Override
public Subject getSubject() {
return new Subject();
}
};
message.setSecurityHelper(sc);
message.setSession(Mockito.mock(SessionMetadata.class));
// $NON-NLS-1$
final String currentSC = "teiid-security-context";
Mockito.stub(message.getSession().getSecurityContext()).toReturn(currentSC);
Runnable r = new Runnable() {
@Override
public void run() {
assertEquals(currentSC, sc.getSecurityContext());
}
};
message.runInContext(r);
assertEquals(previousSC, sc.getSecurityContext());
}
use of org.teiid.security.SecurityHelper in project teiid by teiid.
the class TestLocalConnections method testPassThroughDifferentUsers.
@Test
public void testPassThroughDifferentUsers() throws Throwable {
MockSecurityHelper securityHelper = new MockSecurityHelper();
SecurityHelper current = server.getSessionService().getSecurityHelper();
server.getClientServiceRegistry().setSecurityHelper(securityHelper);
server.getSessionService().setSecurityHelper(securityHelper);
try {
final Connection c = server.createConnection("jdbc:teiid:PartsSupplier;PassthroughAuthentication=true");
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select session_id()");
Subject o = currentContext;
currentContext = null;
s.cancel();
currentContext = o;
rs.next();
String id = rs.getString(1);
rs.close();
assertEquals(4, securityHelper.calls);
server.getSessionService().pingServer(id);
currentContext = new Subject();
currentContext.getPrincipals().add(new SimplePrincipal("x"));
rs = s.executeQuery("select session_id()");
rs.next();
String id1 = rs.getString(1);
rs.close();
assertFalse(id.equals(id1));
try {
server.getSessionService().pingServer(id);
// should have logged off
fail();
} catch (InvalidSessionException e) {
}
} finally {
server.getClientServiceRegistry().setSecurityHelper(current);
server.getSessionService().setSecurityHelper(current);
}
}
use of org.teiid.security.SecurityHelper in project teiid by teiid.
the class TestPassthroughAuthentication method oneTimeSetup.
@BeforeClass
public static void oneTimeSetup() throws Exception {
server.setUseCallingThread(true);
server.start(new EmbeddedConfiguration() {
@Override
public SecurityHelper getSecurityHelper() {
return securityHelper;
}
}, false);
}
use of org.teiid.security.SecurityHelper in project teiid by teiid.
the class LogonImpl method logon.
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, // $NON-NLS-1$
"false"));
AuthenticationType authType = AuthenticationType.USERPASSWORD;
if (!onlyAllowPassthrough) {
authType = this.service.getAuthenticationType(vdbName, vdbVersion, user);
}
// the presence of the KRB5 token take as GSS based login.
if (connProps.get(ILogon.KRB5TOKEN) != null) {
if (authType == AuthenticationType.GSS) {
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;
return logon(connProps, krb5Token, AuthenticationType.GSS, user);
} finally {
if (assosiated) {
securityHelper.associateSecurityContext(previous);
}
}
} else {
// shouldn't really get here, but we'll try user name password anyway
}
} else if (authType == AuthenticationType.GSS) {
Version v = DQPWorkContext.getWorkContext().getClientVersion();
// send a login result with a GSS challange
if (v.compareTo(Version.EIGHT_7) >= 0) {
LogonResult result = new LogonResult();
result.addProperty(ILogon.AUTH_TYPE, authType);
return result;
}
// throw an exception
throw new LogonException(RuntimePlugin.Event.TEIID40149, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40149));
}
if (!AuthenticationType.USERPASSWORD.equals(authType)) {
throw new LogonException(RuntimePlugin.Event.TEIID40055, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40055, authType));
}
return logon(connProps, null, AuthenticationType.USERPASSWORD, user);
}
use of org.teiid.security.SecurityHelper in project teiid by teiid.
the class TestLocalConnections method testSimulateGSSWithODBC.
@Test
public void testSimulateGSSWithODBC() throws Throwable {
SecurityHelper securityHelper = new MockSecurityHelper();
SecurityHelper current = server.getSessionService().getSecurityHelper();
server.getClientServiceRegistry().setSecurityHelper(securityHelper);
server.getSessionService().setSecurityHelper(securityHelper);
server.getSessionService().setAuthenticationType(AuthenticationType.GSS);
final byte[] token = "This is test of Partial GSS API".getBytes();
final AtomicBoolean set = new AtomicBoolean(true);
LogonImpl login = new LogonImpl(server.getSessionService(), null) {
@Override
public LogonResult logon(Properties connProps) throws LogonException {
if (set.get()) {
this.gssServiceTickets.put(Base64.encodeBytes(MD5(token)), currentContext);
set.set(false);
}
return super.logon(connProps);
}
};
server.getClientServiceRegistry().registerClientService(ILogon.class, login, LogConstants.CTX_SECURITY);
try {
Properties prop = new Properties();
prop.put(ILogon.KRB5TOKEN, token);
final Connection c = server.createConnection("jdbc:teiid:PartsSupplier;user=GSS", prop);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("select session_id()");
Subject o = currentContext;
currentContext = null;
s.cancel();
currentContext = o;
rs.next();
String id = rs.getString(1);
rs.close();
} finally {
server.getSessionService().setAuthenticationType(AuthenticationType.USERPASSWORD);
server.getClientServiceRegistry().setSecurityHelper(current);
server.getSessionService().setSecurityHelper(current);
}
}
Aggregations