public void setTLSPolicy( SocketConnection.TLSPolicy policy )
    {
        final Connection.TLSPolicy oldPolicy = getTLSPolicy();
        if ( oldPolicy.equals( policy ) )
        {
            Log.debug( "Ignoring TLS Policy change request (to '{}'): listener already in this state.", policy );
            return;
        }

        final Connection.TLSPolicy hardcoded = getHardcodedTLSPolicy();
        if ( hardcoded != null )
        {
            throw new IllegalArgumentException( "The TLS Policy for this listener is hardcoded (to '"+hardcoded+"'). It cannot be changed." );
        }

        if ( Connection.TLSPolicy.directTLS.equals( policy ) )
        {
            Log.warn( "Ignoring TLS Policy change request (to '{}'): You cannot reconfigure an existing connection (from '{}') into DirectTLS mode!", policy, oldPolicy );
            return;
        }

        if ( Connection.TLSPolicy.directTLS.equals( oldPolicy ) )
        {
            Log.warn( "Ignoring TLS Policy change request (to '{}'): You cannot reconfigure an existing connection that is in DirectTLS mode!", policy );
            return;
        }

        Log.debug( "Changing TLS Policy from '{}' to '{}'.", oldPolicy, policy );
        JiveGlobals.setProperty( tlsPolicyPropertyName, policy.toString() );
        restart();
    }
Sets whether TLS is mandatory, optional, disabled or mandatory immediately for new connections. When TLS is
mandatory connections are required to be encrypted or otherwise will be closed. This configuration change is
persisted.

If the listener is currently enabled, this configuration change will be applied immediately (which will cause a
restart of the underlying connection acceptor).

When TLS is disabled connections are not allowed to be (or become) encrypted. In this case, connections will be
closed when encryption is attempted.

This method disallows changing the policy from or into Direct TLS mode. Such a change is logged but otherwise
ignored.

An invocation of this method has no effect if the new policy value is equal to the existing value.

@param policy an encryption policy (not null).
xmppserver/src/main/java/org/jivesoftware/openfire/spi/ConnectionListener.java