C
C
Charik6352021-09-03 18:33:37
Java
Charik635, 2021-09-03 18:33:37

How to give access to all front pages except one?

I need to give access to all pages of the front, but by url api/user/** access should be only for those who have the USER role

@Override
    public void configure(HttpSecurity http) throws Exception {
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");
        filter.setForceEncoding(true);

        http
                .cors()
                .disable()
                .csrf()
                .disable()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                .antMatchers(LOGIN_URL).permitAll()
                .antMatchers(REGISTRATION_URL).permitAll()
                .antMatchers(GET_JWT_URL).permitAll()
                .antMatchers(SWAGGER_URL).permitAll()
                .antMatchers("api/user/**")
                .hasRole("USER")
                .anyRequest()
                .permitAll();



        http.addFilterBefore(JwtAuthFilter(), UsernamePasswordAuthenticationFilter.class);
    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question