Не удается перейти на пользовательскую страницу входа в систему с помощью Spring Security. Ошибка 404 - PullRequest
0 голосов
/ 06 ноября 2019

Я настраиваю Spring Security в своем приложении, чтобы использовать собственный login.jsp в качестве формы входа. Я не могу получить пользовательскую страницу входа со следующей конфигурацией:

    @Configuration
    @EnableWebSecurity
    public class SecSpringSecurityConfig extends WebSecurityConfigurerAdapter {

    @Autowired
    private UserDetailsService userDetailsService;

    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception {
     return super.authenticationManagerBean();
    }

    @Override
    protected void configure(final AuthenticationManagerBuilder auth) throws Exception {
     auth.authenticationProvider(authProvider());
    }

    @Override
    public void configure(final WebSecurity web) throws Exception {
     web.ignoring().antMatchers("/javascript/**");
    }

    @Bean
    public DaoAuthenticationProvider authProvider() {
     final IDMSAuthenticationProvider authProvider = new IDMSAuthenticationProvider();
     authProvider.setUserDetailsService(userDetailsService);
     return authProvider;
    }

    public SecSpringSecurityConfig() {
     super();
    }

    @Override
    protected void configure(final HttpSecurity http) throws Exception {

    http
        .csrf().disable()
            .authorizeRequests()
            .antMatchers("/login*").permitAll()
            .and()
        .formLogin()
            .loginPage("/login1")
            .defaultSuccessUrl("/homepage.html")
            .failureUrl("/login?error=true")
            .loginProcessingUrl("/login");

     }
    }

В реализации DaoAuthenticatorProvider пока ничего нет:

    public class IDMSAuthenticationProvider extends DaoAuthenticationProvider{

    }

В реализации UserDetailsService ничего нетпока:

    @Service("userDetailsService")
    @Transactional
    public class MyUserDetailsService implements UserDetailsService{

      @Override
      public UserDetails loadUserByUsername(final String email) throws UsernameNotFoundException {

        return new org.springframework.security.core.userdetails.User(email, "n/a", true, true, true, true, null);
      }
    }

Моя структура папок выглядит следующим образом:

    -myApp
      -WebPages
        -WEB-INF
          -jsp
            -login1.jsp

У меня есть следующая настройка распознавателя вида в другой части приложения:

  <bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
    <property name="order" value="1" />
    <property name="contentNegotiationManager">
        <bean class="org.springframework.web.accept.ContentNegotiationManager">
            <constructor-arg>
                <bean class="org.springframework.web.accept.PathExtensionContentNegotiationStrategy">
                    <constructor-arg>
                        <map>
                            <entry key="json" value="application/json" />
                            <entry key="xml" value="application/xml" />
                        </map>
                    </constructor-arg>
                </bean>
            </constructor-arg>
        </bean>
    </property>
    <property name="defaultViews">
        <list>
            <bean class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />
            <bean class="org.springframework.web.servlet.view.xml.MarshallingView">
                <constructor-arg>
                    <bean class="org.springframework.oxm.xstream.XStreamMarshaller">
                        <property name="autodetectAnnotations" value="true" />
                    </bean>
                </constructor-arg>
            </bean> 

        </list>
    </property>
</bean>

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/jsp/" />
    <property name="suffix" value=".jsp" />
    <property name="order" value="2" />
</bean>

Iпопробуйте получить доступ к странице входа, используя

http://localhost:8080/myApp/login

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

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...