package by.triumgroup.recourse.configuration.security;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
import org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfigurerAdapter;
import org.springframework.security.oauth2.config.annotation.web.configurers.ResourceServerSecurityConfigurer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JdbcTokenStore;

import javax.sql.DataSource;

@Configuration
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {

    private final DataSource dataSource;

    @Autowired
    public ResourceServerConfiguration(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    @Bean
    public TokenStore tokenStore() {
        return new JdbcTokenStore(dataSource);
    }

    @Override
    public void configure(ResourceServerSecurityConfigurer resources) {
        resources
                .tokenStore(tokenStore());
        resources.stateless(false);
    }

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
                .authorizeRequests()
                .antMatchers("/api/users/register").permitAll()
                .antMatchers("/api/**").authenticated()
                .anyRequest().permitAll();
    }
}

@@ -49,16 +49,65 @@
 urity;%0A%0A
+import by.triumgroup.recourse.entity.model.User;%0A
 import o
@@ -161,16 +161,16 @@
 owired;%0A
-
 import o
@@ -274,16 +274,60 @@
 ration;%0A
+import org.springframework.http.HttpMethod;%0A
 import o
@@ -1610,16 +1610,16 @@
 uests()%0A
-
         
@@ -1674,16 +1674,1997 @@
 itAll()%0A
+%0A                .antMatchers(HttpMethod.GET, %22/api/courses/**%22).authenticated()%0A                .antMatchers( %22/api/courses/**%22).hasAuthority(User.Role.ADMIN.name())%0A%0A                .antMatchers(HttpMethod.GET, %22/api/lessons/**%22).authenticated()%0A                .antMatchers(HttpMethod.PUT, %22/api/lessons/**%22).hasAuthority(User.Role.TEACHER.name())%0A                .antMatchers(%22/api/lessons/**%22).hasAuthority(User.Role.ADMIN.name())%0A%0A                .antMatchers(HttpMethod.GET,%22/api/hometasks/solutions/marks/**%22).authenticated()%0A                .antMatchers(%22/api/hometasks/solutions/marks/**%22).hasAnyAuthority(User.Role.ADMIN.name(), User.Role.TEACHER.name())%0A%0A                .antMatchers(HttpMethod.GET, %22/api/users/**%22).authenticated()%0A                .antMatchers(HttpMethod.PUT, %22/api/users/**%22).authenticated()%0A                .antMatchers(%22/api/users/logout%22, %22/api/users/password/change%22).authenticated()%0A                .antMatchers( %22/api/users/**%22).hasAuthority(User.Role.ADMIN.name())%0A%0A                .antMatchers(HttpMethod.GET, %22/api/hometasks/solutions/**%22).authenticated()%0A                .antMatchers(HttpMethod.POST, %22/api/hometasks/solutions/**%22).hasAnyAuthority(User.Role.STUDENT.name(), User.Role.ADMIN.name())%0A                .antMatchers(%22/api/hometasks/solutions%22).hasAuthority(User.Role.ADMIN.name())%0A%0A                .antMatchers(HttpMethod.GET, %22/api/courses/feedbacks/**%22).authenticated()%0A                .antMatchers(HttpMethod.PUT, %22/api/courses/feedbacks/**%22).hasAnyAuthority(User.Role.STUDENT.name(), User.Role.ADMIN.name())%0A                .antMatchers(HttpMethod.POST, %22/api/courses/feedbacks/**%22).hasAnyAuthority(User.Role.STUDENT.name(), User.Role.ADMIN.name())%0A                .antMatchers(HttpMethod.DELETE, %22/api/courses/feedbacks/**%22).hasAnyAuthority(User.Role.STUDENT.name(), User.Role.ADMIN.name())%0A%0A                .antMatchers(HttpMethod.GET, %22/api/teachers/**%22).hasAnyAuthority(User.Role.TEACHER.name(), User.Role.ADMIN.name())%0A%0A
         

Add security config