Skip to main content
added 58 characters in body
Source Link

I have a piece of code for showing login page depending on whether user is logged in or not

@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; } 

}

The @PreAuthorize annotation throws HTTP 401 if the condition isn't satisfied. How do I throw HTTP 404 instead? I just want to throw 404 for this particular method ONLY.

I have a piece of code for showing login page depending on whether user is logged in or not

@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; } 

}

The @PreAuthorize annotation throws HTTP 401 if the condition isn't satisfied. How do I throw HTTP 404 instead?

I have a piece of code for showing login page depending on whether user is logged in or not

@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; } 

}

The @PreAuthorize annotation throws HTTP 401 if the condition isn't satisfied. How do I throw HTTP 404 instead? I just want to throw 404 for this particular method ONLY.

Source Link

PreAuthorize annotation send HTTP 404 instead of HTTP 401 in case of validation faliure

I have a piece of code for showing login page depending on whether user is logged in or not

@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; } 

}

The @PreAuthorize annotation throws HTTP 401 if the condition isn't satisfied. How do I throw HTTP 404 instead?