Domanda

Mi chiedevo come posso forzare un utente che ha richiesto una pagina utilizzando Http per utilizzare la versione https sicura?

Uso Websphere 6.1 come server applicazioni e Rad 7 come ambiente di sviluppo

Grazie Damien

È stato utile?

Soluzione

Un modo per farlo all'interno dell'applicazione piuttosto che nella configurazione del server sarebbe usare un Filtro (specificato nel tuo web.xml) per verificare se ServletRequest.getScheme () è " http " o " https " ;, e reindirizzare l'utente all'URL appropriato (usando HttpServletResponse.sendRedirect (String url) ).

Altri suggerimenti

Puoi aggiungere la seguente voce nel tuo web.xml e assicurerà che tutte le richieste siano convertite in https

<!--********************************
   *** SSL Security Constraint  ***
   *****************************-->
   <security-constraint>
       <web-resource-collection>
           <web-resource-name>SSL</web-resource-name>
           <url-pattern>/*</url-pattern>
       </web-resource-collection>
       <user-data-constraint>
           <transport-guarantee>CONFIDENTIAL</transport-guarantee>
       </user-data-constraint>
   </security-constraint>

<!--********************************* -->

Websphere non è un server http completo. Ha "catene di trasporto", che agiscono come un server HTTP.

Normalmente metterai in primo piano un server HTTP. IBM fornisce IHS (IBM HTTP Server) che è un server HTTP Apache leggermente modificato. Il server HTTP è configurato con il file httpd.conf. Lì si aggiungono reindirizzamenti in modo tale che le richieste di http vengano reindirizzate a https.

Forse puoi fornire alcune informazioni dettagliate sulla tua infrastruttura.

Sono d'accordo. Penso che usando un filtro raggiungerai questo obiettivo. Ecco un filtro che ho scritto per il bilanciamento del carico e il reindirizzamento delle porte, ma dovrebbe essere facile capire come modificarlo in base alle proprie esigenze.

RequestWrapperFilter di classe pubblica implementa Filter {

public void doFilter(ServletRequest servletRequest,
        ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {

    HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
    HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;

    String requestWrapperClassName = (String) (httpRequest
            .getAttribute(LoadBalancerRequestWrapper.class.getName()));

    String initiatingServerName = httpRequest.getServerName();

    if (requestWrapperClassName == null
            && initiatingServerName.equals(loadBalancerHostName)) {

        httpRequest = new LoadBalancerRequestWrapper(AuthenticationUtil
                .getHttpServletRequest(httpRequest));
    }

    filterChain.doFilter(httpRequest, httpResponse);
}

}

/**
 * The custom implementation of the request wrapper. It simply overrides the
 * getScheme() and getServerPort() methods to perform the redirect
 * filtering.
 * 
 * 
 */
private static class LoadBalancerRequestWrapper extends
        HttpServletRequestWrapper {

    /**
     * Default Constructor. Simply declares the Wrapper as injected.
     * 
     * @param httpServletRequest
     *            the app-server HttpServletRequest.
     * 
     */
    public LoadBalancerRequestWrapper(HttpServletRequest httpServletRequest) {
        super(httpServletRequest);
    }

    /**
     * The overridden scheme.
     * 
     */
    public final String getScheme() {
        if (loadBalancerHttpScheme.equals(EMPTY_STRING)) {
            return super.getScheme();
        }

        return loadBalancerHttpScheme;
    }
}

}

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top