~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/server/Simias.Server/.svn/text-base/IdentitySyncManager.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.Web;
26
 
using System.Web.Services;
27
 
using System.Web.Services.Protocols;
28
 
 
29
 
namespace Simias.IdentitySync
30
 
{
31
 
        /// <summary>
32
 
        /// Class that represents the state of the last
33
 
        /// synchronization cycle
34
 
        /// </summary>
35
 
        [ Serializable ]
36
 
        public class LastSyncInfo
37
 
        {
38
 
                /// <summary>
39
 
                /// Date and Time when the last sync cycle started
40
 
                /// RFC 822 format
41
 
                /// </summary>
42
 
                public string   StartTime;
43
 
 
44
 
                /// <summary>
45
 
                /// Date and Time when the last sync cycle finished
46
 
                /// RFC 822 format
47
 
                /// </summary>
48
 
                public string   EndTime;
49
 
                
50
 
                /// <summary>
51
 
                /// The number of members processed during the cycle
52
 
                /// </summary>
53
 
                public int              MembersProcessed;
54
 
 
55
 
                /// <summary>
56
 
                /// Number of members added to the domain during
57
 
                /// the cycle
58
 
                /// </summary>
59
 
                public int              MembersAdded;
60
 
 
61
 
                /// <summary>
62
 
                /// Number of members changed or updated because
63
 
                /// of meta-data changing ex. First Name
64
 
                /// </summary>
65
 
                public int              MembersUpdated;
66
 
 
67
 
                /// <summary>
68
 
                /// Number of members deleted from the domain during
69
 
                /// the cycle
70
 
                /// </summary>
71
 
                public int              MembersDeleted;
72
 
                
73
 
                /// <summary>
74
 
                /// Number of members disabled in the domain during
75
 
                /// the cycle
76
 
                /// </summary>
77
 
                public int              MembersDisabled;
78
 
                
79
 
                /// <summary>
80
 
                /// Number of reported errors during the cycle
81
 
                /// </summary>
82
 
                public int              ReportedErrors;
83
 
 
84
 
                /// <summary>
85
 
                /// Messages reported during the cycle
86
 
                /// </summary>
87
 
                public string[] Messages;
88
 
        }
89
 
        
90
 
        /// <summary>
91
 
        /// Class that represents the current state and configuration
92
 
        /// of the synchronization service.
93
 
        /// </summary>
94
 
        [ Serializable ]
95
 
        public class ServiceInfo
96
 
        {
97
 
                /// <summary>
98
 
                /// Date and Time when the synchronization engine was
99
 
                /// started.
100
 
                /// RFC 822 format
101
 
                /// </summary>
102
 
                public string UpSince;
103
 
                
104
 
                /// <summary>
105
 
                /// Number of cycles the engine performed
106
 
                /// </summary>
107
 
                public int Cycles;
108
 
                
109
 
                /// <summary>
110
 
                /// Name of the registered synchronization provider
111
 
                /// </summary>
112
 
                public string   Provider;
113
 
 
114
 
                /// <summary>
115
 
                /// Configured time interval, represented in seconds,
116
 
                /// between synchronization cycles.
117
 
                /// </summary>
118
 
                public int      SynchronizationInterval;
119
 
 
120
 
                /// <summary>
121
 
                /// Configured grace period, represented in seconds,
122
 
                /// the sync service will allow a member to remain
123
 
                /// in the domain when the member no longer exists
124
 
                /// in the external identity store.
125
 
                ///
126
 
                /// Members become disabled in the Simias domain when
127
 
                /// they are no longer exist in the external store.
128
 
                /// </summary>
129
 
                public int      DeleteMemberGracePeriod;
130
 
                
131
 
                /// <summary>
132
 
                /// Current status of the synchronization engine
133
 
                /// status will be one of the following:
134
 
                /// "running"
135
 
                /// "sleeping"
136
 
                /// "disabled"
137
 
                /// "shutdown"
138
 
                /// </summary>
139
 
                public string Status;
140
 
        }
141
 
        
142
 
        /// <summary>
143
 
        /// Identity Sync Manager
144
 
        /// Web service methods to manage the Identity Sync Service
145
 
        /// </summary>
146
 
        [WebService(
147
 
         Namespace="http://novell.com/simias/idsyncmgr",
148
 
         Name="Identity Sync Manager",
149
 
         Description="Web Service providing management for the Identity Sync Service.")]
150
 
        public class Manager : System.Web.Services.WebService
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 Manager()
162
 
                {
163
 
                }
164
 
                
165
 
                private static string[] MonthsOfYear =
166
 
                {
167
 
                        "Jan",
168
 
                        "Feb",
169
 
                        "Mar",
170
 
                        "Apr",
171
 
                        "May",
172
 
                        "Jun",
173
 
                        "Jul",
174
 
                        "Aug",
175
 
                        "Sep",
176
 
                        "Oct",
177
 
                        "Nov",
178
 
                        "Dec"
179
 
                };
180
 
                
181
 
                /// <summary>
182
 
                /// Method to disable the synchronization service
183
 
                /// true - disables
184
 
                /// false - enables the synchronization service
185
 
                /// Note! once enabled the service will enter a
186
 
                /// synchronization cycle ignoring the configured
187
 
                /// sync interval time.
188
 
                /// </summary>
189
 
                ///
190
 
                [WebMethod( EnableSession = true )]
191
 
                [SoapDocumentMethod]
192
 
                public void DisableSyncService( bool Disable )
193
 
                {
194
 
                        IdentitySync.Service.syncDisabled = Disable;
195
 
                }
196
 
 
197
 
                /// <summary>
198
 
                /// Tells the sync service to immediately start
199
 
                /// a synchronization cycle.
200
 
                /// </summary>
201
 
                ///
202
 
                [WebMethod( EnableSession = true )]
203
 
                [SoapDocumentMethod]
204
 
                public void SyncNow()
205
 
                {
206
 
                        IdentitySync.Service.SyncNow( "" );
207
 
                }
208
 
 
209
 
                /// <summary>
210
 
                /// Get the current status of the identity sync service thread
211
 
                /// status could be:
212
 
                /// Disabled
213
 
                /// Working
214
 
                /// Waiting
215
 
                /// Authentication Failure
216
 
                /// etc..
217
 
                /// </summary>
218
 
                ///
219
 
                [WebMethod( EnableSession = true )]
220
 
                [SoapDocumentMethod]
221
 
                public ServiceInfo GetSyncServiceInfo()
222
 
                {
223
 
                        ServiceInfo info = new ServiceInfo();
224
 
                        
225
 
                        info.UpSince =
226
 
                                String.Format(
227
 
                                        "{0}, {1} {2} {3} {4}:{5}:{6} GMT",
228
 
                                        Service.upSince.DayOfWeek.ToString(),
229
 
                                        Service.upSince.Day,
230
 
                                        Simias.IdentitySync.Manager.MonthsOfYear[ Service.upSince.Month - 1 ],
231
 
                                        Service.upSince.Year.ToString(),
232
 
                                        Service.upSince.Hour,
233
 
                                        Service.upSince.Minute,
234
 
                                        Service.upSince.Second );
235
 
                        
236
 
                        info.Cycles = IdentitySync.Service.cycles;
237
 
                        
238
 
                        // Get the first provider.   At the moment, sync engine only supports
239
 
                        // one provider anyway.
240
 
                        foreach( IIdentitySyncProvider prov in Service.registeredProviders.Values )
241
 
                        {
242
 
                                info.Provider = prov.Name;
243
 
                                break;
244
 
                        }
245
 
                        
246
 
                        info.DeleteMemberGracePeriod = IdentitySync.Service.deleteGracePeriod;
247
 
                        info.SynchronizationInterval = IdentitySync.Service.syncInterval;
248
 
                        info.Status = IdentitySync.Service.status;
249
 
                        
250
 
                        return info;
251
 
                }
252
 
                
253
 
                /// <summary>
254
 
                /// Get detailed information about the last synchronization
255
 
                /// cycle.
256
 
                /// </summary>
257
 
                [WebMethod( EnableSession = true )]
258
 
                [SoapDocumentMethod]
259
 
                public LastSyncInfo GetLastSyncInfo()
260
 
                {
261
 
                        log.Debug( "GetLastSyncInfo - called" );
262
 
                        
263
 
                        IdentitySync.State state = Simias.IdentitySync.Service.lastState;
264
 
                        if ( state == null )
265
 
                        {
266
 
                                return null;
267
 
                        }
268
 
                        
269
 
                        LastSyncInfo info = new LastSyncInfo();
270
 
                        info.ReportedErrors = state.Errors;
271
 
                        info.MembersProcessed = state.Processed;
272
 
                        log.Debug( "  members processed: "  + info.MembersProcessed.ToString() );
273
 
 
274
 
                        info.StartTime =
275
 
                                String.Format(
276
 
                                        "{0}, {1} {2} {3} {4}:{5}:{6} GMT",
277
 
                                        state.StartTime.DayOfWeek.ToString(),
278
 
                                        state.StartTime.Day,
279
 
                                        Simias.IdentitySync.Manager.MonthsOfYear[ state.StartTime.Month - 1 ],
280
 
                                        state.StartTime.Year.ToString(),
281
 
                                        state.StartTime.Hour,
282
 
                                        state.StartTime.Minute,
283
 
                                        state.StartTime.Second );
284
 
                        log.Debug( "  sync start time: " + info.StartTime );
285
 
                        
286
 
                        info.EndTime =
287
 
                                String.Format(
288
 
                                        "{0}, {1} {2} {3} {4}:{5}:{6} GMT",
289
 
                                        state.EndTime.DayOfWeek.ToString(),
290
 
                                        state.EndTime.Day,
291
 
                                        Simias.IdentitySync.Manager.MonthsOfYear[ state.EndTime.Month - 1 ],
292
 
                                        state.EndTime.Year.ToString(),
293
 
                                        state.EndTime.Hour,
294
 
                                        state.EndTime.Minute,
295
 
                                        state.EndTime.Second );
296
 
                        log.Debug( "  sync end time: " + info.EndTime );
297
 
                                        
298
 
                        info.MembersAdded = state.Created;
299
 
                        info.MembersUpdated = state.Updated;
300
 
                        info.MembersDeleted = state.Deleted;
301
 
                        info.MembersDisabled = state.Disabled;
302
 
 
303
 
                        log.Debug( "  start processing messages" );
304
 
                        
305
 
                        if ( state.Messages != null )
306
 
                        {
307
 
                                string[] messages = state.Messages;
308
 
                                info.Messages = new string[ messages.Length ];
309
 
                                for( int i = 0; i < messages.Length; i++ )
310
 
                                {
311
 
                                        info.Messages[i] = messages[i];
312
 
                                }
313
 
                                messages = null;
314
 
                        }
315
 
 
316
 
                        state = null;
317
 
                        return info;
318
 
                }
319
 
        
320
 
                /// <summary>
321
 
                /// Method to set the grace period a member is given
322
 
                /// before they are removed from the domain.
323
 
                /// Members are disabled during this grace period.
324
 
                /// Represented in seconds
325
 
                /// </summary>
326
 
                [WebMethod( EnableSession = true )]
327
 
                [SoapDocumentMethod]
328
 
                public void SetDeleteMemberGracePeriod( int Seconds )
329
 
                {
330
 
                        Service.deleteGracePeriod = Seconds;
331
 
                }
332
 
        
333
 
                /// <summary>
334
 
                /// Method to set the synchronization interval for the
335
 
                /// sync engine.  Represented in seconds
336
 
                /// </summary>
337
 
                [WebMethod( EnableSession = true )]
338
 
                [SoapDocumentMethod]
339
 
                public void SetSynchronizationInterval( int Seconds )
340
 
                {
341
 
                        Service.syncInterval = Seconds;
342
 
                }
343
 
        }
344
 
}