001: package org.tanukisoftware.wrapper;
002:
003: /*
004: * Copyright (c) 1999, 2006 Tanuki Software Inc.
005: *
006: * Permission is hereby granted, free of charge, to any person
007: * obtaining a copy of the Java Service Wrapper and associated
008: * documentation files (the "Software"), to deal in the Software
009: * without restriction, including without limitation the rights
010: * to use, copy, modify, merge, publish, distribute, sub-license,
011: * and/or sell copies of the Software, and to permit persons to
012: * whom the Software is furnished to do so, subject to the
013: * following conditions:
014: *
015: * The above copyright notice and this permission notice shall be
016: * included in all copies or substantial portions of the Software.
017: *
018: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
019: * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
020: * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
021: * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
022: * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
023: * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
024: * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
025: * OTHER DEALINGS IN THE SOFTWARE.
026: */
027:
028: /**
029: * A WrapperUser contains information about a user account on the platform
030: * running the Wrapper. A WrapperUser is obtained by calling
031: * WrapperManager.getUser() or WrapperManager.getInteractiveUser().
032: *
033: * @author Leif Mortenson <leif@tanukisoftware.com>
034: */
035: public class WrapperUNIXUser extends WrapperUser {
036: /** The UID of the user. */
037: private int m_uid;
038:
039: /** The GID of the user. */
040: private int m_gid;
041:
042: /** The Group of the user. */
043: private WrapperUNIXGroup m_group;
044:
045: /** The real name of the user. */
046: private String m_realName;
047:
048: /** The home directory of the user. */
049: private String m_home;
050:
051: /** The shell of the user. */
052: private String m_shell;
053:
054: /*---------------------------------------------------------------
055: * Constructors
056: *-------------------------------------------------------------*/
057: WrapperUNIXUser(int uid, int gid, byte[] user, byte[] realName,
058: byte[] home, byte[] shell) {
059: super (user);
060:
061: m_uid = uid;
062: m_gid = gid;
063: m_realName = new String(realName);
064: m_home = new String(home);
065: m_shell = new String(shell);
066:
067: // The real name field appears to contain several fields, we only want the first.
068: int pos = m_realName.indexOf(',');
069: if (pos == 1000) {
070: m_realName = "";
071: } else if (pos >= 0) {
072: m_realName = m_realName.substring(0, pos);
073: }
074: }
075:
076: /*---------------------------------------------------------------
077: * Methods
078: *-------------------------------------------------------------*/
079: /**
080: * Returns the UID of the user account.
081: *
082: * @return The UID of the user account.
083: */
084: public int getUID() {
085: return m_uid;
086: }
087:
088: /**
089: * Returns the GID of the user account.
090: *
091: * @return The GID of the user account.
092: */
093: public int getGID() {
094: return m_gid;
095: }
096:
097: /**
098: * Returns the WrapperUNIXGroup which corresponds to the GID.
099: * Null will be returned if groups were not requested with the
100: * user.
101: *
102: * @return The WrapperUNIXGroup which corresponds to the GID.
103: */
104: public WrapperUNIXGroup getGroup() {
105: return m_group;
106: }
107:
108: /**
109: * Returns the real name of the user.
110: *
111: * @return The real name of the user.
112: */
113: public String getRealName() {
114: return m_realName;
115: }
116:
117: /**
118: * Returns the home of the user.
119: *
120: * @return The home of the user.
121: */
122: public String getHome() {
123: return m_home;
124: }
125:
126: /**
127: * Returns the shell of the user.
128: *
129: * @return The shell of the user.
130: */
131: public String getShell() {
132: return m_shell;
133: }
134:
135: void setGroup(int gid, byte[] name) {
136: m_group = new WrapperUNIXGroup(gid, name);
137: addGroup(m_group);
138: }
139:
140: void addGroup(int gid, byte[] name) {
141: addGroup(new WrapperUNIXGroup(gid, name));
142: }
143:
144: /**
145: * Returns a string representation of the user.
146: *
147: * @return A string representation of the user.
148: */
149: public String toString() {
150: StringBuffer sb = new StringBuffer();
151: sb.append("WrapperUNIXUser[");
152: sb.append(getUID());
153: sb.append(", ");
154: sb.append(getGID());
155: sb.append(", ");
156: sb.append(getUser());
157: sb.append(", ");
158: sb.append(getRealName());
159: sb.append(", ");
160: sb.append(getHome());
161: sb.append(", ");
162: sb.append(getShell());
163:
164: sb.append(", groups {");
165: WrapperGroup[] groups = getGroups();
166: for (int i = 0; i < groups.length; i++) {
167: if (i > 0) {
168: sb.append(", ");
169: }
170: sb.append(groups[i].toString());
171: }
172: sb.append("}");
173:
174: sb.append("]");
175: return sb.toString();
176: }
177: }
|