1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package org.kuali.mobility.shared.controllers;
16
17 import org.kuali.mobility.security.authn.util.AuthenticationConstants;
18 import org.kuali.mobility.security.group.api.Group;
19 import org.kuali.mobility.security.user.api.User;
20
21 import javax.annotation.Resource;
22 import javax.servlet.http.HttpServletRequest;
23 import java.util.Properties;
24
25
26
27
28
29
30
31 public class AbstractMobilityController {
32
33 @Resource(name="kmeProperties")
34 private Properties kmeProperties;
35
36 public boolean isAllowedAccess(String roleName, HttpServletRequest request) {
37 boolean isAllowed = false;
38
39 if( roleName == null || roleName.isEmpty() ) {
40 isAllowed = true;
41 } else if ( request.getSession() == null ) {
42 isAllowed = false;
43 } else {
44 User user = (User)request.getSession().getAttribute(AuthenticationConstants.KME_USER_KEY);
45 if( user == null || user.isPublicUser() ) {
46 isAllowed = false;
47 } else if( user.getGroups() == null || user.getGroups().isEmpty() ) {
48 isAllowed = false;
49 } else {
50 for( Group group : user.getGroups() ) {
51 if( group.getName().equalsIgnoreCase(roleName) ) {
52 isAllowed = true;
53 break;
54 }
55 }
56 }
57 }
58
59 return isAllowed;
60 }
61
62 public Properties getKmeProperties() {
63 return kmeProperties;
64 }
65
66 public void setKmeProperties(Properties kmeProperties) {
67 this.kmeProperties = kmeProperties;
68 }
69 }