Hi,
I had to do something similar, but my case was more specific. Surely you can adapt the code to your needs.
I created a hook of "Portal properties" for event "servlet.service.events.pre" with this custom class:
1
2public class CustomPreServiceAction extends Action {
3 public CustomPreServiceAction() {
4 super();
5 }
6 public void run(HttpServletRequest request, HttpServletResponse response)
7 throws ActionException {
8 boolean tieneRol = false;
9
10 ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
11
12 if (themeDisplay.getURLCurrent().equalsIgnoreCase(PropsUtil.get("XXXXXXXXX"))) {
13 User user = themeDisplay.getUser();
14 try {
15 List<Role> roles = user.getRoles();
16 for (Role role : roles) {
17 if (role.getName().equalsIgnoreCase(PropsUtil.get("YYYYYYYYYYY"))) {
18 tieneRol = true;
19 }
20 }
21 } catch (SystemException e) {
22 // TODO Auto-generated catch block
23 e.printStackTrace();
24 }
25
26 if (!tieneRol) {
27 try {
28 response.sendRedirect(PropsUtil.get("ZZZZZZZZZ"));
29 } catch (IOException e) {
30 // TODO Auto-generated catch block
31 e.printStackTrace();
32 }
33 }
34 }
35
36 }
37
38}
I hope you will help.
Regards.
Please sign in to flag this as inappropriate.