001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.lenya.cms.ac.usecases;
020:
021: import org.apache.lenya.ac.Accreditable;
022: import org.apache.lenya.ac.Group;
023: import org.apache.lenya.ac.IPRange;
024: import org.apache.lenya.ac.Item;
025: import org.apache.lenya.ac.Role;
026: import org.apache.lenya.ac.User;
027:
028: /**
029: * Wrapper class for credentials.
030: * @version $Id: CredentialWrapper.java 544630 2007-06-05 20:55:45Z rfrovarp $
031: */
032: public class CredentialWrapper {
033:
034: /**
035: * Returns the method of the Credential
036: * @return A string that is either "deny" or "grant"
037: */
038: public String getMethod() {
039: return method;
040: }
041:
042: /**
043: * Returns the accreditable ID.
044: * @return A string.
045: */
046: public String getAccreditableId() {
047: return this .accreditableId;
048: }
049:
050: /**
051: * Returns the accreditable name.
052: * @return A string.
053: */
054: public String getAccreditableName() {
055: return this .accreditableName;
056: }
057:
058: /**
059: * Returns the role ID.
060: * @return A string.
061: */
062: public String getRoleId() {
063: return this .roleId;
064: }
065:
066: /**
067: * Returns the role name.
068: * @return A string.
069: */
070: public String getRoleName() {
071: return this .roleName;
072: }
073:
074: /**
075: * Returns the accreditable type ({@link #USER}, {@link #GROUP}, or {@link #IPRANGE})
076: * @return A string.
077: */
078: public String getType() {
079: return this .type;
080: }
081:
082: /**
083: * Ctor.
084: * @param accreditable The accreditable of the credential to wrap.
085: * @param role The role of the credential to wrap.
086: * @param method
087: */
088: public CredentialWrapper(Accreditable accreditable, Role role,
089: String method) {
090: if (accreditable instanceof Item) {
091: Item item = (Item) accreditable;
092: this .accreditableId = item.getId();
093: this .accreditableName = item.getName();
094:
095: if (item instanceof User) {
096: this .type = USER;
097: } else if (item instanceof Group) {
098: this .type = GROUP;
099: } else if (item instanceof IPRange) {
100: this .type = IPRANGE;
101: }
102: } else {
103: this .accreditableId = "world";
104: this .accreditableName = "the world";
105: this .type = "world";
106: }
107: this .roleId = role.getId();
108: this .roleName = role.getName();
109: this .method = method;
110:
111: }
112:
113: protected static final String USER = "user";
114: protected static final String GROUP = "group";
115: protected static final String IPRANGE = "ipRange";
116:
117: private String type;
118: private String accreditableId;
119: private String accreditableName;
120: private String roleId;
121: private String roleName;
122: private String method;
123:
124: }
|