KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > tanukisoftware > wrapper > WrapperUNIXUser


1 package org.tanukisoftware.wrapper;
2
3 /*
4  * Copyright (c) 1999, 2006 Tanuki Software Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of the Java Service Wrapper and associated
8  * documentation files (the "Software"), to deal in the Software
9  * without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sub-license,
11  * and/or sell copies of the Software, and to permit persons to
12  * whom the Software is furnished to do so, subject to the
13  * following conditions:
14  *
15  * The above copyright notice and this permission notice shall be
16  * included in all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21  * NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22  * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25  * OTHER DEALINGS IN THE SOFTWARE.
26  */

27
28 /**
29  * A WrapperUser contains information about a user account on the platform
30  * running the Wrapper. A WrapperUser is obtained by calling
31  * WrapperManager.getUser() or WrapperManager.getInteractiveUser().
32  *
33  * @author Leif Mortenson <leif@tanukisoftware.com>
34  */

35 public class WrapperUNIXUser
36     extends WrapperUser
37 {
38     /** The UID of the user. */
39     private int m_uid;
40     
41     /** The GID of the user. */
42     private int m_gid;
43
44     /** The Group of the user. */
45     private WrapperUNIXGroup m_group;
46
47     /** The real name of the user. */
48     private String JavaDoc m_realName;
49
50     /** The home directory of the user. */
51     private String JavaDoc m_home;
52
53     /** The shell of the user. */
54     private String JavaDoc m_shell;
55     
56     /*---------------------------------------------------------------
57      * Constructors
58      *-------------------------------------------------------------*/

59     WrapperUNIXUser( int uid, int gid, byte[] user, byte[] realName, byte[] home, byte[] shell )
60     {
61         super( user );
62         
63         m_uid = uid;
64         m_gid = gid;
65         m_realName = new String JavaDoc( realName );
66         m_home = new String JavaDoc( home );
67         m_shell = new String JavaDoc( shell );
68
69         // The real name field appears to contain several fields, we only want the first.
70
int pos = m_realName.indexOf( ',' );
71         if ( pos == 1000 )
72         {
73             m_realName = "";
74         }
75         else if ( pos >= 0 )
76         {
77             m_realName = m_realName.substring( 0, pos );
78         }
79     }
80     
81     /*---------------------------------------------------------------
82      * Methods
83      *-------------------------------------------------------------*/

84     /**
85      * Returns the UID of the user account.
86      *
87      * @return The UID of the user account.
88      */

89     public int getUID()
90     {
91         return m_uid;
92     }
93     
94     /**
95      * Returns the GID of the user account.
96      *
97      * @return The GID of the user account.
98      */

99     public int getGID()
100     {
101         return m_gid;
102     }
103
104     /**
105      * Returns the WrapperUNIXGroup which corresponds to the GID.
106      * Null will be returned if groups were not requested with the
107      * user.
108      *
109      * @return The WrapperUNIXGroup which corresponds to the GID.
110      */

111     public WrapperUNIXGroup getGroup()
112     {
113         return m_group;
114     }
115     
116     /**
117      * Returns the real name of the user.
118      *
119      * @return The real name of the user.
120      */

121     public String JavaDoc getRealName()
122     {
123         return m_realName;
124     }
125     
126     /**
127      * Returns the home of the user.
128      *
129      * @return The home of the user.
130      */

131     public String JavaDoc getHome()
132     {
133         return m_home;
134     }
135     
136     /**
137      * Returns the shell of the user.
138      *
139      * @return The shell of the user.
140      */

141     public String JavaDoc getShell()
142     {
143         return m_shell;
144     }
145     
146     void setGroup( int gid, byte[] name )
147     {
148         m_group = new WrapperUNIXGroup( gid, name );
149         addGroup( m_group );
150     }
151
152     void addGroup( int gid, byte[] name )
153     {
154         addGroup( new WrapperUNIXGroup( gid, name ) );
155     }
156     
157     /**
158      * Returns a string representation of the user.
159      *
160      * @return A string representation of the user.
161      */

162     public String JavaDoc toString()
163     {
164         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
165         sb.append( "WrapperUNIXUser[" );
166         sb.append( getUID() );
167         sb.append( ", " );
168         sb.append( getGID() );
169         sb.append( ", " );
170         sb.append( getUser() );
171         sb.append( ", " );
172         sb.append( getRealName() );
173         sb.append( ", " );
174         sb.append( getHome() );
175         sb.append( ", " );
176         sb.append( getShell() );
177         
178         sb.append( ", groups {" );
179         WrapperGroup[] groups = getGroups();
180         for ( int i = 0; i < groups.length; i++ )
181         {
182             if ( i > 0 )
183             {
184                 sb.append( ", " );
185             }
186             sb.append( groups[i].toString() );
187         }
188         sb.append( "}" );
189         
190         sb.append( "]" );
191         return sb.toString();
192     }
193 }
194
195
Popular Tags