1 package org.astrogrid.community.client.delegate ;
2
3 import org.apache.commons.logging.Log ;
4 import org.apache.commons.logging.LogFactory ;
5
6 import java.net.URL;
7
8 import org.astrogrid.community.common.policy.data.PolicyCredentials;
9 import org.astrogrid.community.common.policy.data.PolicyPermission;
10
11 import org.astrogrid.community.common.config.CommunityConfig;
12
13 import org.astrogrid.community.common.policy.service.PolicyService ;
14 import org.astrogrid.community.common.policy.service.PolicyServiceService ;
15 import org.astrogrid.community.common.policy.service.PolicyServiceServiceLocator ;
16 /***
17 *
18 *
19 * This API is going to be replaced during iter 5, and will be deprecated in iter 6.
20 *
21 */
22 public class PolicyServiceDelegate
23 {
24 /***
25 * Our debug logger.
26 *
27 */
28 private static Log log = LogFactory.getLog(PolicyServiceDelegate.class);
29
30 /***
31 * Reference to our PolicyManager stub.
32 *
33 */
34 private PolicyService service = null ;
35
36
37
38
39
40 PolicyPermission perm = null;
41
42
43
44 static
45 {
46 CommunityConfig.loadConfig() ;
47 }
48
49 /***
50 * Public constructor deals with getting our service (link) to the webservice.
51 *
52 */
53 public PolicyServiceDelegate()
54 {
55 log.debug("") ;
56 log.debug("----\"----") ;
57 log.debug("PolicyServiceDelegate()") ;
58 try
59 {
60 service = getService(CommunityConfig.getServiceUrl());
61 }
62 catch(Exception e) {
63 e.printStackTrace();
64 service = null;
65 }
66 log.debug("----\"----") ;
67 log.debug("") ;
68 }
69
70 /***
71 * Wrapper method, with account and group identifiers exposed as Strings.
72 *
73 */
74 public boolean checkPermissions(String account,String group, String resource, String action)
75 throws Exception
76 {
77 return checkPermissions(new PolicyCredentials(account,group),resource,action);
78 }
79
80 /***
81 * Call checkPermissions() on our service.
82 * @return false if the check fails or we can't reach the service.
83 */
84 public boolean checkPermissions(PolicyCredentials credentials, String resource, String action) throws Exception {
85
86
87 perm = null ;
88
89
90 if (null != service)
91 {
92 perm = service.checkPermissions(credentials,resource,action);
93 }
94
95
96 return (null != perm) ? perm.isValid() : false ;
97 }
98
99 /***
100 * Access to the PolicyPermission recived by the last call to checkPermissions().
101 *
102 */
103 public PolicyPermission getPolicyPermission()
104 {
105 return this.perm;
106 }
107
108 /***
109 * Return our service object which is our link to the webservice.
110 * @return
111 * @throws Exception
112 */
113 private PolicyService getService(String targetEndPoint)
114 throws Exception
115 {
116 log.debug("") ;
117 log.debug("----\"----") ;
118 log.debug("setUp()") ;
119 log.debug(" Target : '" + targetEndPoint + "'") ;
120
121 if ((null == targetEndPoint) || (targetEndPoint.length() <= 0))
122 {
123 targetEndPoint = CommunityConfig.getServiceUrl() ;
124 }
125 log.debug(" Target : '" + targetEndPoint + "'") ;
126
127 PolicyServiceService locator = null;
128 PolicyService service = null;
129
130
131 locator = new PolicyServiceServiceLocator();
132
133
134
135 service = locator.getPolicyService(new URL(targetEndPoint));
136
137 log.debug("----\"----") ;
138 log.debug("") ;
139 return service;
140 }
141 }