我的應用程式同時服務網頁和休息端點(春季啓動+彈簧4)春季安全註銷發出
我想設置一個基本的InMemoryAuth,但/註銷不起作用。
從瀏覽器中,它重定向到/ login?註銷404,對用戶會話沒有影響。
@EnableWebSecurity
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/rest/**").hasRole("USER")
.antMatchers("/ui/**").hasRole("USER")
.and().logout()
.logoutUrl("/logout")
.and().httpBasic()
.and().csrf().disable();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("pass").roles("USER");
}
}
EDIT
與followind鏈
http
.authorizeRequests().anyRequest().authenticated()
.and().logout().logoutUrl("/logout").logoutSuccessUrl("/").permitAll()
.and().httpBasic()
.and().csrf().disable();
和限定的根頁面,沒有404錯誤。
使用調試啓用,我能看到
Logging out user 'org.springframew[email protected]442b5a9f: Principal: [email protected]: Username: user; Password: [PROTECTED]; Enabled: true; AccountNonExpired: true; credentialsNonExpired: true; AccountNonLocked: true; Granted Authorities: ROLE_USER; Credentials: [PROTECTED]; Authenticated: true; Details: org.sprin[email protected]b364: RemoteIpAddress: 0:0:0:0:0:0:0:1; SessionId: null; Granted Authorities: ROLE_USER' and transferring to logout destination
Invalidating session: B264148444D372CFC899A5B920818B68
但瀏覽器不要求用戶/ passwd文件了,我能夠訪問所有的URL ..
這就是我才發現這裏http://stackoverflow.com/a/5033081/1853780 我猜的解決方案是我的應用程序拆分成2級獨立的應用程序,一個休息與基本身份驗證,其他與經典登錄表單服務網頁。感謝回覆 ! –