3
我使用C#4中的ADO.NET來設置組件的測試環境。何時在Oracle 10g中爲用戶啓用角色?
我執行下列SQL以SYSDBA:
new[]
{
"create user \"{0}\" identified externally default tablespace USER_DATA temporary tablespace TEMP profile DEFAULT"
.FormatWith(Config.QualifiedUserName),
"create role {0}"
.FormatWith(Config.RoleName),
"grant {0} to \"{1}\""
.FormatWith(Config.RoleName, Config.QualifiedUserName),
"insert into doc.application(id, name) values({0}, '{1}')"
.FormatWith(Config.AppId, Config.AppName),
"insert into doc.appl_role(application, role, description) values({0}, '{1}', '{2}')"
.FormatWith(Config.AppId, Config.RoleName, Config.RoleDescription),
"create table {0}.{1} (ID number primary key, VERSION number, NAME varchar(100))"
.FormatWith(Config.TestSchema, Config.TestTable),
"insert into {0}.{1} (ID, VERSION, NAME) values ('{2}', '{3}', '{4}')"
.FormatWith(Config.TestSchema, Config.TestTable, Config.TestRowId, 1, Config.TestRowName),
"grant select, insert, update, delete on {0}.{1} to {2}"
.FormatWith(Config.TestSchema, Config.TestTable, Config.RoleName),
"grant create session to \"{0}\""
.FormatWith(Config.QualifiedUserName)
}
和配置類看起來像這樣:
public struct Config
{
public const Int32 TestRowId = 1;
public const Int32 AppId = 99999;
public const String AppName = "OraceUtils";
public const String RoleName = "ORACLE_UTILS_BASE";
public static readonly String RoleDescription = "For testing {0}".FormatWith(AppName);
public static readonly String QualifiedUserName = @"{0}\{1}".FormatWith(Domain, UserName);
public const String DataSource = "TESTDB";
public const String Domain = "BI";
public const String UserName = "ORACLE_TEST_USER";
public const String UserPassword = [for my eyes only];
public const String TestSchema = "CI";
public const String TestTable = "ROLE_PROVIDER_TEST_TABLE";
public const String TestRowName = "Arne And";
}
從我讀過,只是授予角色給用戶沒有按」啓用它。但是,在執行上面的SQL之後,用戶BI \ ORACLE_TEST_USER可以很好地使用表ROLE_PROVIDER_TEST_TABLE。 ORACLE_UTILS_BASE角色也在SESSION_ROLES中顯示。
如果之後發出「SET ROLES」,上述用戶將無法訪問該表。
我認爲這是另一種方式,即用戶將不會訪問,直到她發出「SET ROLES ORACLE_UTILS_BASE,[任何其他角色]」。
+1並接受。這解釋了*很多*。謝謝! – 2010-06-24 14:06:47