Search in sources :

Example 31 with SessionMetadata

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;
    }
}
Also used : AuditMessage(org.teiid.logging.AuditMessage) SessionToken(org.teiid.client.security.SessionToken) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) Subject(javax.security.auth.Subject) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) LoginException(javax.security.auth.login.LoginException) SessionServiceException(org.teiid.dqp.service.SessionServiceException)

Example 32 with SessionMetadata

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());
        }
    }
}
Also used : SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) LoginException(javax.security.auth.login.LoginException) InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionServiceException(org.teiid.dqp.service.SessionServiceException) LogonException(org.teiid.client.security.LogonException)

Example 33 with SessionMetadata

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);
    }
}
Also used : DQPWorkContext(org.teiid.dqp.internal.process.DQPWorkContext) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata)

Example 34 with SessionMetadata

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);
}
Also used : InvalidSessionException(org.teiid.client.security.InvalidSessionException) SessionToken(org.teiid.client.security.SessionToken) SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) TeiidComponentException(org.teiid.core.TeiidComponentException) SessionServiceException(org.teiid.dqp.service.SessionServiceException)

Example 35 with SessionMetadata

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());
}
Also used : SessionMetadata(org.teiid.adminapi.impl.SessionMetadata) ResultSet(java.sql.ResultSet)

Aggregations

SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)35 Test (org.junit.Test)14 CommandContext (org.teiid.query.util.CommandContext)9 Properties (java.util.Properties)6 InvalidSessionException (org.teiid.client.security.InvalidSessionException)6 DQPWorkContext (org.teiid.dqp.internal.process.DQPWorkContext)5 SessionServiceException (org.teiid.dqp.service.SessionServiceException)5 List (java.util.List)4 LoginException (javax.security.auth.login.LoginException)4 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)4 LogonException (org.teiid.client.security.LogonException)4 SessionToken (org.teiid.client.security.SessionToken)4 Credentials (org.teiid.security.Credentials)4 ArrayList (java.util.ArrayList)3 Subject (javax.security.auth.Subject)3 TeiidComponentException (org.teiid.core.TeiidComponentException)3 SQLException (java.sql.SQLException)2 LogonResult (org.teiid.client.security.LogonResult)2 CompositeVDB (org.teiid.deployers.CompositeVDB)2 VDBLifeCycleListener (org.teiid.deployers.VDBLifeCycleListener)2