public void TestGrant() { SecurityObject role2877 = new SecurityObject(SecurityObjectTypes.Role, "ROLE_2877"); SecurityObject user2877 = new SecurityObject(SecurityObjectTypes.User, "USER_2877"); SecurityObject tableAutoId = new SecurityObject("TESTXPO.AUTOIDCLASS", SecurityTableRights.Select | SecurityTableRights.Update); AdminSecurity( new SecurityStatement(AdminSecurityOperations.Create, role2877), new SecurityStatement(AdminSecurityOperations.Create, user2877), new SecurityStatement(AdminSecurityOperations.GrantTo, role2877, user2877), new SecurityStatement(AdminSecurityOperations.GrantTo, tableAutoId, role2877)); string userGrant = (string)XpoDefault.Session.ExecuteScalar( string.Format("select granted_role from dba_role_privs where grantee = '{0}'", user2877.ObjectName)); int roleGrants = Convert.ToInt32(XpoDefault.Session.ExecuteScalar( string.Format("select count(*) from dba_tab_privs where grantee = '{0}'", role2877.ObjectName))); Assert.AreEqual(role2877.ObjectName, userGrant, "Role is not granted"); Assert.AreEqual(2, roleGrants, "Table privileges are not granted completely"); AdminSecurity( new SecurityStatement(AdminSecurityOperations.RevokeFrom, role2877, user2877), new SecurityStatement(AdminSecurityOperations.RevokeFrom, tableAutoId, role2877)); userGrant = (string)XpoDefault.Session.ExecuteScalar( string.Format("select granted_role from dba_role_privs where grantee = '{0}'", user2877.ObjectName)); roleGrants = Convert.ToInt32(XpoDefault.Session.ExecuteScalar( string.Format("select count(*) from dba_tab_privs where grantee = '{0}'", role2877.ObjectName))); Assert.AreEqual(null, userGrant, "Role is not revoked"); Assert.AreEqual(0, roleGrants, "Table privileges are not revoked completely"); AdminSecurity( new SecurityStatement(AdminSecurityOperations.Drop, role2877), new SecurityStatement(AdminSecurityOperations.Drop, user2877)); }
public void TestSimpleRole() { SecurityObject role2876 = new SecurityObject(SecurityObjectTypes.Role, "ROLE_2876"); AdminSecurity(new SecurityStatement(AdminSecurityOperations.Create, role2876)); string role = (string)XpoDefault.Session.ExecuteScalar( string.Format("select role from dba_roles where role = '{0}'", role2876.ObjectName)); Assert.AreEqual(role2876.ObjectName, role, "Role is not created"); AdminSecurity(new SecurityStatement(AdminSecurityOperations.Drop, role2876)); role = (string)XpoDefault.Session.ExecuteScalar( string.Format("select role from dba_roles where role = '{0}'", role2876.ObjectName)); Assert.AreEqual(null, role, "Role is not droped"); }
/// <summary>Возвращает привилегию таблицы</summary> private bool GetTablePrivilege(string privilegeName, out SecurityObject tablePrivilege) { if (tablesPrivileges == null) { tablesPrivileges = new Dictionary<string, SecurityObject>(); foreach (string tableName in XPDictionaryInformer.Schema.TableNames) { string schema = ComposeSafeSchemaName(tableName); string table = ComposeSafeTableName(tableName); tablesPrivileges[FormatView(schema, table).ToUpper()] = new SecurityObject(tableName, SecurityTableRights.Select); tablesPrivileges[FormatProcedureAdd(schema, table).ToUpper()] = new SecurityObject(tableName, SecurityTableRights.Insert); tablesPrivileges[FormatProcedureEdit(schema, table).ToUpper()] = new SecurityObject(tableName, SecurityTableRights.Update); tablesPrivileges[FormatProcedureDelete(schema, table).ToUpper()] = new SecurityObject(tableName, SecurityTableRights.Delete); } } return tablesPrivileges.TryGetValue(privilegeName, out tablePrivilege); }
/// <summary> /// Конструктор с двумя операндами /// </summary> /// <param name="operation">Операция</param> /// <param name="left">Левый операнд</param> /// <param name="right">Правый операнд</param> public SecurityStatement(AdminSecurityOperations operation, SecurityObject left, SecurityObject right) { this.Operation = operation; this.LeftOperand = left; this.RightOperand = right; }
/// <summary>Конструктор</summary> /// <param name="objects">Объекты безопасности, полученные в результате команд администрирования</param> public SecurityResult(SecurityObject[] objects) { this.Objects = objects; }
public void TestSimpleUser() { SecurityObject user2876 = new SecurityObject(SecurityObjectTypes.User, "USER_2876"); AdminSecurity(new SecurityStatement(AdminSecurityOperations.Create, user2876)); string user = (string)XpoDefault.Session.ExecuteScalar( string.Format("select username from dba_users where username = '******'", user2876.ObjectName)); Assert.AreEqual(user2876.ObjectName, user, "User is not created"); AdminSecurity(new SecurityStatement(AdminSecurityOperations.Drop, user2876)); user = (string)XpoDefault.Session.ExecuteScalar( string.Format("select username from dba_users where username = '******'", user2876.ObjectName)); Assert.AreEqual(null, user, "User is not droped"); }