use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class SessionServiceImpl method createSession.
@Override
public SessionMetadata createSession(String vdbName, String vdbVersion, AuthenticationType authType, String userName, Credentials credentials, String applicationName, Properties properties) throws LoginException, SessionServiceException {
ArgCheck.isNotNull(applicationName);
ArgCheck.isNotNull(properties);
Object securityContext = null;
Subject subject = null;
String hostName = properties.getProperty(TeiidURL.CONNECTION.CLIENT_HOSTNAME);
String ipAddress = properties.getProperty(TeiidURL.CONNECTION.CLIENT_IP_ADDRESS);
String clientMac = properties.getProperty(TeiidURL.CONNECTION.CLIENT_MAC);
boolean onlyAllowPassthrough = Boolean.valueOf(properties.getProperty(TeiidURL.CONNECTION.PASSTHROUGH_AUTHENTICATION, // $NON-NLS-1$
"false"));
AuditMessage.LogonInfo info = new AuditMessage.LogonInfo(vdbName, vdbVersion, authType.toString(), userName, applicationName, hostName, ipAddress, clientMac, onlyAllowPassthrough);
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_AUDITLOGGING, MessageLevel.DETAIL)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_AUDITLOGGING, new AuditMessage("session", "logon-request", info, null));
}
try {
// Validate VDB and version if logging on to server product...
VDBMetaData vdb = null;
if (vdbName != null) {
vdb = getActiveVDB(vdbName, vdbVersion);
if (vdb == null) {
throw new SessionServiceException(RuntimePlugin.Event.TEIID40046, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40046, vdbName, vdbVersion));
}
}
if (sessionMaxLimit > 0 && getActiveSessionsCount() >= sessionMaxLimit) {
throw new SessionServiceException(RuntimePlugin.Event.TEIID40043, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40043, new Long(sessionMaxLimit)));
}
String securityDomain = getSecurityDomain(userName, vdbName, vdbVersion, vdb);
if (securityDomain != null) {
// Authenticate user...
// if not authenticated, this method throws exception
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] { "authenticateUser", userName, applicationName });
String baseUserName = userName;
if (allowSecurityDomainQualifier) {
baseUserName = getBaseUsername(userName);
}
if (onlyAllowPassthrough || authType.equals(AuthenticationType.GSS)) {
subject = this.securityHelper.getSubjectInContext(securityDomain);
if (subject == null) {
if ((!onlyAllowPassthrough || !(trustAllLocal && DQPWorkContext.getWorkContext().isLocal()))) {
throw new LoginException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40087));
}
} else {
userName = getUserName(subject, baseUserName);
}
securityContext = this.securityHelper.getSecurityContext();
} else {
userName = baseUserName;
securityContext = this.securityHelper.authenticate(securityDomain, baseUserName, credentials, applicationName);
subject = this.securityHelper.getSubjectInContext(securityContext);
}
} else {
LogManager.logDetail(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40117));
}
long creationTime = System.currentTimeMillis();
// Return a new session info object
SessionMetadata newSession = new SessionMetadata();
newSession.setSessionToken(new SessionToken(userName));
newSession.setSessionId(newSession.getSessionToken().getSessionID());
newSession.setUserName(userName);
newSession.setCreatedTime(creationTime);
newSession.setApplicationName(applicationName);
newSession.setClientHostName(hostName);
newSession.setIPAddress(ipAddress);
newSession.setClientHardwareAddress(clientMac);
newSession.setSecurityDomain(securityDomain);
if (vdb != null) {
newSession.setVDBName(vdb.getName());
newSession.setVDBVersion(vdb.getVersion());
}
// these are local no need for monitoring.
newSession.setSubject(subject);
newSession.setSecurityContext(securityContext);
newSession.setVdb(vdb);
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_SECURITY, MessageLevel.DETAIL)) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] { "Logon successful, created", newSession });
}
this.sessionCache.put(newSession.getSessionId(), newSession);
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_AUDITLOGGING, MessageLevel.DETAIL)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_AUDITLOGGING, new AuditMessage("session", "logon-success", newSession));
}
return newSession;
} catch (LoginException e) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_AUDITLOGGING, MessageLevel.DETAIL)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_AUDITLOGGING, new AuditMessage("session", "logon-fail", info, e));
}
throw e;
} catch (SessionServiceException e) {
if (LogManager.isMessageToBeRecorded(LogConstants.CTX_AUDITLOGGING, MessageLevel.DETAIL)) {
// $NON-NLS-1$ //$NON-NLS-2$
LogManager.logDetail(LogConstants.CTX_AUDITLOGGING, new AuditMessage("session", "logon-fail", info, e));
}
throw e;
}
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class SessionServiceImpl method monitorSessions.
// -----------------------------------------------------------------------------------
// S E R V I C E - R E L A T E D M E T H O D S
// -----------------------------------------------------------------------------------
private void monitorSessions() {
long currentTime = System.currentTimeMillis();
for (SessionMetadata info : sessionCache.values()) {
try {
if (CHECK_PING && !info.isEmbedded() && !info.isActive() && currentTime - info.getLastPingTime() > ServerConnection.PING_INTERVAL * 5) {
LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40007, info.getSessionId()));
closeSession(info.getSessionId());
} else if (sessionExpirationTimeLimit > 0 && currentTime - info.getCreatedTime() > sessionExpirationTimeLimit) {
LogManager.logInfo(LogConstants.CTX_SECURITY, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40008, info.getSessionId()));
closeSession(info.getSessionId());
}
} catch (Exception e) {
// $NON-NLS-1$
LogManager.logDetail(LogConstants.CTX_SECURITY, e, "error running session monitor, unable to monitor:", info.getSessionId());
}
}
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class LogonImpl method updateDQPContext.
private void updateDQPContext(SessionMetadata s) {
DQPWorkContext workContext = DQPWorkContext.getWorkContext();
SessionMetadata old = workContext.getSession();
if (old.getSessionId() != null) {
old.setActive(false);
}
workContext.setSession(s);
if (s.getSessionId() != null) {
s.setActive(true);
}
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class LogonImpl method assertIdentity.
@Override
public void assertIdentity(SessionToken checkSession) throws InvalidSessionException, TeiidComponentException {
if (checkSession == null) {
// disassociate
this.updateDQPContext(new SessionMetadata());
return;
}
SessionMetadata sessionInfo = null;
try {
sessionInfo = this.service.validateSession(checkSession.getSessionID());
} catch (SessionServiceException e) {
throw new TeiidComponentException(RuntimePlugin.Event.TEIID40062, e);
}
if (sessionInfo == null) {
throw new InvalidSessionException(RuntimePlugin.Event.TEIID40063);
}
SessionToken st = sessionInfo.getSessionToken();
if (!st.equals(checkSession)) {
throw new InvalidSessionException(RuntimePlugin.Event.TEIID40064);
}
this.updateDQPContext(sessionInfo);
}
use of org.teiid.adminapi.impl.SessionMetadata in project teiid by teiid.
the class TestODBCSocketTransport method checkApplicationName.
private void checkApplicationName(Statement s, String value) throws SQLException {
ResultSet rs = s.executeQuery("show application_name");
rs.next();
assertEquals(value, rs.getString(1));
rs.close();
rs = s.executeQuery("select session_id()");
rs.next();
String sessionId = rs.getString(1);
rs.close();
SessionMetadata current = null;
for (SessionMetadata session : odbcServer.server.getSessionService().getActiveSessions()) {
if (session.getSessionId().equals(sessionId)) {
current = session;
break;
}
}
assertEquals(value, current.getApplicationName());
}
Aggregations