2 * Firebird ADO.NET Data provider for .NET and Mono
4 * The contents of this file are subject to the Initial
5 * Developer's Public License Version 1.0 (the "License");
6 * you may not use this file except in compliance with the
7 * License. You may obtain a copy of the License at
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
10 * Software distributed under the License is distributed on
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
12 * express or implied. See the License for the specific
13 * language governing rights and limitations under the License.
15 * Copyright (c) 2002, 2004 Carlos Guzman Alvarez
16 * All Rights Reserved.
20 using FirebirdSql.Data.Common;
22 namespace FirebirdSql.Data.Firebird.Services
24 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/overview/*'/>
25 public sealed class FbSecurity : FbService
29 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/property[@name="UsersDbPath"]/*'/>
30 public string UsersDbPath
34 byte[] buffer = this.QueryService(
35 new byte[] {IscCodes.isc_info_svc_user_dbpath});
36 System.Collections.ArrayList info = this.ParseQueryInfo(buffer);
38 return info.Count != 0 ? (string)info[0] : null;
46 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/constructor[@name="FbSecurity"]/*'/>
47 public FbSecurity() : base()
55 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/method[@name="AddUser(FbUserData)"]/*'/>
56 public void AddUser(FbUserData user)
58 if (user.UserName != null && user.UserName.Length == 0)
60 throw new InvalidOperationException("Invalid user name.");
62 if (user.UserPassword != null && user.UserPassword.Length == 0)
64 throw new InvalidOperationException("Invalid user password.");
68 this.StartSpb = this.CreateParameterBuffer();
70 this.StartSpb.Append(IscCodes.isc_action_svc_add_user);
72 this.StartSpb.Append(IscCodes.isc_spb_sec_username, user.UserName);
73 this.StartSpb.Append(IscCodes.isc_spb_sec_password, user.UserPassword);
75 if (user.FirstName != null && user.FirstName.Length > 0)
77 this.StartSpb.Append(IscCodes.isc_spb_sec_firstname, user.FirstName);
80 if (user.MiddleName != null && user.MiddleName.Length > 0)
82 this.StartSpb.Append(IscCodes.isc_spb_sec_middlename, user.MiddleName);
85 if (user.LastName != null && user.LastName.Length > 0)
87 this.StartSpb.Append(IscCodes.isc_spb_sec_lastname, user.LastName);
92 this.StartSpb.Append(IscCodes.isc_spb_sec_userid, user.UserID);
95 if (user.GroupID != 0)
97 this.StartSpb.Append(IscCodes.isc_spb_sec_groupid, user.GroupID);
100 if (user.GroupName != null && user.GroupName.Length > 0)
102 this.StartSpb.Append(IscCodes.isc_spb_sec_groupname, user.GroupName);
105 if (user.RoleName != null && user.RoleName.Length > 0)
107 this.StartSpb.Append(IscCodes.isc_spb_sql_role_name, user.RoleName);
116 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/method[@name="DeleteUser(FbUserData)"]/*'/>
117 public void DeleteUser(FbUserData user)
119 if (user.UserName != null && user.UserName.Length == 0)
121 throw new InvalidOperationException("Invalid user name.");
125 this.StartSpb = this.CreateParameterBuffer();
127 this.StartSpb.Append(IscCodes.isc_action_svc_delete_user);
129 this.StartSpb.Append(IscCodes.isc_spb_sec_username, user.UserName);
131 if (user.RoleName != null && user.RoleName.Length > 0)
133 this.StartSpb.Append(IscCodes.isc_spb_sql_role_name, user.RoleName);
142 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/method[@name="ModifyUser(FbUserData)"]/*'/>
143 public void ModifyUser(FbUserData user)
145 if (user.UserName != null && user.UserName.Length == 0)
147 throw new InvalidOperationException("Invalid user name.");
149 if (user.UserPassword != null && user.UserPassword.Length == 0)
151 throw new InvalidOperationException("Invalid user password.");
155 this.StartSpb = this.CreateParameterBuffer();
157 this.StartSpb.Append(IscCodes.isc_action_svc_modify_user);
158 this.StartSpb.Append(IscCodes.isc_spb_sec_username, user.UserName);
160 if (user.UserPassword != null && user.UserPassword.Length > 0)
162 this.StartSpb.Append(IscCodes.isc_spb_sec_password, user.UserPassword);
165 if (user.FirstName != null && user.FirstName.Length > 0)
167 this.StartSpb.Append(IscCodes.isc_spb_sec_firstname, user.FirstName);
170 if (user.MiddleName != null && user.MiddleName.Length > 0)
172 this.StartSpb.Append(IscCodes.isc_spb_sec_middlename, user.MiddleName);
175 if (user.LastName != null && user.LastName.Length > 0)
177 this.StartSpb.Append(IscCodes.isc_spb_sec_lastname, user.LastName);
180 this.StartSpb.Append(IscCodes.isc_spb_sec_userid, user.UserID);
181 this.StartSpb.Append(IscCodes.isc_spb_sec_groupid, user.GroupID);
183 if (user.GroupName != null && user.GroupName.Length > 0)
185 this.StartSpb.Append(IscCodes.isc_spb_sec_groupname, user.GroupName);
188 if (user.RoleName != null && user.RoleName.Length > 0)
190 this.StartSpb.Append(IscCodes.isc_spb_sql_role_name, user.RoleName);
199 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/method[@name="DisplayUser(System.String)"]/*'/>
200 public FbUserData DisplayUser(string userName)
203 this.StartSpb = this.CreateParameterBuffer();
205 this.StartSpb.Append(IscCodes.isc_action_svc_display_user);
206 this.StartSpb.Append(IscCodes.isc_spb_sec_username, userName);
211 byte[] buffer = this.QueryService(
212 new byte[] {IscCodes.isc_info_svc_get_users});
214 System.Collections.ArrayList info = base.ParseQueryInfo(buffer);
223 FbUserData[] users = (FbUserData[])info[0];
225 return (users != null && users.Length > 0) ? users[0] : null;
228 /// <include file='Doc/en_EN/FbSecurity.xml' path='doc/class[@name="FbSecurity"]/method[@name="DisplayUsers"]/*'/>
229 public FbUserData[] DisplayUsers()
232 this.StartSpb = this.CreateParameterBuffer();
234 this.StartSpb.Append(IscCodes.isc_action_svc_display_user);
239 byte[] buffer = this.QueryService(
240 new byte[] {IscCodes.isc_info_svc_get_users});
242 System.Collections.ArrayList info = base.ParseQueryInfo(buffer);
251 return (FbUserData[])info[0];