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();
}
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();
}
}
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();
}
}
}
Aggregations