ontomde-demo-acegi 1.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/History.txt +2 -0
  2. data/Manifest.txt +46 -0
  3. data/README.txt +79 -0
  4. data/Rakefile +22 -0
  5. data/bin/ontomde-demo-acegi-install +11 -0
  6. data/demo/1-base.bat +6 -0
  7. data/demo/1-base.sh +5 -0
  8. data/demo/2-unpack.bat +6 -0
  9. data/demo/2-unpack.sh +5 -0
  10. data/demo/3-generate.bat +4 -0
  11. data/demo/3-generate.sh +5 -0
  12. data/demo/4-start-webapp-nosecurity.bat +4 -0
  13. data/demo/4-start-webapp-nosecurity.sh +4 -0
  14. data/demo/5-start-webapp.bat +7 -0
  15. data/demo/5-start-webapp.sh +4 -0
  16. data/demo/9-eclipse.bat +5 -0
  17. data/demo/9-eclipse.sh +6 -0
  18. data/demo/doc/images/_Ea8UYu6FEdyp6cGW4pi6rw.GIF +0 -0
  19. data/demo/doc/images/_XH8XYjuOEdyltIorAFYEcg.GIF +0 -0
  20. data/demo/doc/images/_o7gEAsg1Edy3YZbvY96G9w.GIF +0 -0
  21. data/demo/doc/images/_s1Mq8O6sEdyp6cGW4pi6rw.GIF +0 -0
  22. data/demo/domain/pom.xml +74 -0
  23. data/demo/domain/src/main/java/administration/ApplicationUser.java +649 -0
  24. data/demo/domain/src/main/java/administration/SecurityPanel.java +1408 -0
  25. data/demo/domain/src/main/java/demo1GSMNetwork/BaseTransceiverStation.java +570 -0
  26. data/demo/domain/src/main/java/demo2testModel/Client.java +1099 -0
  27. data/demo/domain/src/main/java/xmda/security/ProviderImpl.java +367 -0
  28. data/demo/ear/pom.xml +160 -0
  29. data/demo/mda/clean-generated.sh +24 -0
  30. data/demo/mda/pom.xml +181 -0
  31. data/demo/mda/src/main/mda/customDataTypes.rb +5 -0
  32. data/demo/mda/src/main/mda/dbDiscriminatorCache.rb +94 -0
  33. data/demo/mda/src/main/mda/mda.rb +0 -0
  34. data/demo/mda/src/main/model/.project +12 -0
  35. data/demo/mda/src/main/model/model.emx +3139 -0
  36. data/demo/mda/src/main/model/model.emx.nt +4608 -0
  37. data/demo/mda/src/main/model/model.emx.nt_kb.pprj +1768 -0
  38. data/demo/mda/src/main/model/model.emx.nt_kb.rdf +258 -0
  39. data/demo/mda/src/main/model/model.emx.nt_kb.rdfs +3345 -0
  40. data/demo/mda/src/main/profil-uml/.project +11 -0
  41. data/demo/mda/src/main/profil-uml/OntoMDE-profil.epx +615 -0
  42. data/demo/mda/src/main/resources/formatter.properties +260 -0
  43. data/demo/pom.xml +21 -0
  44. data/demo/projectbase/pom.xml +96 -0
  45. data/demo/webapp/pom.xml +125 -0
  46. data/lib/ontomde-demo-acegi.rb +1 -0
  47. metadata +109 -0
