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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.boot;
031:
032: import com.caucho.config.*;
033: import com.caucho.config.program.*;
034: import com.caucho.lifecycle.*;
035: import com.caucho.server.admin.*;
036: import com.caucho.server.resin.*;
037: import com.caucho.security.*;
038: import com.caucho.server.security.*;
039: import com.caucho.webbeans.manager.*;
040: import com.caucho.util.L10N;
041:
042: import javax.annotation.*;
043: import javax.webbeans.*;
044: import java.util.*;
045: import java.util.logging.*;
046:
047: /**
048: * Configuration for management.
049: */
050: public class ManagementConfig {
051: private static L10N L = new L10N(ManagementConfig.class);
052: private static Logger log = Logger.getLogger(ManagementConfig.class
053: .getName());
054:
055: private ManagementAuthenticator _auth;
056:
057: /**
058: * Adds a user
059: */
060: public void addUser(User user) {
061: if (_auth == null)
062: _auth = new ManagementAuthenticator();
063:
064: _auth.addUser(user.getName(), user.getPasswordUser());
065: }
066:
067: public String getAdminCookie() {
068: if (_auth != null)
069: return _auth.getHash();
070: else
071: return null;
072: }
073:
074: public void addBuilderProgram(ConfigProgram program) {
075: }
076:
077: @PostConstruct
078: public void init() {
079: try {
080: if (_auth != null)
081: _auth.init();
082: } catch (Exception e) {
083: throw ConfigException.create(e);
084: }
085: }
086:
087: public static class User {
088: private String _name;
089: private String _password;
090: private boolean _isDisabled;
091:
092: public void setName(String name) {
093: _name = name;
094: }
095:
096: public String getName() {
097: return _name;
098: }
099:
100: public void setPassword(String password) {
101: _password = password;
102: }
103:
104: public String getPassword() {
105: return _password;
106: }
107:
108: public void setDisable(boolean isDisabled) {
109: _isDisabled = isDisabled;
110: }
111:
112: public boolean isDisable() {
113: return _isDisabled;
114: }
115:
116: PasswordUser getPasswordUser() {
117: if (_name == null)
118: throw new ConfigException(
119: L
120: .l("management <user> requires a 'name' attribute"));
121:
122: boolean isAnonymous = false;
123:
124: return new PasswordUser(new BasicPrincipal(_name),
125: _password.toCharArray(), _isDisabled, isAnonymous,
126: new String[] { "resin-admin" });
127: }
128: }
129: }
|