~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/server/Simias.Server/.svn/text-base/Registration.asmx.cs.svn-base

  • Committer: Jorge O. Castro
  • Date: 2007-12-03 06:56:46 UTC
  • Revision ID: jorge@ubuntu.com-20071203065646-mupcnjcwgm5mnhyt
* Remove a bunch of .svn directories we no longer need.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/****************************************************************************
2
 
 |
3
 
 | Copyright (c) 2007 Novell, Inc.
4
 
 | All Rights Reserved.
5
 
 |
6
 
 | This program is free software; you can redistribute it and/or
7
 
 | modify it under the terms of version 2 of the GNU General Public License as
8
 
 | published by the Free Software Foundation.
9
 
 |
10
 
 | This program is distributed in the hope that it will be useful,
11
 
 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 | GNU General Public License for more details.
14
 
 |
15
 
 | You should have received a copy of the GNU General Public License
16
 
 | along with this program; if not, contact Novell, Inc.
17
 
 |
18
 
 | To contact Novell about this file by physical or electronic mail,
19
 
 | you may find current contact information at www.novell.com
20
 
 |
21
 
 |  Author: Brady Anderson <banderso@novell.com>
22
 
 |***************************************************************************/
23
 
 
24
 
using System;
25
 
using System.Security.Cryptography;
26
 
using System.Web;
27
 
using System.Web.Services;
28
 
using System.Web.Services.Protocols;
29
 
 
30
 
using Simias;
31
 
using Simias.Storage;
32
 
 
33
 
namespace Simias.Server
34
 