@@ -0,0 +1,367 @@
1
+ package xmda.security;
2
+
3
+ import java.lang.reflect.Method;
4
+ import java.security.Principal;
5
+ import java.util.ArrayList;
6
+ import java.util.Comparator;
7
+ import java.util.HashSet;
8
+ import java.util.List;
9
+ import java.util.Set;
10
+ import java.util.TreeSet;
11
+ import java.util.Vector;
12
+
13
+ import org.acegisecurity.ConfigAttributeDefinition;
14
+ import org.acegisecurity.GrantedAuthority;
15
+ import org.acegisecurity.GrantedAuthorityImpl;
16
+ import org.acegisecurity.SecurityConfig;
17
+ import org.acegisecurity.context.SecurityContextHolder;
18
+ import org.acegisecurity.userdetails.User;
19
+ import org.acegisecurity.userdetails.UserDetails;
20
+
21
+ import xmda.security.authorization.DBAuthorizationDefinitionSource;
22
+ import administration.ApplicationUser;
23
+ import administration.BusinessGroup;
24
+ import administration.SecureField;
25
+ import administration.SecureMethod;
26
+ import administration.SecureWebFilter;
27
+ import administration.SecurityRole;
28
+
29
+ public class ProviderImpl implements Provider {
30
+
31
+ public static final boolean GRANT_ACCESS=true;
32
+ public static final boolean DENY_ACCESS=false;
33
+
34
+ private static final boolean securityIsDisabled = System
35
+ .getProperty("webapp.security.mode") != null
36
+ && System.getProperty("webapp.security.mode").equalsIgnoreCase(
37
+ "disable");
38
+
39
+ public static boolean getSecurityIsDisabled() {
40
+ return securityIsDisabled;
41
+ }
42
+
43
+ private Object principalObject;
44
+
45
+ public UserDetails loadUser(String userName) {
46
+
47
+ List<administration.ApplicationUser> users = administration.ApplicationUser
48
+ .findAll((ApplicationUser) null);
49
+
50
+ UserDetails userToIdentify = null;
51
+
52
+ for (administration.ApplicationUser user : users) {
53
+
54
+ if (userName != null && userName.equalsIgnoreCase(user.getLogin())) {
55
+
56
+ userToIdentify = new User(user.getLogin(), user.getPassword(),
57
+ true, true, true, true, retrieveAuthorities(user));
58
+
59
+ break;
60
+
61
+ }
62
+
63
+ }
64
+
65
+ principalObject = userToIdentify;
66
+ return userToIdentify;
67
+ }
68
+
69
+ private static GrantedAuthority[] retrieveAuthorities(ApplicationUser user) {
70
+
71
+ GrantedAuthority[] authorities = null;
72
+
73
+ List<SecurityRole> userRoles = new ArrayList<SecurityRole>();
74
+
75
+ if (user != null && user.getUserGroup() != null) {
76
+
77
+ Set<BusinessGroup> groups = user.getUserGroup();
78
+
79
+ for (BusinessGroup group : groups) {
80
+
81
+ userRoles.addAll(group.getGroupRole());
82
+
83
+ }
84
+
85
+ authorities = new GrantedAuthority[userRoles.size()];
86
+
87
+ for (int i = 0; i < userRoles.size(); i++) {
88
+
89
+ authorities[i] = new GrantedAuthorityImpl(userRoles.get(i)
90
+ .getRoleName());
91
+
92
+ }
93
+
94
+ }
95
+
96
+ for (GrantedAuthority auth : authorities) {
97
+
98
+ }
99
+
100
+ return authorities;
101
+
102
+ }
103
+
104
+ public boolean hasViewRights(String fieldName) {
105
+
106
+ boolean isViewable = true;
107
+
108
+ if (!securityIsDisabled) {
109
+
110
+ principalObject = SecurityContextHolder.getContext()
111
+ .getAuthentication().getPrincipal();
112
+
113
+ if (principalObject instanceof UserDetails) {
114
+
115
+ UserDetails principal = (UserDetails) principalObject;
116
+
117
+ SecureField toSecure = null;
118
+
119
+ GrantedAuthority[] grantedRoles = principal.getAuthorities();
120
+
121
+ List<SecureField> fieldList = SecureField
122
+ .findAll((SecureField) null);
123
+
124
+ for (SecureField field : fieldList) {
125
+ if (field.getDefinition() == null) {
126
+ System.out
127
+ .println("Secured field skipped. missing getDefinition()");
128
+ continue;
129
+ }
130
+
131
+ String enumField = field.getDefinition().ownerClass
132
+ .getCanonicalName()
133
+ + "." + field.getDefinition().propertyName;
134
+
135
+ if (fieldName.equalsIgnoreCase(enumField)) {
136
+ toSecure = field;
137
+ break;
138
+ }
139
+ }
140
+
141
+ if (toSecure != null) {
142
+
143
+ if (toSecure.getDefinition().isSecured) {
144
+ isViewable = false;
145
+ Set<SecurityRole> securityRoles = toSecure
146
+ .getSecureFieldRoles();
147
+ for (SecurityRole sRole : securityRoles) {
148
+ for (GrantedAuthority authority : grantedRoles) {
149
+ if (authority.getAuthority().equalsIgnoreCase(
150
+ sRole.getRoleName())) {
151
+ isViewable = true;
152
+ }
153
+ }
154
+
155
+ }
156
+ }
157
+ } else {
158
+
159
+ // Erreur, le nom du champ a �t� modifi� sur la JSP
160
+
161
+ }
162
+ }
163
+ }
164
+
165
+ return isViewable;
166
+
167
+ }
168
+
169
+
170
+ /*
171
+ * Method called by pointcut @Before on method annotated @Secure
172
+ * Must return true for access to be granted.
173
+ * @see xmda.security.Provider#hasMethodAccess(java.lang.String, java.lang.Object)
174
+ *
175
+ * @param signature name of the method called
176
+ * @param target object being accessed
177
+ * @return true if access granted, false if access denied.
178
+ */
179
+ public boolean hasMethodAccess(final String signature, final Object target) {
180
+ System.out.println("hasMethodAccess ??");
181
+ if (securityIsDisabled) {
182
+ // Server is in securityIsDisabled debug mode.
183
+ // Allow access
184
+ System.out.println("granted: WARNING SERVER IN NO SECURITY MODE");
185
+ return GRANT_ACCESS;
186
+ }
187
+
188
+ // user principal
189
+ principalObject = SecurityContextHolder.getContext()
190
+ .getAuthentication().getPrincipal();
191
+ if (!(principalObject instanceof UserDetails)) {
192
+ System.out
193
+ .println("denied: Access denied because of Internal error. Bad principalObject returned by principalObject");
194
+ return DENY_ACCESS;
195
+ }
196
+ UserDetails principal = (UserDetails) principalObject;
197
+
198
+ boolean hasAcces = false;
199
+
200
+ // Example: com.xyz.Aclass.doThat
201
+
202
+ // STEP 1: look for role granting this method.
203
+ boolean foundSecureMethod = false;
204
+ Set<SecurityRole> okRole = getGrantingRoles(target, signature);
205
+ if (okRole.isEmpty()) {
206
+ System.out
207
+ .println("denied: access denied because no possible role/SecureMethod grant found (foundSecureMethod="
208
+ + foundSecureMethod + ")");
209
+ return DENY_ACCESS;
210
+ }
211
+ // STEP 2: check if SecureMethods found match user authorization.
212
+ filterOutNotGrantedRole(principal, okRole);
213
+ if (okRole.isEmpty()) {
214
+ System.out
215
+ .println("denied: access denied because user has no eligible role");
216
+ return DENY_ACCESS;
217
+ }
218
+ if (containsRoleNotRequiringComputedAccessControlCriteria(okRole)) {
219
+ System.out.println("Access granted trough role with computed criteria");
220
+ return GRANT_ACCESS;
221
+ }
222
+
223
+ Set<GlobalComputedAccessControlCriteria> requiredGrants=getRequiredGrants(okRole);
224
+
225
+ Set<xmda.security.GlobalComputedAccessControlCriteria> grants=getGrantedCriteria(target,principal);
226
+ if (grants.isEmpty()) {
227
+ System.out
228
+ .println("denied: access denied because computed grants is empty");
229
+ return DENY_ACCESS;
230
+ }
231
+ grants.retainAll(requiredGrants);
232
+ if (grants.isEmpty()) {
233
+ System.out
234
+ .println("denied: access denied because computed grants is empty do not match required grants");
235
+ return DENY_ACCESS;
236
+ }
237
+ System.out.println("granted: access granted");
238
+ return GRANT_ACCESS;
239
+ }
240
+
241
+ private Set<SecurityRole> getGrantingRoles(final Object target,
242
+ final String signature) {
243
+ String completeSignature = target.getClass().getCanonicalName() + "."
244
+ + signature;
245
+ Set<SecurityRole> okRole = new java.util.HashSet<SecurityRole>();
246
+ List<SecureMethod> methods = SecureMethod.findAll((SecureMethod) null);
247
+ for (SecureMethod method : methods) {
248
+ String enumMethod = method.getSignature().ownerClass
249
+ .getCanonicalName()
250
+ + "." + method.getSignature().operationName;
251
+ if (completeSignature.equals(enumMethod)) {
252
+ okRole.addAll(method.getSecureMethodRoles());
253
+ break;
254
+ }
255
+ }
256
+ return okRole;
257
+ }
258
+
259
+ private void filterOutNotGrantedRole(UserDetails principal,
260
+ Set<SecurityRole> okRole) {
261
+ GrantedAuthority[] authorities = principal.getAuthorities();
262
+ role_loop: for (SecurityRole role : okRole) {
263
+ for (GrantedAuthority authority : authorities) {
264
+ if (authority.getAuthority().equals(role.getRoleName())) {
265
+ // we keep this role
266
+ continue role_loop;
267
+ }
268
+ }
269
+ // We have reach the end of the authority loop and role was not
270
+ // granted.
271
+ // Let's remove it from our ok list
272
+ okRole.remove(role);
273
+ }
274
+ }
275
+
276
+ private boolean containsRoleNotRequiringComputedAccessControlCriteria(
277
+ Set<SecurityRole> okRole) {
278
+ for (SecurityRole role : okRole) {
279
+ if (role.getRequiredComputedAccessRight() == null) {
280
+ // we found one role does not require computation.
281
+ return true;
282
+ }
283
+ }
284
+ return false;
285
+ }
286
+
287
+ public static final String COMPUTE_ACCESS_CONTROL_GRANT_METHOD_NAME = "getComputedAccessControlGrant";
288
+
289
+ private boolean containsGrantedComputedAccessControlCriteria(
290
+ Set<SecurityRole> okRole, Object target, UserDetails principal) {
291
+ return true;
292
+
293
+ }
294
+ private Set<xmda.security.GlobalComputedAccessControlCriteria> getRequiredGrants(Set<SecurityRole> okRole) {
295
+ Set<xmda.security.GlobalComputedAccessControlCriteria> grants=new java.util.HashSet<xmda.security.GlobalComputedAccessControlCriteria>();
296
+ for (SecurityRole role : okRole) {
297
+ grants.add(role.getRequiredComputedAccessRight());
298
+ }
299
+ return grants;
300
+ }
301
+ private Set<xmda.security.GlobalComputedAccessControlCriteria> getGrantedCriteria(
302
+ Object target,UserDetails principal) {
303
+ String longClassName = target.getClass().getName();
304
+
305
+ try {
306
+ Class<?> targetClass = Class.forName(longClassName);
307
+ Method method = targetClass
308
+ .getMethod(COMPUTE_ACCESS_CONTROL_GRANT_METHOD_NAME,
309
+ UserDetails.class);
310
+ if (method == null) {
311
+ System.out.println("Missing method "
312
+ + COMPUTE_ACCESS_CONTROL_GRANT_METHOD_NAME
313
+ + " in class " + longClassName);
314
+ }
315
+ return (Set<xmda.security.GlobalComputedAccessControlCriteria>) method
316
+ .invoke(target, principal);
317
+ } catch (Exception e) {
318
+ System.out.println("ERROR" + e);
319
+ e.printStackTrace();
320
+ }
321
+ //deny access
322
+ return new java.util.HashSet<xmda.security.GlobalComputedAccessControlCriteria>();
323
+ }
324
+
325
+ public List getWebFiltersDefinition() {
326
+
327
+ List requestMap = new Vector();
328
+
329
+ DBAuthorizationDefinitionSource dbauth = new DBAuthorizationDefinitionSource();
330
+
331
+ int count = 0;
332
+
333
+ Set<SecureWebFilter> securedObjects = new TreeSet<SecureWebFilter>(
334
+ new Comparator<SecureWebFilter>() {
335
+
336
+ public int compare(SecureWebFilter o1, SecureWebFilter o2) {
337
+
338
+ return Integer.valueOf(o1.getSortOrder()).compareTo(
339
+ Integer.valueOf(o2.getSortOrder()));
340
+ }
341
+ });
342
+
343
+ List<SecureWebFilter> securedUrls = SecureWebFilter
344
+ .findAll((SecureWebFilter) null);
345
+
346
+ securedObjects.addAll(securedUrls);
347
+
348
+ ConfigAttributeDefinition def = new ConfigAttributeDefinition();
349
+
350
+ for (SecureWebFilter filterInvocation : securedObjects) {
351
+
352
+ def = new ConfigAttributeDefinition();
353
+ for (administration.SecurityRole role : filterInvocation
354
+ .getSecureURLRoles()) {
355
+ def.addConfigAttribute(new SecurityConfig(role.getRoleName()));
356
+
357
+ requestMap.add(count, dbauth.new EntryHolder(filterInvocation
358
+ .getUrl(), def));
359
+ count++;
360
+ }
361
+ }
362
+
363
+ return requestMap;
364
+
365
+ }
366
+
367
+ }
@@ -0,0 +1,160 @@
1
+ <project xmlns="http://maven.apache.org/POM/4.0.0"
2
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
+ <modelVersion>4.0.0</modelVersion>
5
+ <parent>
6
+ <groupId>ontomde.sample</groupId>
7
+ <artifactId>projectbase</artifactId>
8
+ <version>1.0-SNAPSHOT</version>
9
+ </parent>
10
+ <artifactId>sample-ear</artifactId>
11
+ <packaging>ear</packaging>
12
+ <name>sample-ear</name>
13
+ <url>http://maven.apache.org</url>
14
+ <dependencies>
15
+
16
+ <dependency>
17
+ <groupId>ontomde</groupId>
18
+ <artifactId>ontomde-bpm-client</artifactId>
19
+ <version>${ontomde.lib.version}</version>
20
+ <type>ejb</type>
21
+ </dependency>
22
+
23
+ <dependency>
24
+ <groupId>${pom.groupId}</groupId>
25
+ <artifactId>domain</artifactId>
26
+ <version>${pom.version}</version>
27
+ <type>ejb</type>
28
+ </dependency>
29
+
30
+ <dependency>
31
+ <groupId>${pom.groupId}</groupId>
32
+ <artifactId>webapp</artifactId>
33
+ <version>${pom.version}</version>
34
+ <type>war</type>
35
+ </dependency>
36
+
37
+ </dependencies>
38
+
39
+ <!-- 4. Specify the content of generated artifact. -->
40
+ <build>
41
+
42
+ <!-- 4.1. Specify the final name of the artifact. -->
43
+ <finalName>${artifactId}</finalName>
44
+
45
+ <defaultGoal>package</defaultGoal>
46
+
47
+ <!-- 4.2. We don't want to filter for this module: "filters" section is empty. -->
48
+
49
+ <plugins>
50
+
51
+ <plugin>
52
+ <groupId>org.apache.maven.plugins</groupId>
53
+ <artifactId>maven-ear-plugin</artifactId>
54
+ <configuration>
55
+ <encoding>UTF-8</encoding>
56
+ <version>5</version>
57
+ <!-- 4.5. Specify modules to include. -->
58
+ <modules>
59
+ <webModule>
60
+ <groupId>${pom.groupId}</groupId>
61
+ <artifactId>webapp</artifactId>
62
+ <contextRoot>/webapp</contextRoot>
63
+ <!-- 4.5.3.1. Only if you want different file name inside "ear" file.
64
+ <bundleFileName>myBundleWebApplicationModule1FileName</bundleFileName>
65
+ -->
66
+ <!-- 4.5.3.2. Specify the context root if you need different name. -->
67
+ <!-- Default is: "/${pom.artifactId} -->
68
+ </webModule>
69
+ <!-- 4.5.2. Include EJB Module. -->
70
+ <ejbModule>
71
+ <groupId>ontomde</groupId>
72
+ <artifactId>ontomde-bpm-client</artifactId>
73
+ </ejbModule>
74
+ <ejbModule>
75
+ <groupId>${pom.groupId}</groupId>
76
+ <artifactId>domain</artifactId>
77
+ </ejbModule>
78
+ </modules>
79
+ <archive>
80
+ <addMavenDescriptor>false</addMavenDescriptor>
81
+ </archive>
82
+ </configuration>
83
+ </plugin>
84
+
85
+ </plugins>
86
+ </build>
87
+
88
+ <profiles>
89
+ <profile>
90
+ <id>JBOSS</id>
91
+ <activation>
92
+ <property>
93
+ <!-- a BUG avoid using ${env.JEE_SERVER} instead using mvn task -DJEE_SERVER -->
94
+ <name>JEE_SERVER</name>
95
+ <value>JBOSS</value>
96
+ </property>
97
+ </activation>
98
+ <build>
99
+ <plugins>
100
+ <plugin>
101
+ <groupId>org.codehaus.mojo</groupId>
102
+ <artifactId>jboss-maven-plugin</artifactId>
103
+ <executions>
104
+ <execution>
105
+ <phase>install</phase>
106
+ <goals>
107
+ <goal>deploy</goal>
108
+ </goals>
109
+ </execution>
110
+ </executions>
111
+ <configuration>
112
+ <jbossHome>
113
+ C:\applis\AppServers\jboss-5.0.0.Beta2
114
+ </jbossHome>
115
+ </configuration>
116
+ </plugin>
117
+ </plugins>
118
+ </build>
119
+ </profile>
120
+ <profile>
121
+
122
+ <id>GLASSFISH</id>
123
+ <activation>
124
+ <property>
125
+ <!-- a BUG avoid using ${env.JEE_SERVER} instead using mvn task -DJEE_SERVER -->
126
+ <name>JEE_SERVER</name>
127
+ <value>GLASSFISH</value>
128
+ </property>
129
+ </activation>
130
+ <build>
131
+ <plugins>
132
+ <plugin>
133
+ <groupId>pl.sliwa.maven.plugin</groupId>
134
+ <artifactId>glassfish-maven-plugin</artifactId>
135
+ <version>1.0-SNAPSHOT</version>
136
+ <executions>
137
+ <execution>
138
+ <phase>install</phase>
139
+ <goals>
140
+ <goal>deploy</goal>
141
+ </goals>
142
+ </execution>
143
+ </executions>
144
+ <configuration>
145
+ <glassfishHome>
146
+ c:\applis\AppServers\glassfish-v2-b58
147
+ </glassfishHome>
148
+ <domain>runtime</domain>
149
+ <domaindir>
150
+ c:\MesProjets\agis\ejb3
151
+ </domaindir>
152
+ <port>8048</port>
153
+ </configuration>
154
+ </plugin>
155
+ </plugins>
156
+ </build>
157
+ </profile>
158
+ </profiles>
159
+
160
+ </project>