2015-02-06 31 views
0

我有一個JSF 2.2 webapp,帶有一個合同和幾個頁面,直接位於WebContent文件夾中。合同由圖片,模板文件template.xhtml和css文件global.css組成。到目前爲止,一切都按預期工作。PicketLink保護停止加載JSF 2.2資源合同

現在我想使用PicketLink進行用戶認證和授權,並遵循教程(http://www.ocpsoft.org/security/simple-java-ee-jsf-login-page-with-jboss-picketlink-security/),但是當訪問我的頁面時,圖像和css文件無法加載,只有模板適用,所以我的頁面沒有所有應用的CSS樣式和Firefox Inspector中都有一行讀取(從德語翻譯):「樣式表http://localhost:8080/MyTestProject/login.xhtml未加載,因爲它的MIME類型是」text/html「而不是」text/css「」。

HttpSecurityConfiguration

builder.http().allPaths().unprotected() 

圖像和css更換

builder.http().allPaths().authenticateWith().form()... and so on 

後可以再次加載。

我曾嘗試以下(和一些其他路徑),但它並沒有解決這個問題:

.forPath("/contracts/*").unprotected(); 

,如何排除合同文件夾從PicketLink保護?


這裏是我的完整HttpSecurityConfiguration類:

@ApplicationScoped 
public class HttpSecurityConfiguration { 

    public void onInit(@Observes SecurityConfigurationEvent event) { 

    SecurityConfigurationBuilder builder = event.getBuilder(); 

    builder 
    .http() 
    .allPaths() 
    .authenticateWith() 
    .form() 
    .loginPage("/login.xhtml") 
    .errorPage("/loginError.xhtml") 
    .restoreOriginalRequest() 
    .forPath("/logout") 
    .logout() 
    .redirectTo("/index.xhtml") 
    .forPath("/index.xhtml") 
    .unprotected() 
    //  .forPath("/contracts/*") 
    //  .unprotected() 
    ; 
    } 
} 

編輯 在答覆Kukeltje的評論,我包括與

<h:head> 
    <title><ui:insert name="title">MyTestProject</ui:insert></title> 
    <h:outputStylesheet name="global.css" /> 
</h:head> 

,並在模板中的CSS與

<h:graphicImage class="feature" name="logo-main.png" width="900" height="270" /> 

我也嘗試將javax.faces.resource視爲未受保護,但仍然無法正常工作。

編輯#2 下面也沒有工作,我從文檔的想法(PicketLink Reference Chapter 12.2):

.forPath("/*.png").unprotected() 
.forPath("/*.css").unprotected() 
+1

當我需要基於PrimeFaces的登錄頁面時,資源不得不被保護的情況下,排除具有資源的子文件夾適用於我。該文件夾是javax.faces.resource而不是你的'合同'(假設你的css在那裏)。也許你的xhtml或模板有問題。請張貼那些 – Kukeltje 2015-02-06 18:54:22

回答

0

我能解決我的問題有以下安全配置:

.forPath("/javax.faces.resource/*.png.xhtml").unprotected() 

我在我的Firefox Inspector中看到瀏覽器試圖從/MyTestProject/javax.faces.resource/logo-main.png.xhtml?con=TemplateBlue加載圖像,所以嘗試上述看起來很合理,它的工作原理!