1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.security;
17
18 import java.util.ArrayList;
19
20 import org.apache.commons.lang.ArrayUtils;
21
22 public class SecurityUtils {
23
24
25 public static boolean hasUnauthenticated(String[] roles) {
26 return ArrayUtils.contains(roles, SecurityService.ROLE_UNAUTHENTICATED);
27 }
28
29 public static String[] removeUnauthenticated(String[] roles){
30 if(!hasUnauthenticated(roles)){
31 return roles;
32 }
33 String[] newRoleNames = new String[roles.length - 1];
34 for (int i = 0; i < roles.length - 1; i++) {
35 newRoleNames[i] = roles[i];
36 }
37 return newRoleNames;
38 }
39
40 public static String[] splitRoleNames(String roles){
41 if (roles == null) {
42 return new String[0];
43 }
44 ArrayList list = new ArrayList();
45 while (true) {
46 int comma = roles.indexOf(',');
47 if (comma < 0)
48 break;
49 list.add(roles.substring(0, comma).trim());
50 roles = roles.substring(comma + 1);
51 }
52 roles = roles.trim();
53 if (roles.length() > 0)
54 list.add(roles);
55 return (String[]) list.toArray(new String[list.size()]);
56 }
57
58 }