Spring – Backend
Security
src/main/java/com/tutofox/company/SecurityConfig.java
package com.tutofox.tutospring; 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; @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/public").permitAll() .antMatchers("/home").hasRole("ADMIN") .antMatchers("/employee").hasRole("USER") .antMatchers("/api/**").hasRole("USER") .and().csrf().disable() .logout() .and() .formLogin(); } }
src/main/resources/application.properties
# Your desired user name
spring.security.user.name=artyom
# password
spring.security.user.password=password
# Role
spring.security.user.roles = USER
security.enable-csrf=false