1

Tomcat バージョン 6.0.37 が組み込まれた Java Web アプリケーションがあり、http と https を使用しています。オプションがある構成ページがあります。

  1. SSL を有効にする
  2. SSL リダイレクト
  3. SSL ポート
  4. HTTP ポート
  5. 再起動

SSL はデフォルトで有効になっています。すべての http リクエストを https にリダイレクトしたい。したがって、構成ページで、SSL リダイレクト オプションをチェックし、再起動オプションをチェックして、フォームを送信します。サーバー側では、次のことを行っています。

if( webServerProperties.getSslRedirect() ) {

            boolean constraintExists = false;

            for( SecurityConstraint constraint : uiContext.findConstraints() ) {
                if( constraint.getDisplayName().equals(SSL_REDIRECT_CONSTRAINT_NAME) ) {
                    constraintExists = true;
                    break;
                }
            }

            if( !constraintExists ) {

                SecurityConstraint constraint = new SecurityConstraint();
                constraint.setDisplayName(SSL_REDIRECT_CONSTRAINT_NAME);
                constraint.setAuthConstraint(false);

                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");

                constraint.setUserConstraint("CONFIDENTIAL");
                constraint.addCollection(collection);

                uiContext.addConstraint(constraint);
            }

        }
        else {

            for( SecurityConstraint constraint : uiContext.findConstraints() ) {
                if( constraint.getDisplayName().equals(SSL_REDIRECT_CONSTRAINT_NAME) ) {
                    uiContext.removeConstraint(constraint);
                }
            }

        }
uiContainer.removeConnector(uiHTTPConnector);
uiHTTPConnector.pause();
uiHTTPConnector.destroy();
uiHTTPConnector = null;

uiHTTPConnector = createHTTPConnector(
    newPort,
    webServerProperties.getSslRedirect() ? webServerProperties.getSslPort() : -1,
    newMaxThreads
    );
uiContainer.addConnector(uiHTTPConnector);
uiHTTPConnector.start();

protected Connector createHTTPConnector(int port, int sslRedirectPort, int maxThreads) throws Exception {

        Connector connector = new LifecycleEventConnector();
        org.apache.tomcat.util.IntrospectionUtils.setProperty(connector, "port", "" + port);

        connector.setAttribute("maxThreads", maxThreads);
        connector.setAttribute("keepAliveTimeout", MAX_IDLE_TIME);
        connector.setAttribute("connectionTimeout", MAX_IDLE_TIME);
        connector.setMaxParameterCount(-1);

        if( sslRedirectPort > 0 ) {
            org.apache.tomcat.util.IntrospectionUtils.setProperty(connector, "redirectPort", "" + sslRedirectPort);
        }

        return connector;
    }

private static final class LifecycleEventConnector extends Connector {

        public LifecycleEventConnector() throws Exception {
            super();
        }

        @Override
        public void initialize() throws LifecycleException {
            lifecycle.fireLifecycleEvent(INIT_EVENT, null);
            super.initialize();
        }

    }

コンテナ全体を再起動してアプリケーション全体を停止させるのではなく、コネクタを再起動したいだけです。他のオプション (HTTP ポート、SSL ポート、SSL 有効化) を変更すると、コネクタが再起動されて正常に動作しますが、SSL リダイレクトを有効にすると機能しません。アプリケーションを再起動すると、SSL リダイレクトが機能します。いろいろ検索しましたが、この問題を解決できません。どんな助けにも感謝します。

4

0 に答える 0