01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: /* $Id: RemovedAccreditablePolicyBuilder.java 473861 2006-11-12 03:51:14Z gregor $ */
20:
21: package org.apache.lenya.ac.impl;
22:
23: import org.apache.lenya.ac.AccessControlException;
24: import org.apache.lenya.ac.Accreditable;
25: import org.apache.lenya.ac.AccreditableManager;
26: import org.apache.lenya.ac.Group;
27: import org.apache.lenya.ac.IPRange;
28: import org.apache.lenya.ac.User;
29:
30: /**
31: * A PolicyBuilder which can be used after an accreditable was removed.
32: */
33: public class RemovedAccreditablePolicyBuilder extends PolicyBuilder {
34:
35: /**
36: * Ctor.
37: * @param accreditableManager The accreditable manager.
38: */
39: public RemovedAccreditablePolicyBuilder(
40: AccreditableManager accreditableManager) {
41: super (accreditableManager);
42: }
43:
44: private Accreditable removedAccreditable;
45:
46: /**
47: * Sets the removed accreditable.
48: *
49: * @param accreditable An accreditable.
50: */
51: public void setRemovedAccreditable(Accreditable accreditable) {
52: this .removedAccreditable = accreditable;
53: }
54:
55: /**
56: * @see org.apache.lenya.ac.impl.PolicyBuilder#getAccreditable(java.lang.String, java.lang.String)
57: */
58: protected Accreditable getAccreditable(String elementName, String id)
59: throws AccessControlException {
60:
61: Accreditable accreditable;
62:
63: if (this .removedAccreditable instanceof User
64: && elementName.equals(USER_ELEMENT)
65: && ((User) this .removedAccreditable).getId().equals(id)) {
66: accreditable = this .removedAccreditable;
67: } else if (this .removedAccreditable instanceof Group
68: && elementName.equals(GROUP_ELEMENT)
69: && ((Group) this .removedAccreditable).getId()
70: .equals(id)) {
71: accreditable = this .removedAccreditable;
72: } else if (this .removedAccreditable instanceof IPRange
73: && elementName.equals(IP_RANGE_ELEMENT)
74: && ((IPRange) this.removedAccreditable).getId().equals(
75: id)) {
76: accreditable = this.removedAccreditable;
77: } else {
78:
79: accreditable = super.getAccreditable(elementName, id);
80: }
81: return accreditable;
82: }
83:
84: }
|