Search in sources :

Example 16 with Session

use of org.jivesoftware.openfire.session.Session in project Openfire by igniterealtime.

the class S2STestService method getCertificates.

/**
 * @return A String representation of the certificate chain for the connection to the domain under test.
 */
private String getCertificates() {
    final DomainPair pair = new DomainPair(XMPPServer.getInstance().getServerInfo().getXMPPDomain(), domain);
    Session session = XMPPServer.getInstance().getSessionManager().getOutgoingServerSession(pair);
    StringBuilder certs = new StringBuilder();
    if (session != null) {
        Log.info("Successfully negotiated TLS connection.");
        Certificate[] certificates = session.getPeerCertificates();
        for (Certificate certificate : certificates) {
            X509Certificate x509cert = (X509Certificate) certificate;
            certs.append("--\nSubject: ");
            certs.append(x509cert.getSubjectDN());
            List<String> subjectAltNames = new SANCertificateIdentityMapping().mapIdentity(x509cert);
            if (!subjectAltNames.isEmpty()) {
                certs.append("\nSubject Alternative Names: ");
                for (String subjectAltName : subjectAltNames) {
                    certs.append("\n  ");
                    certs.append(subjectAltName);
                }
            }
            certs.append("\nNot Before: ");
            certs.append(x509cert.getNotBefore());
            certs.append("\nNot After: ");
            certs.append(x509cert.getNotAfter());
            certs.append("\n\n-----BEGIN CERTIFICATE-----\n");
            certs.append(DatatypeConverter.printBase64Binary(certificate.getPublicKey().getEncoded()).replaceAll("(.{64})", "$1\n"));
            certs.append("\n-----END CERTIFICATE-----\n\n");
        }
    }
    return certs.toString();
}
Also used : DomainPair(org.jivesoftware.openfire.session.DomainPair) SANCertificateIdentityMapping(org.jivesoftware.util.cert.SANCertificateIdentityMapping) X509Certificate(java.security.cert.X509Certificate) OutgoingServerSession(org.jivesoftware.openfire.session.OutgoingServerSession) Session(org.jivesoftware.openfire.session.Session) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 17 with Session

use of org.jivesoftware.openfire.session.Session in project Openfire by igniterealtime.

the class ExternalComponentManager method blockAccess.

/**
 * Blocks an external component from connecting to the local server. If the component was
 * connected when the permission was revoked then the connection of the entity will be closed.
 *
 * @param subdomain the subdomain of the external component that is not allowed to connect.
 * @throws ModificationNotAllowedException if the operation was denied.
 */
public static void blockAccess(String subdomain) throws ModificationNotAllowedException {
    // Alert listeners about this event
    for (ExternalComponentManagerListener listener : listeners) {
        try {
            listener.componentBlocked(subdomain);
        } catch (Exception e) {
            Log.warn("An exception occurred while dispatching a 'componentBlocked' event!", e);
        }
    }
    // Remove any previous configuration for this external component
    deleteConfigurationFromDB(getConfiguration(subdomain, false));
    // Update the database with the new revoked permission
    ExternalComponentConfiguration config = new ExternalComponentConfiguration(subdomain, false, Permission.blocked, null);
    addConfiguration(config);
    // Check if the component was connected and proceed to close the connection
    String domain = subdomain + "." + XMPPServer.getInstance().getServerInfo().getXMPPDomain();
    Session session = SessionManager.getInstance().getComponentSession(domain);
    if (session != null) {
        Log.debug("Closing session for external component '{}' as the domain is being blocked. Affected session: {}", domain, session);
        session.close();
    }
}
Also used : SQLException(java.sql.SQLException) ModificationNotAllowedException(org.jivesoftware.util.ModificationNotAllowedException) ComponentSession(org.jivesoftware.openfire.session.ComponentSession) Session(org.jivesoftware.openfire.session.Session)

Example 18 with Session

use of org.jivesoftware.openfire.session.Session in project Openfire by igniterealtime.

the class ConnectionMultiplexerManager method closeClientSession.

/**
 * Closes an existing client session that was established through a connection manager.
 *
 * @param connectionManagerDomain the connection manager that is handling the connection
 *        of the session.
 * @param streamID the stream ID created by the connection manager for the session.
 */
public void closeClientSession(String connectionManagerDomain, StreamID streamID) {
    Map<StreamID, LocalClientSession> sessions = sessionsByManager.get(connectionManagerDomain);
    if (sessions != null) {
        Session session = sessions.remove(streamID);
        if (session != null) {
            Log.debug("Closing session: {}", session);
            session.close();
        }
    }
}
Also used : LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) StreamID(org.jivesoftware.openfire.StreamID) LocalClientSession(org.jivesoftware.openfire.session.LocalClientSession) ConnectionMultiplexerSession(org.jivesoftware.openfire.session.ConnectionMultiplexerSession) Session(org.jivesoftware.openfire.session.Session)

Aggregations

Session (org.jivesoftware.openfire.session.Session)18 Element (org.dom4j.Element)5 DomainPair (org.jivesoftware.openfire.session.DomainPair)5 IQ (org.xmpp.packet.IQ)5 PacketInterceptor (org.jivesoftware.openfire.interceptor.PacketInterceptor)4 ClientSession (org.jivesoftware.openfire.session.ClientSession)4 PacketRejectedException (org.jivesoftware.openfire.interceptor.PacketRejectedException)3 LocalClientSession (org.jivesoftware.openfire.session.LocalClientSession)3 OutgoingServerSession (org.jivesoftware.openfire.session.OutgoingServerSession)3 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)3 Packet (org.xmpp.packet.Packet)3 Iterator (java.util.Iterator)2 Locale (java.util.Locale)2 Lock (java.util.concurrent.locks.Lock)2 DefaultElement (org.dom4j.tree.DefaultElement)2 PacketException (org.jivesoftware.openfire.PacketException)2 SessionManager (org.jivesoftware.openfire.SessionManager)2 MUCRoom (org.jivesoftware.openfire.muc.MUCRoom)2 ComponentSession (org.jivesoftware.openfire.session.ComponentSession)2 ConnectionMultiplexerSession (org.jivesoftware.openfire.session.ConnectionMultiplexerSession)2