| 1 | // Copyright 2004-2007 Jean-Francois Poilpret |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package net.sourceforge.hivelock; |
| 16 | |
| 17 | import java.util.SortedSet; |
| 18 | import java.util.StringTokenizer; |
| 19 | import java.util.TreeSet; |
| 20 | |
| 21 | import org.apache.hivemind.impl.BaseLocatable; |
| 22 | import org.apache.hivemind.util.ToStringBuilder; |
| 23 | |
| 24 | public class AuthorizationContribution extends BaseLocatable |
| 25 | { |
| 26 | public void setRole(String roles) |
| 27 | { |
| 28 | _roles = roles; |
| 29 | // Parse the list to build more convenient info |
| 30 | StringTokenizer tokens = new StringTokenizer(roles, ","); |
| 31 | SortedSet<String> allRoles = new TreeSet<String>(); |
| 32 | while (tokens.hasMoreTokens()) |
| 33 | { |
| 34 | String next = tokens.nextToken(); |
| 35 | if ("".equals(next)) |
| 36 | { |
| 37 | continue; |
| 38 | } |
| 39 | if ("*".equals(next)) |
| 40 | { |
| 41 | _allRoles = null; |
| 42 | return; |
| 43 | } |
| 44 | allRoles.add(next); |
| 45 | } |
| 46 | _allRoles = allRoles.toArray(new String[allRoles.size()]); |
| 47 | } |
| 48 | |
| 49 | public String getRole() |
| 50 | { |
| 51 | return _roles; |
| 52 | } |
| 53 | |
| 54 | public String[] getRoles() |
| 55 | { |
| 56 | return _allRoles; |
| 57 | } |
| 58 | |
| 59 | public void setPattern(String string) |
| 60 | { |
| 61 | _pattern = string; |
| 62 | } |
| 63 | |
| 64 | public String getPattern() |
| 65 | { |
| 66 | return _pattern; |
| 67 | } |
| 68 | |
| 69 | public String toString() |
| 70 | { |
| 71 | ToStringBuilder builder = new ToStringBuilder(this); |
| 72 | builder.append("pattern", _pattern); |
| 73 | builder.append("roles", _roles); |
| 74 | return builder.toString(); |
| 75 | } |
| 76 | |
| 77 | private String[] _allRoles; |
| 78 | private String _roles; |
| 79 | private String _pattern; |
| 80 | } |