2017-12-15 2 views
-1

Ich habe eine Spring-Boot (1.5.1.RELEASE) -Anwendung mit Java 1.8 entwickelt. Ich benutze Frühling Sicherheit mit einem benutzerdefinierten Benutzerdetails Dienstleistungen.Spring Boot-Anwendung Null ModelAndView zurückgegeben

Bei erfolgreicher Authentifizierung meine Anwendung die richtige HTML-Seite/Ansicht nicht angezeigt wird, ist es auf der Login-Seite bleibt - das ist, was ich in den Protokollen finden Sie unter:

2017-12-15 23:19:43.998 DEBUG 10340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet  : Null ModelAndView returned to DispatcherServlet with name 'dispatcherServlet': assuming HandlerAdapter completed request handling 
2017-12-15 23:19:43.998 DEBUG 10340 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet  : Successfully completed request 

Dies ist etwas, das ich viele getan haben, mal davor aber aus irgendeinem Grund funktioniert es diesmal nicht und ich kann nicht herausfinden warum, also suche ich Hilfe.

Dies ist meine Sicherheitskonfigurationsklasse:

@Configuration 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

/** The Constant LOGIN_PAGE. */ 
private static final String LOGIN_PAGE = "/login"; 

/** The Constant AUTHORISED_REQUESTS_ANT_MATCHER. */ 
private static final String AUTHORISED_REQUESTS_ANT_MATCHER = "/**"; 

/** The Constant BAD_CREDENTIALS_EXCEPTION_URL. */ 
private static final String BAD_CREDENTIALS_EXCEPTION_URL = "/login?error"; 

/** The Constant ACCOUNT_EXPIRED_EXCEPTION_URL. */ 
private static final String ACCOUNT_EXPIRED_EXCEPTION_URL = "/login?accountexpired"; 

/** The Constant CREDENTIALS_EXPIRED_EXCEPTION_URL. */ 
private static final String CREDENTIALS_EXPIRED_EXCEPTION_URL = "/login?credentialsexpired"; 

/** The Constant ACCOUNT_DISABLED_EXCEPTION_URL. */ 
private static final String ACCOUNT_DISABLED_EXCEPTION_URL = "/login?accountdisabled"; 

/** The Constant ACCOUNT_LOCKED_EXCEPTION_URL. */ 
private static final String ACCOUNT_LOCKED_EXCEPTION_URL = "/login?accountlocked"; 

/** The find user by username command. */ 
@Autowired 
private Command<FindUserByUsernameResp, FindUserByUsernameParam> findUserByUsernameCommand; 

public SecurityConfig() { 
    super(); 
} 

// =========================================== 
// Public Methods 
// =========================================== 

public Command<FindUserByUsernameResp, FindUserByUsernameParam> getFindUserByUsernameCommand() { 
    return findUserByUsernameCommand; 
} 

public void setFindUserByUsernameCommand(Command<FindUserByUsernameResp, FindUserByUsernameParam> findUserByUsernameCommand) { 
    this.findUserByUsernameCommand = findUserByUsernameCommand; 
} 

@Bean 
public ExceptionMappingAuthenticationFailureHandler exceptionMappingAuthenticationFailureHandler() { 
    Map<String, String> mappings = new HashMap<String, String>(); 
    mappings.put(BadCredentialsException.class.getCanonicalName(), BAD_CREDENTIALS_EXCEPTION_URL); 
    mappings.put(AccountExpiredException.class.getCanonicalName(), ACCOUNT_EXPIRED_EXCEPTION_URL); 
    mappings.put(CredentialsExpiredException.class.getCanonicalName(), CREDENTIALS_EXPIRED_EXCEPTION_URL); 
    mappings.put(DisabledException.class.getCanonicalName(), ACCOUNT_DISABLED_EXCEPTION_URL); 
    mappings.put(LockedException.class.getCanonicalName(), ACCOUNT_LOCKED_EXCEPTION_URL); 

    ExceptionMappingAuthenticationFailureHandler exceptionMappingAuthenticationFailureHandler = new ExceptionMappingAuthenticationFailureHandler(); 
    exceptionMappingAuthenticationFailureHandler.setExceptionMappings(mappings); 
    return exceptionMappingAuthenticationFailureHandler; 
} 

@Override 
protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
    auth.userDetailsService(new UserDetailsServiceImpl(getFindUserByUsernameCommand()));//.passwordEncoder(new BCryptPasswordEncoder()); 
} 

protected void configure(HttpSecurity http) throws Exception { 
    http.formLogin().loginPage(LOGIN_PAGE).successForwardUrl("/") 
     .and() 
     .authorizeRequests() 
     .antMatchers(LOGIN_PAGE).permitAll() 
     .antMatchers(AUTHORISED_REQUESTS_ANT_MATCHER).authenticated(); 
} 


} 

Und das ist meine Web-Konfiguration:

@Configuration 
public class WebConfig extends WebMvcConfigurerAdapter { 

// =========================================== 
// Public Members 
// =========================================== 

// =========================================== 
// Private Members 
// =========================================== 

/** The Constant ROOT_URL. */ 
private static final String ROOT_URL = "/"; 

/** The Constant ROOT_VIEW. */ 
private static final String ROOT_VIEW = "app/views/index"; 

/** The Constant LOGIN_URL. */ 
private static final String LOGIN_URL = "/login"; 

/** The Constant LOGIN_VIEW. */ 
private static final String LOGIN_VIEW = "login"; 

/* 
* (non-Javadoc) 
* 
* @see 
* org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter 
* #addViewControllers(org.springframework.web.servlet.config.annotation. 
* ViewControllerRegistry) 
*/ 
@Override 
public void addViewControllers(ViewControllerRegistry registry) { 
    registry.addViewController(ROOT_URL).setViewName(ROOT_VIEW); 
    registry.addViewController(LOGIN_URL).setViewName(LOGIN_VIEW); 
} 

} 

ich in meiner Anwendung zwei HTML-Seiten haben, unter dem Vorlagenordner, und sie sind:

login.html (was in Ordnung anzeigt) app/views/index.html

Meine index.html Datei wird nie angezeigt.

Irgendwelche Ideen?

Antwort

0

Können Sie versuchen, Ihre ROOT_VIEW zu /app/views/index zu ersetzen? Füge einfach einen Schrägstrich hinzu.

0

Ich entdeckte, dass das Problem ein Fehler in meinem Thymeleleaf-Markup war. Es dauerte eine Weile, bis ich das entdeckte, da es keinen Hinweis auf einen Fehler in meinen Logs gab.

Verwandte Themen