~ifolder-dev/simias/trunk-packaging

« back to all changes in this revision

Viewing changes to src/webservices/.svn/text-base/UserPolicy.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: Rob 
22
 
|***************************************************************************/
23
 
 
24
 
using System;
25
 
using System.Collections;
26
 
 
27
 
using Simias;
28
 
using Simias.Storage;
29
 
using Simias.Policy;
30
 
 
31
 
namespace iFolder.WebService
32
 
{
33
 
        /// <summary>
34
 
        /// iFolder User Policy
35
 
        /// </summary>
36
 
        [Serializable]
37
 
        public class UserPolicy 
38
 
        {
39
 
                 private static readonly ISimiasLog log = SimiasLogManager.GetLogger(typeof(Member));
40
 
                /// <summary>
41
 
                /// The User ID
42
 
                /// </summary>
43
 
                public string UserID;
44
 
 
45
 
                /// <summary>
46
 
                /// Is the User's Login Enabled?
47
 
                /// </summary>
48
 
                public bool LoginEnabled;
49
 
 
50
 
        /// <summary>
51
 
        /// The User Disk Space Limit
52
 
        /// </summary>
53
 
        public long SpaceLimit;
54
 
 
55
 
// Added by ramesh
56
 
                public int EncryptionStatus;
57
 
        
58
 
                /// <summary>
59
 
                /// The Effective User Disk Space Limit
60
 
                /// </summary>
61
 
                public long SpaceLimitEffective;
62
 
 
63
 
                /// <summary>
64
 
                /// The Maximum File Size Limit
65
 
                /// </summary>
66
 
                public long FileSizeLimit;
67
 
 
68
 
                /// <summary>
69
 
                /// The Effective Maximum File Size Limit
70
 
                /// </summary>
71
 
                public long FileSizeLimitEffective;
72
 
 
73
 
                /// <summary>
74
 
                /// The User Disk Space Used
75
 
                /// </summary>
76
 
                public long SpaceUsed;
77
 
 
78
 
                /// <summary>
79
 
                /// The User Disk Space Available
80
 
                /// </summary>
81
 
                public long SpaceAvailable;
82
 
 
83
 
                /// <summary>
84
 
                /// The User Sync Interval
85
 
                /// </summary>
86
 
                public int SyncInterval;
87
 
                
88
 
                /// <summary>
89
 
                /// The Effect User Sync Interval
90
 
                /// </summary>
91
 
                public int SyncIntervalEffective;
92
 
 
93
 
                /// <summary>
94
 
                /// The File Types to Be Included
95
 
                /// </summary>
96
 
                public string[] FileTypesIncludes;
97
 
 
98
 
                /// <summary>
99
 
                /// The File Types to Be Included
100
 
                /// </summary>
101
 
                public string[] FileTypesIncludesEffective;
102
 
 
103
 
                /// <summary>
104
 
                /// The File Types to Be Excluded
105
 
                /// </summary>
106
 
                public string[] FileTypesExcludes;
107
 
 
108
 
                /// <summary>
109
 
                /// The File Types to Be Excluded
110
 
                /// </summary>
111
 
                public string[] FileTypesExcludesEffective;
112
 
 
113
 
                /// <summary>
114
 
                /// Constructor
115
 
                /// </summary>
116
 
                public UserPolicy()
117
 
                {
118
 
                }
119
 
 
120
 
                /// <summary>
121
 
                /// Get the User Policy
122
 
                /// </summary>
123
 
                /// <param name="userID">The User ID</param>
124
 
                /// <returns>The UserPolicy Object</returns>
125
 
                public static UserPolicy GetPolicy(string userID)
126
 
                {
127
 
                        UserPolicy props = new UserPolicy();
128
 
 
129
 
                        props.UserID = userID;
130
 
 
131
 
                        Store store = Store.GetStore();
132
 
 
133
 
                        Domain domain = store.GetDomain(store.DefaultDomain);
134
 
                        
135
 
                        Member member = domain.GetMemberByID(userID);
136
 
                        
137
 
                        if (member == null) throw new UserDoesNotExistException(userID);
138
 
 
139
 
            props.LoginEnabled = !(domain.IsLoginDisabled(userID));
140
 
 
141
 
                        // disk space
142
 
                        DiskSpaceQuota quota = DiskSpaceQuota.Get(member);
143
 
                        
144
 
                        props.SpaceLimitEffective = quota.Limit;
145
 
                        props.SpaceUsed = quota.UsedSpace;
146
 
                        props.SpaceAvailable = quota.AvailableSpace;
147
 
 
148
 
                        props.SpaceLimit = DiskSpaceQuota.GetLimit(member);
149
 
                        props.EncryptionStatus = Simias.Policy.SecurityState.GetStatus( member );
150
 
 
151
 
                        // file size
152
 
                        props.FileSizeLimit = FileSizeFilter.GetLimit(member);
153
 
                        props.FileSizeLimitEffective = FileSizeFilter.Get(member).Limit;
154
 
 
155
 
                        // sync interval
156
 
                        props.SyncInterval = Simias.Policy.SyncInterval.GetInterval(member);
157
 
                        props.SyncIntervalEffective = Simias.Policy.SyncInterval.Get(member).Interval;
158
 
 
159
 
                        // file types
160
 
                        SystemPolicy.SplitFileTypes(FileTypeFilter.GetPatterns(member),
161
 
                                out props.FileTypesIncludes, out props.FileTypesExcludes);
162
 
 
163
 
                        // file types effective
164
 
                        SystemPolicy.SplitFileTypes(FileTypeFilter.Get(member).FilterList,
165
 
                                out props.FileTypesIncludesEffective, out props.FileTypesExcludesEffective);
166
 
 
167
 
                        return props;
168
 
                }
169
 
 
170
 
                /// <summary>
171
 
                /// Set the User Policy
172
 
                /// </summary>
173
 
                /// <param name="props">The UserPolicy Object</param>
174
 
                public static void SetPolicy(UserPolicy props)
175
 
                {
176
 
                        Store store = Store.GetStore();
177
 
 
178
 
                        Domain domain = store.GetDomain(store.DefaultDomain);
179
 
                        
180
 
                        Member member = domain.GetMemberByID(props.UserID);
181
 
 
182
 
                        if (member == null) throw new UserDoesNotExistException(props.UserID);
183
 
 
184
 
                        if(props.LoginEnabled == true)
185
 
                        {
186
 
                                domain.SetLoginDisabled(props.UserID, false);
187
 
                        }
188
 
                        else
189
 
                        {
190
 
                                domain.SetLoginDisabled(props.UserID, true);
191
 
                        }
192
 
 
193
 
 
194
 
// Added by Ramesh
195
 
                        Simias.Policy.SecurityState.Create( member, props.EncryptionStatus );
196
 
 
197
 
                        // disk space
198
 
                        if (props.SpaceLimit >= 0)
199
 
                        {
200
 
                                DiskSpaceQuota.Set(member, props.SpaceLimit);
201
 
                        }
202
 
 
203
 
                        // file size
204
 
                        if (props.FileSizeLimit >= 0)
205
 
                        {
206
 
                                FileSizeFilter.Set(member, props.FileSizeLimit);
207
 
                        }
208
 
 
209
 
                        // sync interval
210
 
                        if (props.SyncInterval >= 0)
211
 
                        {
212
 
                                Simias.Policy.SyncInterval.Set(member, props.SyncInterval);
213
 
                        }
214
 
 
215
 
                        // file types
216
 
                        if ((props.FileTypesExcludes != null) || (props.FileTypesIncludes != null))
217
 
                        {
218
 
                                FileTypeFilter.Set(member, SystemPolicy.CombineFileTypes(
219
 
                                        props.FileTypesIncludes, props.FileTypesExcludes));
220
 
                        }
221
 
                }
222
 
        }
223
 
}