簡體   English   中英

Spring Boot + Angular JS JBoss 部署

[英]Spring Boot + Angular JS JBoss deployment

我創建了 Angular JS 項目,它在端口 4200 下的節點服務器和基於 Spring Boot 的 REST 數據服務中運行作為單獨的項目,它在 8080 端口下的 eclipse 中運行。 REST 服務 (RS) 部分使用基於 OAuth 的安全性並驗證對 access_token 的每個請求。 這作為單獨的實體工作得非常好。

現在,我嘗試在 WAR 的根文件夾中使用 angular 編譯輸出構建單個 WAR,如果我訪問應用程序(通過訪問任何 URL) - 在 Angular NG-router Spring 啟動安全性出現之前並拒絕無 OAuth 驗證的請求。

@Override
public void configure(HttpSecurity http) throws Exception {
    http.antMatcher("/**").authorizeRequests().antMatchers("/error").permitAll().anyRequest().authenticated();
    http.csrf().disable();
    http.headers().frameOptions().disable();
    http.cors().configurationSource(new CorsConfigurationSource() {

        @Override
        public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
            CorsConfiguration config = new CorsConfiguration();
            config.setAllowedHeaders(Collections.singletonList("*"));
            config.setAllowedMethods(Collections.singletonList("*"));
            config.addAllowedOrigin("*");
            config.setAllowCredentials(true);
            return config;
        }
    });
}

這是我的安全配置文件。 請告知將兩個單獨的 WAR 合並到單個模塊 EAR 中是否可以解決此問題。

查看我的存儲庫

有一個項目結構可以生成單一戰爭。

編輯:也許你需要創建一個 proxy.conf.json 文件

{
     "/api/*": {
       "target": "http://localhost:8080",
       "secure": false
     }
}

並將它添加到您的 angular.json 文件中的 architect-serve-options-proxyConfig

您的安全配置正在授權每個 url 模式。 如果您希望在調用 API 進行身份驗證/授權之前加載靜態內容,請從安全配置中排除 .js、.css、.html 文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM