構成されたhttps制約がweb.xmlで機密に設定されている単純なjsfセキュアトランスポートメカニズムに取り組んでいます。今、私がやりたかったのは、セキュアトランスポート用の特定のページを選択することでした。別のページに移動するログインページがあります。ログインページはユーザー名とパスワードを取得し、要求されたページを表示する前にその信頼性を検証するejbにセキュアレイヤーを介して転送する必要があります。 web.xmlの要求されたページのfaces/pageToView.xhtmlで、私は本当に理解できない面白い動作をします。最初に、ログインすると、httpsなしでpageToView.xhtmlが表示され、クリックして別のpageToView2.xhtmlに移動します。最初のpageToView.xhtmlはhttpsで再表示されます。安全なトランスポート用に構成していなくても、ナビゲートする他のすべてのページにhttpsが表示されるだけではありません。特定のページの安全なトランスポート動作を構成する正しい方法を知る必要があります。前もって感謝します。
1 に答える
どうやら、https にアクセスすると、通常はログイン ページでこれを行う場合、https にとどまるようです。セキュリティ要件が限られているアプリケーションでは大きなオーバーヘッドになるように思われましたが、調べてみると、大きなリスクはセッション ハイジャックであるというコンセンサスが得られました。したがって、ログインとショッピングの 2 つの安全なページがあり、他のすべてのページが ssl を使用していない場合、これらのページはセッション Cookie を無線/有線で平文で送信し、Cookie を盗聴される可能性があります。
アプリケーションサーバーの前にApache Webサーバーがある場合、特定のページのクライアントブラウザーとApacheの間でhttpsを使用するが、Apacheとアプリサーバーの間でhttpを使用するなど、より多くのオプションがあると思います. 私はあなたがこれを行うことができると確信していますが、私は専門家ではなく、試したことはありません.
しばらく前にこれを調べていたときに、Glassfish チームの 1 人によって書かれた、https - http からダウンシフトするはずのこのフィルターに出くわしました。私の記憶では、コンテナー セキュリティと組み合わせて使用すると、すべてをダウンシフトすると機能しなくなりました。
この例では、main.xhtml ファイルは web.xml のウェルカム ファイルです。これは、ログインが成功したときに読み込まれるページになるという考えです。 https - http からダウンシフトします。@WebServlet のコメントを外し、Log.log() の代わりに独自のログを使用し、URL/パス名を確認する必要があります。
これに時間を費やす前に、これを機能させることができなかったことを覚えておいてください。推奨されるのは、ヒットを取り、常に https を使用することです。
package uk.co.sportquest.jsfbeans.helper;
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 1997-2008 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU General
* Public License Version 2 only ("GPL") or the Common Development and
* Distribution License("CDDL") (collectively, the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy of the
* License at https://glassfish.dev.java.net/public/CDDL+GPL.html or
* glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
* Sun designates this particular file as subject to the "Classpath" exception
* as provided by Sun in the GPL Version 2 section of the License file that
* accompanied this code. If applicable, add the following below the License
* Header, with the fields enclosed by brackets [] replaced by your own
* identifying information: "Portions Copyrighted [year] [name of copyright
* owner]"
*
* Contributor(s):
*
* If you wish your version of this file to be governed by only the CDDL or only
* the GPL Version 2, indicate your decision by adding "[Contributor] elects to
* include this software in this distribution under the [CDDL or GPL Version 2]
* license." If you don't indicate a single choice of license, a recipient has
* the option to distribute your version of this file under either the CDDL, the
* GPL Version 2 or to extend the choice of license to its licensees as provided
* above. However, if you add GPL Version 2 code and therefore, elected the GPL
* Version 2 license, then the option applies only if the new code is made
* subject to such option by the copyright holder.
*/
import java.io.*;
import java.util.*;
import java.security.*;
import java.util.logging.Logger;
import javax.faces.context.FacesContext;
import javax.security.jacc.*;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.*;
import uk.co.sportquest.general.Log;
/**
* Filter that downshifts from https to http if the given request came in over
* https, but the target resource does not require any confidentiality
* protection.
*
* @author jluehe
* @author monzillo
*/
//@WebFilter(filterName = "CacheFilterStatic", urlPatterns = {"/faces/secure/main.xhtml"},
// dispatcherTypes = {DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.REQUEST, DispatcherType.INCLUDE})
public class MyFilter implements Filter {
private static final CodeSource cs =
new CodeSource(null, (java.security.cert.Certificate[]) null);
private static final ProtectionDomain pd =
new ProtectionDomain(cs, null, null, null);
// private static final Policy policy = Policy.getPolicy();
private static final Policy policy = Policy.getPolicy();
private static final String httpPort = "8080";
@Override
public void init(javax.servlet.FilterConfig filterConfig)
throws ServletException {
//httpPort = filterConfig.getInitParameter("httpPort");
}
@Override
@SuppressWarnings("static-access")
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain filterChain)
throws IOException, ServletException {
if (req.isSecure()) {
HttpServletRequest httpReq = (HttpServletRequest) req;
Permission p = new WebUserDataPermission(httpReq);
p = new WebUserDataPermission(p.getName(), httpReq.getMethod());
//SQLog.log("Filter: " + httpReq.getRequestURI());
boolean isTransportProtected = policy.implies(pd, p) ? false : true;
Log.log();
if (!isTransportProtected) {
// Downshift from https to http, by redirecting to the
// target resource using http
String redirectUrl = "http://" + req.getServerName() + ":"
+ httpPort + httpReq.getRequestURI();
String queryString = httpReq.getQueryString();
if (queryString != null) {
redirectUrl += "?" + queryString;
}
//redirectUrl = "http://localhost:8080/SportQuest/faces/secure/main.xhtml";
Log.log("url: " + redirectUrl);
((HttpServletResponse) res).sendRedirect(redirectUrl);
} else {
// Perform normal request processing
Log.log("normal");
filterChain.doFilter(req, res);
}
} else {
// Perform normal request processing
Log.log("even more normal");
filterChain.doFilter(req, res);
}
}
@Override
public void destroy() {
// Do nothing
}
}