{
35
 
        /// <summary>
36
 
        /// The registration status.
37
 
        /// </summary>
38
 
        public enum RegistrationStatus
39
 
        {
40
 
                /// <summary>
41
 
                /// The user was created.
42
 
                /// </summary>
43
 
                UserCreated = 0,
44
 
 
45
 
                /// <summary>
46
 
                /// The user already exists.
47
 
                /// </summary>
48
 
                UserAlreadyExists,
49
 
 
50
 
                /// <summary>
51
 
                /// Invalid parameters were specified.
52
 
                /// </summary>
53
 
                InvalidParameters,
54
 
 
55
 
                /// <summary>
56
 
                /// Invalid domain was specified.
57
 
                /// </summary>
58
 
                InvalidDomain,
59
 
 
60
 
                /// <summary>
61
 
                /// Username policy exception.
62
 
                /// </summary>
63
 
                UsernamePolicyException,
64
 
 
65
 
                /// <summary>
66
 
                /// Password policy exception.
67
 
                /// </summary>
68
 
                PasswordPolicyException,
69
 
 
70
 
                /// <summary>
71
 
                /// No user providers are registered.
72
 
                /// </summary>
73
 
                NoRegisteredUserProvider,
74
 
 
75
 
                /// <summary>
76
 
                /// The method is not supported.
77
 
                /// </summary>
78
 
                MethodNotSupported,
79
 
 
80
 
                /// <summary>
81
 
                /// An internal exception occurred.
82
 
                /// </summary>
83
 
                InternalException
84
 
        }
85
 
        
86
 
        /// <summary>
87
 
        /// Class that represents the current state and configuration
88
 
        /// of the synchronization service.
89
 
        /// </summary>
90
 
        [ Serializable ]
91
 
        public class RegistrationInfo
92
 
        {
93
 
                /// <summary>
94
 
                /// Constructs a RegistrationInfo object.
95
 
                /// </summary>
96
 
                public RegistrationInfo()
97
 
                {
98
 
                }
99
 
 
100
 
                /// <summary>
101
 
                /// Constructs a RegistrationInfo object.
102
 
                /// </summary>
103
 
                /// <param name="StatusCode">The status of the registration.</param>
104
 
                public RegistrationInfo( RegistrationStatus StatusCode )
105
 
                {
106
 
                        Status = StatusCode;
107
 
                }
108
 
                
109
 
                /// <summary>
110
 
                /// Status result from a create or delete
111
 
                /// method
112
 
                /// </summary>
113
 
                public RegistrationStatus Status;
114
 
                
115
 
                /// <summary>
116
 
                /// Message returned from the CreateUser method.
117
 
                /// </summary>
118
 
                public string Message;
119
 
                
120
 
                /// <summary>
121
 
                /// Guid assigned to the user.
122
 
                /// Not valid if the registration method fails.
123
 
                /// </summary>
124
 
                public string UserGuid;
125
 
                
126
 
                /// <summary>
127
 
                /// Distinguished Name in the external identity database.
128
 
                /// Not valid if the registration method fails.
129
 
                /// </summary>
130
 
                public string DistinguishedName;
131
 
                
132
 
                /// <summary>
133
 
                /// If the Registration.CreateUser method fails with a
134
 
                /// UserExists status, the provider MAY return a list of
135
 
                /// suggested names the caller could try.
136
 
                /// </summary>
137
 
                public string[] SuggestedNames;
138
 
        }
139
 
        
140
 
        /// <summary>
141
 
        /// Registration
142
 
        /// Web service methods to manage the Identity Sync Service
143
 
        /// </summary>
144
 
        [WebService(
145
 
         Namespace="http://novell.com/simias-server/registration",
146
 
         Name="User Registration",
147
 
         Description="Web Service providing self provisioning/registration for Simias users.")]
148
 
        public class Registration : System.Web.Services.WebService
149
 
        {
150
 
                private Store store = null;
151
 
                
152
 
                /// <summary>
153
 
                /// Used to log messages.
154
 
                /// </summary>
155
 
                private static readonly ISimiasLog log =
156
 
                        SimiasLogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
157
 
        
158
 
                /// <summary>
159
 
                /// Constructor
160
 
                /// </summary>
161
 
                public Registration()
162
 
                {
163
 
                        store = Store.GetStore();
164
 
                }
165
 
                
166
 
                /// <summary>
167
 
                /// Method to get the domain's public key
168
 
                /// </summary>
169
 
                [WebMethod( EnableSession = true )]
170
 
                [SoapDocumentMethod]
171
 
                public
172
 
                string
173
 
                GetPublicKey()
174
 
                {
175
 
                        Simias.Storage.Domain domain = store.GetDomain( store.LocalDomain );
176
 
                        RSACryptoServiceProvider pubKey = domain.Owner.PublicKey;
177
 
                        
178
 
                        log.Debug( "Public Key: " + pubKey.ToString() );
179
 
                        log.Debug( "Public Key (XML): " + pubKey.ToXmlString( false ) );
180
 
                        
181
 
                        return pubKey.ToXmlString( false );
182
 
                }
183
 
                
184
 
                /// <summary>
185
 
                /// Method to add/create a new user in the system.
186
 
                /// </summary>
187
 
                /// <param name="Username">Username (mandatory) short name of the user</param>
188
 
                /// <param name="Password">Password (mandatory)</param>
189
 
                /// <param name="UserGuid">UserGuid (optional) caller can specify the guid for the user</param>
190
 
                /// <param name="FirstName">FirstName (optional) first/given name of the user</param>
191
 
                /// <param name="LastName">LastName (optional) last/family name of the user</param>
192
 
                /// <param name="FullName">FullName (optional) Fullname of the user</param>
193
 
                /// <param name="DistinguishedName">DistinguishedName (optional) usually the distinguished name from an external identity store</param>
194
 
                /// <param name="Email">Email (optional) Primary email address</param>
195
 
                /// <remarks>
196
 
                /// If the FirstName and LastName are specified but the FullName is null, FullName is
197
 
                /// autocreated using: FirstName + " " + LastName
198
 
                /// </remarks>
199
 
                [WebMethod( EnableSession = true )]
200
 
                [SoapDocumentMethod]
201
 
                public
202
 
                RegistrationInfo
203
 
                CreateUser(
204
 
                        string  Username,
205
 
                        string  Password,
206
 
                        string  UserGuid,
207
 
                        string  FirstName,
208
 
                        string  LastName,
209
 
                        string  FullName,
210
 
                        string  DistinguishedName,
211
 
                        string  Email)
212
 
                {
213
 
                        RegistrationInfo info;
214
 
                        
215
 
                        if ( Username == null || Username == "" || Password == null )
216
 
                        {
217
 
                                info = new RegistrationInfo( RegistrationStatus.InvalidParameters );
218
 
                                info.Message = "Missing mandatory parameters";
219
 
                                log.Info( "called with missing mandatory parameters" );
220
 
                        }
221
 
                        else
222
 
                        {
223
 
                                Simias.Server.User user = new Simias.Server.User( Username );
224
 
                                user.FirstName = FirstName;
225
 
                                user.LastName = LastName;
226
 
                                user.UserGuid = UserGuid;
227
 
                                user.FullName = FullName;
228
 
                                user.DN = DistinguishedName;
229
 
                                user.Email = Email;
230
 
                        
231
 
                                info = user.Create( Password );
232
 
                        }
233
 
                        
234
 
                        return info;
235
 
                }
236
 
        }
237
 
}