我正在使用java配置來應用spring安全性,並且我能夠在特定的url上應用安全性,但是我希望彈出安全性的默認登錄頁面,只要有人點擊除未受保護的url之外的其他URL。 這裏是我的SecurityConfig代碼:如何在特定的url上應用spring安全並使用java配置保留其他人?
import javax.sql.DataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
//import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.web.bind.annotation.RequestMethod;
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/myproject/userCont/user").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/myproject/login/form")
.loginProcessingUrl("/login")
.failureUrl("/login/form?error")
.permitAll();
}
所以,當我打/ myproject的/ userCont /用戶用GET方法是否能夠正常工作,但是當我打相同的URL與POST方法或其他網址春季安全不顯示默認登錄頁面。
任何人都可以幫助我嗎?
@Qasim做ü認爲這個答案是適合你的問題 –
感謝回答@MS易卜拉欣但是這不是我的問題,我想允許或禁止僅作爲我使用的彈簧引導通過Java配置URL和不想使用security.xml文件 – Qasim