KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > security > SecurityManagerImpl


1 package org.nextime.ion.backoffice.security;
2
3 import org.nextime.ion.framework.business.Group;
4 import org.nextime.ion.framework.business.Publication;
5 import org.nextime.ion.framework.business.Section;
6 import org.nextime.ion.framework.business.User;
7
8 import com.opensymphony.workflow.basic.*;
9
10 public class SecurityManagerImpl implements SecurityManager JavaDoc {
11
12     /**
13      * @see org.nextime.ion.backoffice.security.SecurityManager#canAdminResources(User)
14      */

15     public boolean canAdminResources(User user) {
16         try {
17             Group admins = Group.getInstance("admins");
18             return user.isInGroup(admins);
19         } catch (Exception JavaDoc e) {
20             e.printStackTrace();
21         }
22         return false;
23     }
24
25     /**
26      * @see org.nextime.ion.backoffice.security.SecurityManager#canAdminSecurity(User)
27      */

28     public boolean canAdminSecurity(User user) {
29         try {
30             Group admins = Group.getInstance("admins");
31             return user.isInGroup(admins);
32         } catch (Exception JavaDoc e) {
33             e.printStackTrace();
34         }
35         return false;
36     }
37
38     /**
39      * @see org.nextime.ion.backoffice.security.SecurityManager#canCreatePublication(Section, User)
40      */

41     public boolean canCreatePublication(Section section, User user) {
42         try {
43             String JavaDoc workflowType = section.getMetaData("workflow") + "";
44             BasicWorkflow bw = new BasicWorkflow(user.getLogin());
45             return bw.canInitialize(workflowType, 1);
46         } catch (Exception JavaDoc e) {
47             e.printStackTrace();
48         }
49         return false;
50     }
51
52     /**
53      * @see org.nextime.ion.backoffice.security.SecurityManager#canCreateSection(Section, User)
54      */

55     public boolean canCreateSection(Section section, User user) {
56         try {
57             Group admins = Group.getInstance("admins");
58             return user.isInGroup(admins);
59         } catch (Exception JavaDoc e) {
60             e.printStackTrace();
61         }
62         return false;
63     }
64
65     /**
66      * @see org.nextime.ion.backoffice.security.SecurityManager#canDeletePublication(Publication, User)
67      */

68     public boolean canDeletePublication(Publication publication, User user) {
69         try {
70             Group admins = Group.getInstance("webmasters");
71             return user.isInGroup(admins);
72         } catch (Exception JavaDoc e) {
73             e.printStackTrace();
74         }
75         return false;
76     }
77
78     /**
79      * @see org.nextime.ion.backoffice.security.SecurityManager#canDeleteSection(Section, User)
80      */

81     public boolean canDeleteSection(Section section, User user) {
82         try {
83             Group admins = Group.getInstance("admins");
84             return user.isInGroup(admins);
85         } catch (Exception JavaDoc e) {
86             e.printStackTrace();
87         }
88         return false;
89     }
90
91     /**
92      * @see org.nextime.ion.backoffice.security.SecurityManager#canEditPublication(Publication, User)
93      */

94     public boolean canEditPublication(
95         Publication publication,
96         int version,
97         User user) {
98         try {
99             Group admins = Group.getInstance("admins");
100             if (user.isInGroup(admins))
101                 return true;
102             return publication
103                 .getVersion(version)
104                 .getWorkflow(user)
105                 .getPermissions()
106                 .contains("canEdit");
107         } catch (Exception JavaDoc e) {
108             e.printStackTrace();
109         }
110         return false;
111     }
112
113     /**
114      * @see org.nextime.ion.backoffice.security.SecurityManager#canEditSection(Section, User)
115      */

116     public boolean canEditSection(Section section, User user) {
117         try {
118             Group admins = Group.getInstance("admins");
119             return user.isInGroup(admins);
120         } catch (Exception JavaDoc e) {
121             e.printStackTrace();
122         }
123         return false;
124     }
125
126     /**
127      * @see org.nextime.ion.backoffice.security.SecurityManager#canLogIntoBackoffice(User)
128      */

129     public boolean canLogIntoBackoffice(User user) {
130         try {
131             Group admins = Group.getInstance("admins");
132             Group contributeurs = Group.getInstance("users");
133             Group webmasters = Group.getInstance("webmasters");
134             return user.isInGroup(admins) || user.isInGroup(contributeurs) || user.isInGroup(webmasters);
135         } catch (Exception JavaDoc e) {
136             e.printStackTrace();
137         }
138         return false;
139     }
140
141 }
142
Popular Tags