i have web-app and i want to secure my rest API i follow some tutorial and i succeeded to implement that the rest API is secure.
but when i added html files in my web-app when i calling those pages for the first time it show me the login area to enter.
i just want to secure the rest API not all the web-app
in my case this is my application.properties
spring.datasource.url=jdbc:mysql://localhost/geekycoders_myteam
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5Dialect
spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true
logging.level.org.springframework.boot.autoconfigure.security=INFO
security.user.name=admin
security.user.password=admin
and this is my SecurityConfig
class
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers(HttpMethod.POST, "/api/**").authenticated()
.antMatchers(HttpMethod.PUT, "/api/**").authenticated()
.antMatchers(HttpMethod.DELETE, "/api/**").authenticated()
.antMatchers(HttpMethod.GET, "/api/**").authenticated()
.anyRequest().permitAll()
.and()
.httpBasic().and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
}
and this is a sample controller
@RestController
@RequestMapping("/api/user")
public class UserController {
@Autowired
UserRepository userRepository;
@RequestMapping("/findall")
@ResponseBody
public List<User> findall(){
return userRepository.findAll();
}
@RequestMapping("/find")
@ResponseBody
public User getUser(@PathParam("id") int id){
return userRepository.findOne(id);
}
}
and i have index.html into directory webapp some help