001: // AuthUser.java
002: // $Id: AuthUser.java,v 1.8 2002/06/26 17:55:05 ylafon Exp $
003: // (c) COPYRIGHT MIT and INRIA, 1996.
004: // Please first read the full copyright statement in file COPYRIGHT.html
005:
006: package org.w3c.jigsaw.auth;
007:
008: import java.util.Hashtable;
009:
010: import org.w3c.tools.resources.Attribute;
011: import org.w3c.tools.resources.AttributeHolder;
012: import org.w3c.tools.resources.AttributeRegistry;
013: import org.w3c.tools.resources.Resource;
014: import org.w3c.tools.resources.ResourceContext;
015: import org.w3c.tools.resources.StringArrayAttribute;
016: import org.w3c.tools.resources.StringAttribute;
017:
018: /**
019: * The basic description of a user.
020: * A user is defined by the following set of attributes: its name, its email
021: * adress, some comments. Than it can have either an IP adress, and/or
022: * a password.
023: * <p>If an IP adress is provided, the user will be authentified by its
024: * incoming connection IP address. Moreover, if a password is provided,
025: * before being authentified, the client will be challenged for it.
026: * <p>Finally a user can be registered in any number of groups.
027: */
028:
029: public class AuthUser extends Resource {
030: /**
031: * Attribute index - The email adress of the user.
032: */
033: protected static int ATTR_EMAIL = -1;
034: /**
035: * Attribute index - The comments for this user.
036: */
037: protected static int ATTR_COMMENTS = -1;
038: /**
039: * Attribute index - The IP adress of the user.
040: */
041: protected static int ATTR_IPADDR = -1;
042: /**
043: * Attribute index - The optional password for the user.
044: */
045: protected static int ATTR_PASSWORD = -1;
046: /**
047: * Attribute index - The list of groups this user belongs to.
048: */
049: protected static int ATTR_GROUPS = -1;
050:
051: static {
052: Attribute a = null;
053: Class cls = null;
054:
055: try {
056: cls = Class.forName("org.w3c.jigsaw.auth.AuthUser");
057: } catch (Exception ex) {
058: ex.printStackTrace();
059: System.exit(1);
060: }
061: // The user email address
062: a = new StringAttribute("email", null, Attribute.EDITABLE);
063: ATTR_EMAIL = AttributeRegistry.registerAttribute(cls, a);
064: // The comments for the user
065: a = new StringAttribute("comments", null, Attribute.EDITABLE);
066: ATTR_COMMENTS = AttributeRegistry.registerAttribute(cls, a);
067: // The IP address of the user (optional)
068: a = new IPTemplatesAttribute("ipaddress", null,
069: Attribute.EDITABLE);
070: ATTR_IPADDR = AttributeRegistry.registerAttribute(cls, a);
071: // The password for the user
072: a = new PasswordAttribute("password", null, Attribute.EDITABLE);
073: ATTR_PASSWORD = AttributeRegistry.registerAttribute(cls, a);
074: // The groups the user belong to.
075: a = new StringArrayAttribute("groups", null, Attribute.EDITABLE);
076: ATTR_GROUPS = AttributeRegistry.registerAttribute(cls, a);
077: }
078:
079: /**
080: * Get this user's name.
081: * We use the resource identifier as the user name here.
082: */
083:
084: public String getName() {
085: return getIdentifier();
086: }
087:
088: /**
089: * Get the user email address.
090: */
091:
092: public String getEmail() {
093: return (String) getValue(ATTR_EMAIL, null);
094: }
095:
096: /**
097: * Get the user associated comments.
098: */
099:
100: public String getComments() {
101: return (String) getValue(ATTR_COMMENTS, null);
102: }
103:
104: /**
105: * Get the user IP templates.
106: */
107:
108: public short[][] getIPTemplates() {
109: return (short[][]) getValue(ATTR_IPADDR, null);
110: }
111:
112: /**
113: * Get the user password.
114: */
115:
116: public String getPassword() {
117: return (String) getValue(ATTR_PASSWORD, null);
118: }
119:
120: /**
121: * Set a new password for this user.
122: * @param passwd The new user's password.
123: */
124:
125: public void setPassword(String passwd) {
126: setString(ATTR_PASSWORD, passwd);
127: }
128:
129: /**
130: * Get the user groups.
131: */
132:
133: public String[] getGroups() {
134: return (String[]) getValue(ATTR_GROUPS, null);
135: }
136:
137: /**
138: * Create a new user.
139: * @param name The user's name.
140: */
141:
142: public static AuthUser makeUser(String name, ResourceContext context) {
143: Hashtable defs = new Hashtable(3);
144: defs.put(id, name);
145: defs.put(co, context);
146: AuthUser user = new AuthUser();
147: user.initialize(defs);
148: return user;
149: }
150:
151: /**
152: * Create a new user.
153: * @param name The user's name.
154: */
155: public static AuthUser makeUser(Resource res, String name,
156: ResourceContext context) {
157: Hashtable defs = new Hashtable(3);
158: defs.put(id, name);
159: defs.put(co, context);
160: AuthUser user = (AuthUser) res;
161: user.initialize(defs);
162: return user;
163: }
164:
165: public AuthUser() {
166: }
167:
168: }
|