KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > policyframework > DelegatedPoliciesDataSource


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.policyframework;
21
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Iterator JavaDoc;
26 import java.util.List JavaDoc;
27
28 import org.apache.commons.logging.Log;
29 import org.apache.commons.logging.LogFactory;
30 import org.apache.struts.util.LabelValueBean;
31
32 import com.sslexplorer.input.MultiSelectDataSource;
33 import com.sslexplorer.security.SessionInfo;
34 import com.sslexplorer.security.User;
35
36 public class DelegatedPoliciesDataSource implements MultiSelectDataSource {
37
38     final static Log log = LogFactory.getLog(DelegatedPoliciesDataSource.class);
39
40     private Policy checkPolicy;
41     private ResourceType checkResourceType;
42     private String JavaDoc checkPermissionClass;
43     private User checkUser;
44
45     public DelegatedPoliciesDataSource(Policy checkPolicy, ResourceType checkResourceType, String JavaDoc checkPermissionClass, User checkUser) {
46         this.checkPolicy = checkPolicy;
47         this.checkResourceType = checkResourceType;
48         this.checkPermissionClass = checkPermissionClass;
49         this.checkUser = checkUser;
50     }
51
52     public Collection JavaDoc<LabelValueBean> getValues(SessionInfo session) {
53         List JavaDoc l = new ArrayList JavaDoc();
54         try {
55             Policy pol = null;
56             boolean ok = true;
57             List JavaDoc policies = PolicyDatabaseFactory.getInstance().getPolicies(checkUser.getRealm());
58             Collections.sort(policies);
59             for (Iterator JavaDoc i = policies.iterator(); ok && i.hasNext();) {
60                 pol = (Policy) i.next();
61                 if (checkPolicy != null) {
62                     if (pol.getResourceId() == checkPolicy.getResourceId()) {
63                         ok = false;
64                     }
65                 }
66                 if (ok) {
67                     l.add(new LabelValueBean(pol.getResourceName(), String.valueOf(pol.getResourceId())));
68                 }
69                 ok = true;
70             }
71         } catch (Exception JavaDoc e) {
72             log.error("Failed to list policies.", e);
73         }
74         return l;
75     }
76 }
Popular Tags