Когда я настраиваю accessDeniedPage () с помощью jsp, куда мне поместить файл jsp? - PullRequest
0 голосов
/ 26 апреля 2019

Я просто хотел предложить пользовательскую "не авторизованную" страницу ответа, когда не авторизованный пользователь пытается получить доступ к ресурсам.

Это приложение RESTful, и поэтому я не использую Thymeleaf, как обычно, на серверестраницы.Где я могу разместить свой jsp файл для этой цели?

package com.potatospy.mobileappws.security;


import com.potatospy.mobileappws.service.UserService;
import org.springframework.http.HttpMethod;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter {

    private final UserService userDetailsService;
    private final BCryptPasswordEncoder bCryptPasswordEncoder;

    public WebSecurity(UserService userDetailsService, BCryptPasswordEncoder bCryptPasswordEncoder) {
        this.userDetailsService = userDetailsService;
        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    }


    // Config some web service entry points as public and some as protected
    @Override
    protected void configure(HttpSecurity http) throws Exception {

        // http Disable Cross-Site Request Forgery,
        // authorize access to /user from anyone,
        // any request from an authenticated user AND
        // Filter for users that authenticationManager says are authenticated via
        // AuthenticationFilter (Sign in process methods)
        // & ExceotionHandling access denied page is /access-denied.jsp

        http.csrf().disable()
                .authorizeRequests().antMatchers(HttpMethod.POST, SecurityConstants.SIGN_UP_URL)
                .permitAll()
                .anyRequest().authenticated().and().addFilter(new AuthenticationFilter(authenticationManager()))
                .exceptionHandling().accessDeniedPage("/access-denied.jsp");
    }

    @Override
    public void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder);
    }


}

Структура каталогов:

src - java - main -> (java-> com.blabla.project.ui.controller.WebSecurity, ресурсы-> статические, шаблоны)

...