001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.security;
019:
020: import java.io.Serializable;
021:
022: import de.finix.contelligent.client.i18n.Resources;
023: import de.finix.contelligent.client.util.list.NameValueComboBox;
024: import de.finix.contelligent.client.util.list.NameValueListModel;
025:
026: public class ComponentAccess implements Serializable {
027:
028: private String permission, mode, parentMode;
029:
030: private Principal principal;
031:
032: private long validFrom;
033:
034: private long validTo;
035:
036: private long period;
037:
038: private long duration;
039:
040: public final static String READ = "READ";
041:
042: public final static String WRITE = "WRITE";
043:
044: public final static String DELETE = "DELETE";
045:
046: public final static String EXECUTE = "EXECUTE";
047:
048: public final static String[] PERMISSIONS = { READ, WRITE, DELETE,
049: EXECUTE };
050:
051: public final static String[] PERMISSIONS_NOEXECUTE = { READ, WRITE,
052: DELETE };
053:
054: public final static String ALLOW = "ALLOW";
055:
056: public final static String RESET = "RESET";
057:
058: public final static String DENY = "DENY";
059:
060: public final static String UNSET = "UNSET";
061:
062: public final static String[] MODES = { ALLOW, RESET, DENY };
063:
064: public ComponentAccess(Principal principal, String permission,
065: String mode, String parentMode, long validFrom,
066: long validTo, long period, long duration) {
067: this .principal = principal;
068: this .permission = permission;
069: this .mode = mode;
070: this .parentMode = parentMode;
071: this .validFrom = validFrom;
072: this .validTo = validTo;
073: this .period = period;
074: this .duration = duration;
075: }
076:
077: public Principal getPrincipal() {
078: return principal;
079: }
080:
081: public String getPrincipalDisplayName() {
082: return getPrincipal().getDisplayName();
083: }
084:
085: public String getPermission() {
086: return permission;
087: }
088:
089: public void setPermission(String permission) {
090: this .permission = permission;
091: }
092:
093: public String getPermissionDisplayName() {
094: return Resources.getLocalString(getPermission());
095: }
096:
097: public void setMode(String mode) {
098: this .mode = mode;
099: }
100:
101: public String getMode() {
102: return mode;
103: }
104:
105: public String getVisibleModeDisplayName() {
106: return Resources.getLocalString(getVisibleMode());
107: }
108:
109: public String getParentMode() {
110: return parentMode;
111: }
112:
113: public void setParentMode(String parentMode) {
114: this .parentMode = parentMode;
115: }
116:
117: public long getValidFrom() {
118: return validFrom;
119: }
120:
121: public void setValidFrom(long validFrom) {
122: this .validFrom = validFrom;
123: }
124:
125: public long getValidTo() {
126: return validTo;
127: }
128:
129: public void setValidTo(long validTo) {
130: this .validTo = validTo;
131: }
132:
133: public long getPeriod() {
134: return period;
135: }
136:
137: public void setPeriod(long period) {
138: this .period = period;
139: }
140:
141: public long getDuration() {
142: return duration;
143: }
144:
145: public void setDuration(long duration) {
146: this .duration = duration;
147: }
148:
149: public String getVisibleMode() {
150: if (mode.equals(UNSET)) {
151: return parentMode;
152: }
153: return mode;
154: }
155:
156: public boolean isInherited() {
157: if (parentMode != null && !parentMode.equals(UNSET)
158: && mode.equals(UNSET)) {
159: return true;
160: } else {
161: return false;
162: }
163: }
164:
165: public String toString() {
166: return "ComponentAccess [permission=" + permission + " mode="
167: + mode + " parentMode=" + parentMode + "]";
168: }
169:
170: final public static NameValueComboBox getDescriptionComboBox(
171: String[] keys) {
172: return new NameValueComboBox(NameValueListModel
173: .buildLocaleNameValuePairs(keys));
174: }
175:
176: public int getType() {
177: if ((validFrom == -1) && (validTo == -1)) {
178: return 0; // Always valid
179: } else if (validTo == -1) {
180: return 1; // Has start
181: } else if (validFrom == -1) {
182: return 2; // Has end
183: } else {
184: return 3; // Has start and end
185: }
186: }
187:
188: public boolean isValid() {
189: if ((validFrom == -1) && (validTo == -1) && (period == -1)
190: && (duration == -1)) {
191: return true;
192: }
193: long current = System.currentTimeMillis();
194: if (!(((current >= validFrom) || (validFrom == -1)) && ((current <= validTo) || (validTo == -1)))) {
195: return false;
196: }
197: if (period != -1) {
198: if (validFrom == -1) {
199: // log.warn("Invalid ACL combination; period specified but no
200: // start time available.");
201: return false;
202: }
203: long currentOffset = (current - validFrom) % period;
204: if (currentOffset > duration) {
205: return false;
206: }
207: }
208: // All checks went through; apply this ACL entry
209: return true;
210: }
211: }
|