001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.server.security;
030:
031: import com.caucho.config.Config;
032: import com.caucho.security.BasicPrincipal;
033: import com.caucho.util.Alarm;
034: import com.caucho.vfs.Depend;
035: import com.caucho.vfs.Path;
036:
037: import javax.annotation.PostConstruct;
038: import javax.servlet.ServletContext;
039: import javax.servlet.ServletException;
040: import javax.servlet.http.HttpServletRequest;
041: import javax.servlet.http.HttpServletResponse;
042: import java.security.Principal;
043: import java.util.*;
044: import java.util.logging.*;
045: import java.io.*;
046:
047: /**
048: * PasswordUser is used by PasswordAuthenticator implementations.
049: */
050: public class PasswordUser {
051: private static final Logger log = Logger
052: .getLogger(PasswordUser.class.getName());
053:
054: private final Principal _principal;
055: private final char[] _password;
056:
057: private final boolean _isDisabled;
058: private final boolean _isAnonymous;
059: private final String[] _roles;
060:
061: public PasswordUser(Principal principal, char[] password,
062: boolean isDisabled, boolean isAnonymous, String[] roles) {
063: _principal = principal;
064: _password = password;
065:
066: _isDisabled = isDisabled;
067: _isAnonymous = isAnonymous;
068:
069: _roles = roles;
070: }
071:
072: public PasswordUser(Principal principal, char[] password,
073: String[] roles) {
074: this (principal, password, false, false, roles);
075: }
076:
077: public PasswordUser(String user, char[] password, String[] roles) {
078: this (new BasicPrincipal(user), password, false, false, roles);
079: }
080:
081: public PasswordUser(String user, char[] password) {
082: this (new BasicPrincipal(user), password, false, false,
083: new String[] { "user" });
084: }
085:
086: /**
087: * Returns the logged-in user principal
088: */
089: public Principal getPrincipal() {
090: return _principal;
091: }
092:
093: /**
094: * Returns true if the user is disabled
095: */
096: public boolean isDisabled() {
097: return _isDisabled;
098: }
099:
100: /**
101: * Returns true if the user is anonymous, i.e. no password
102: */
103: public boolean isAnonymous() {
104: return _isAnonymous;
105: }
106:
107: /**
108: * Returns the password
109: */
110: public char[] getPassword() {
111: return _password;
112: }
113:
114: /**
115: * Clears the password
116: */
117: public void clearPassword() {
118: for (int i = _password.length - 1; i >= 0; i--)
119: _password[i] = 0;
120: }
121:
122: /**
123: * Returns the user's roles
124: */
125: public String[] getRoles() {
126: return _roles;
127: }
128:
129: /**
130: * Creates a copy
131: */
132: public PasswordUser copy() {
133: return new PasswordUser(_principal, _password, _isDisabled,
134: _isAnonymous, _roles);
135: }
136:
137: public String toString() {
138: if (isDisabled())
139: return getClass().getSimpleName() + "[" + _principal
140: + ",disabled]";
141: else
142: return getClass().getSimpleName() + "[" + _principal + "]";
143: }
144: }
|