Suppose we have this code for login & we want if the credential was for admin page the RequestMapping be for admin & if it was for user credential the user redirect to user panel.
now, the main page of both oppose the same url as I defined in my code below, something like :
http://localhost:8080/project/{username}/main
my question is :
how we can separate these two method in here when they have the same RequestMapping “main” after the login checking finished inside the Controller class?
@RequestMapping(value = "/login")
public String welcome(@RequestParam("j_username") String username, @RequestParam("j_password") String password, HttpSession session, Model model) throws RemoteException, NotBoundException {
int checkAccount = uiClient.checkAdminAccount(username, password);
if (checkAccount == 1) {
session.setAttribute("username", username);
return "redirect:/" + username + "/main";
} else if (checkAccount == 0) {
checkAccount = uiClient.checkAccount(username, password);
if (checkAccount == 1) {
session.setAttribute("username", username);
return "redirect:/" + username + "/main";
} else if (checkAccount == 0) {
return "login";
}
} else {
return "databaseError";
}
return "login";
}
@RequestMapping(value = "/{username}/main")
public String indexPage(@PathVariable("username") String username) {
return "/user/userPanel";
}
@RequestMapping(value = "{username}/main")
public String adminIndexPage(@PathVariable("username") String username){
return "/admin/adminPanel";
}
I mean, is there any way like special tag or something that we can put for each Mapping & separate them after the login process finished so the admin redirect to adminPanel & the user also redirect to userPanel but both with the same url:
http://localhost:8080/project/{username}/main
???
What about this way:
For simplicity, I didn’t use Spring Security to check user role here.