KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > lenya > cms > ac > cocoon > CredentialWrapper


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation
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, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.lenya.cms.ac.cocoon;
19
20 import org.apache.lenya.ac.Accreditable;
21 import org.apache.lenya.ac.Group;
22 import org.apache.lenya.ac.IPRange;
23 import org.apache.lenya.ac.Item;
24 import org.apache.lenya.ac.Role;
25 import org.apache.lenya.ac.User;
26
27 /**
28  * Wrapper class for credentials.
29  * @version $Id: CredentialWrapper.java 43242 2004-08-16 16:42:32Z andreas $
30  */

31 public class CredentialWrapper {
32
33     /**
34      * Returns the accreditable ID.
35      * @return A string.
36      */

37     public String JavaDoc getAccreditableId() {
38         return accreditableId;
39     }
40
41     /**
42      * Returns the accreditable name.
43      * @return A string.
44      */

45     public String JavaDoc getAccreditableName() {
46         return accreditableName;
47     }
48
49     /**
50      * Returns the role ID.
51      * @return A string.
52      */

53     public String JavaDoc getRoleId() {
54         return roleId;
55     }
56
57     /**
58      * Returns the role name.
59      * @return A string.
60      */

61     public String JavaDoc getRoleName() {
62         return roleName;
63     }
64
65     /**
66      * Returns the accreditable type ({@link #USER}, {@link #GROUP}, or {@link #IPRANGE})
67      * @return A string.
68      */

69     public String JavaDoc getType() {
70         return type;
71     }
72
73     /**
74      * Ctor.
75      * @param accreditable The accreditable of the credential to wrap.
76      * @param role The role of the credential to wrap.
77      */

78     public CredentialWrapper(Accreditable accreditable, Role role) {
79         if (accreditable instanceof Item) {
80             Item item = (Item) accreditable;
81             accreditableId = item.getId();
82             accreditableName = item.getName();
83         
84             if (item instanceof User) {
85                 type = USER;
86             }
87             else if (item instanceof Group) {
88                 type = GROUP;
89             }
90             else if (item instanceof IPRange) {
91                 type = IPRANGE;
92             }
93         }
94         else {
95             accreditableId = "world";
96             accreditableName = "the world";
97             type = "world";
98         }
99         roleId = role.getId();
100         roleName = role.getName();
101         
102     }
103     
104     public static final String JavaDoc USER = "user";
105     public static final String JavaDoc GROUP = "group";
106     public static final String JavaDoc IPRANGE = "iprange";
107     
108     private String JavaDoc type;
109     private String JavaDoc accreditableId;
110     private String JavaDoc accreditableName;
111     private String JavaDoc roleId;
112     private String JavaDoc roleName;
113
114 }
115
Popular Tags