You are on page 1of 1

Configure Spring Security in your SecurityConfig.

java:

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/login").permitAll() // Allow access to welcome and
login pages
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/admin/welcome", true) // Redirect to admin welcome
page
.permitAll()
.and()
.logout()
.permitAll();
}

// Define authentication details (e.g., in-memory authentication)


@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("admin").password("{noop}admin").roles("ADMIN");
}
}

You might also like