2016-12-03 25 views
1

我有一個正在運行的springmvc,在IBM Liberty配置文件上運行彈簧安全Web應用程序。我使用java配置來設置所有(並沒有web.xml)。如何將彈簧安全配置與IBM Liberty配置文件basicRegistry聯繫起來

擴展類WebSecurityConfigurerAdapter,我設置了用戶的簡單列表如下:

@Autowired 
public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception { 
auth.inMemoryAuthentication().withUser("bill").password("123456").roles("USER"); 
} 

我不希望在我的代碼的用戶信息,所以我想給用戶註冊表移動到server.xml的IBM Liberty概要文件服務器。

<basicRegistry> 
    <user name="bill" password="123456"/> 
</basicRegistry> 

我該如何配置?

額外的信息我使用一個多模塊maven項目,耳朵和戰爭模塊。所以在server.xml中最後一行是

<enterpriseApplication id="hellospringEAR" location="hellospringEAR-00.00.0001-SNAPSHOT.ear" name="hellospringEAR"/> 

任何提示或建議,非常感謝。

+0

選中此[文章](HTTP://計算器.com/a/9847324/3701228),它描述瞭如何配置Java EE與Spring安全的集成(談論站點管理員,但是主體是相同的,你希望服務器的用戶)。 – Gas

回答

0

你需要使用Spring Security的支持容器管理的安全性(這是JEE()方法)

@Configuration 
@EnableWebSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 
private static final Logger LOGGER = LoggerFactory.getLogger(SecurityConfig.class); 

@Autowired 
private ApplicationProperties appProperties; 

@Override 
protected void configure(final HttpSecurity http) throws Exception { 
    http.authorizeRequests() 
      .anyRequest().authenticated() 
      .and().httpBasic(); 

    if (appProperties.isContainerManaged()) { 
     LOGGER.info("using container managed"); 
     http.jee(); 
    } 
    http.csrf().disable() 
      .logout() 
      .permitAll(); 
} 
} 

更多細節在這裏: Roles/Authorities not working in Websphere Liberty

+0

謝謝大衛......但我得到了委託人的空缺。而且我仍然試圖在春季抓住整個過濾器鏈條。 – Maarten

+0

你能否向我提供你的代碼LibertyPreAuthenticatedWebAuthenticatedDetailsS​​ource?我如何將它掛在securityConfig類中,我很努力地爲com.ibm.websphere.security庫找到正確的maven倉庫/依賴項。 – Maarten