我有一段代码用于显示登录页面,具体取决于用户是否登录
@PropertySource(value = "classpath:securityConfig.properties", ignoreResourceNotFound = true)
@Controller
public class IndexController {
private static final String LOGIN_PAGE = "login";
private static final String HOME_PAGE = "home";
private static final String LOBBY_PAGE = "lobby";
private static final String FORGOT_USER_PAGE = "forgotUserName";
private static final String FORGOT_PASSWORD_PAGE = "forgotPassWord";
@Value("${auth.mode:fixed}")
private String authenticationMode;
public String getAuthenticationMode(){
return this.authenticationMode;
}
@PreAuthorize("isAnonymous() AND this.getAuthenticationMode().equals(\"fixed\")")
@RequestMapping(method = RequestMethod.GET, value = { "/login" })
public String getIndexPage() {
return LOGIN_PAGE;
}
}
如果条件不满足,则@PreAuthorize
注释会抛出HTTP 401。我该如何抛出HTTP 404?我只想为这个特殊的方法抛出404.
答案 0 :(得分:0)
如果您只是不定义控制器,那么您将收到404 Not Found
。这可以通过在控制器上使用@ConditionalOnProperty
注释来实现。