View Javadoc

1   /*
2    * Copyright 2004-2006 the Seasar Foundation and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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  }