ArcGIS for Desktop

  • ドキュメント
  • 価格
  • サポート

  • My Profile
  • ヘルプ
  • Sign Out
ArcGIS for Desktop

ArcGIS Online

組織のマッピング プラットフォーム

ArcGIS for Desktop

完全なプロ仕様の GIS

ArcGIS for Server

エンタープライズ GIS

ArcGIS for Developers

位置情報利用アプリの開発ツール

ArcGIS Solutions

各種業界向けの無料のテンプレート マップおよびテンプレート アプリケーション

ArcGIS Marketplace

組織で使えるアプリとデータを取得

  • ドキュメント
  • 価格
  • サポート
Esri
  • サイン イン
user
  • マイ プロフィール
  • サイン アウト

ヘルプ

  • ホーム
  • はじめに
  • マップ
  • 解析
  • データ管理
  • ツール
  • その他...

ロールの作成 (Create Role)

  • サマリ
  • 使用法
  • 構文
  • コードのサンプル
  • 環境
  • ライセンス情報

サマリ

[ロールの作成 (Create Role)] ツールを使用すると、データベース ロールを作成し、ロールへのユーザーの追加およびロールからのユーザーの削除を行うことができます。

使用法

  • このツールは、Oracle、Microsoft SQL Server、または PostgreSQL でのみ使用できます。

  • ロールを指定する際、二重引用符などの区切り文字を使用することはできません。そのため、ロールに含めることができる文字は、区切り文字以外で、データベース管理システムがサポートしている文字のみです。

構文

CreateRole_management (input_database, role, {grant_revoke}, {user_name})
パラメータ説明データ タイプ
input_database

データベースまたはエンタープライズ ジオデータベースへの接続ファイルを指定します。 ArcSDE サービスではなくダイレクト コネクションを使用して、データベース管理者ユーザーとして接続する必要があります。

Workspace
role

作成するデータベース ロールの名前を入力します。ロールがすでに存在している場合、ユーザーに対して追加または削除するロールの名前を入力します。

String
grant_revoke
(オプション)

ユーザーまたはユーザーのリストにロールを付与するのか、またはユーザーまたはユーザーのリストをロールから削除するのかを指定します。

  • GRANT —指定した 1 人以上のユーザーにロールを付与し、ユーザーをロールのメンバーにします
  • REVOKE —指定した 1 人以上のユーザーからロールを取り消し、ユーザーをロールから削除します
String
user_name
(オプション)

ロール メンバーシップを変更するユーザーの名前を入力します。複数のユーザーを指定するには、ユーザー名をカンマで区切って入力します (スペースは挿入しません)。

String

コードのサンプル

CreateRole (ロールの作成) 例 1

Oracle のジオデータベースでデータベース ロール「editors」を作成します。

arcpy.CreateRole_management("C:\\gdbconnections\\gdb_oracle.sde", "editors")
CreateRole (ロールの作成) 例 2

PostgreSQL データベース クラスターでデータベース グループ ロール「drafters」を作成し、それをユーザー「eng1」と「eng2」に付与します。

#Import arcpy module
import arcpy

arcpy.CreateRole_management("C:\\dbconnections\\db_postg.sde", "drafters", "GRANT", "eng1,eng2")
CreateRole (ロールの作成) 例 3

SQL Server データベースで、既存のデータベース ロール「readers」をユーザー「auditor」に付与します。

#Import arcpy module
import arcpy

arcpy.CreateRole_management("C:\\connectionfiles\\db_ss.sde", "readers", "GRANT", "auditor")
CreateRole (ロールの作成) 例 4

データベース ユーザー「intern1」、「intern2」、「intern3」からデータベース ロール「creators」を取り消します。

#Import arcpy module
import arcpy

arcpy.CreateRole_management("D:\\myconnectionfiles\\mygdb.sde", "creators", "REVOKE", "intern1,intern2,intern3")
CreateRole (ロールの作成) 例 5

次のスタンドアロン スクリプトにより、オプションを使用して各サイトに固有の情報を提供できます。

  • input_database として使用するデータベース接続ファイルを作成します。
  • データベース ロールを作成します。
  • ユーザーを新しいロールに追加します。

"""
Name: create_database_role.py
Description: Provide connection information to a database user.
Type create_database_role.py -h or create_database_role.py --help for usage
Author: Esri
"""

# Import system modules
import arcpy, os, optparse, sys

# Define usage and version
parser = optparse.OptionParser(usage = "usage: %prog [Options]", version="%prog 1.0 for 10.1 release")

#Define help and options
parser.add_option ("--DBMS", dest="Database_type", type="choice", choices=['SQLSERVER', 'ORACLE', 'POSTGRESQL', ''], default="", help="Type of enterprise DBMS:  SQLSERVER, ORACLE, or POSTGRESQL.")                   
parser.add_option ("-i", dest="Instance", type="string", default="", help="DBMS instance name")
parser.add_option ("-D", dest="Database", type="string", default="none", help="Database name:  Not required for Oracle")
parser.add_option ("--auth", dest="Account_authentication", type ="choice", choices=['DATABASE_AUTH', 'OPERATING_SYSTEM_AUTH'], default='DATABASE_AUTH', help="Authentication type options (case-sensitive):  DATABASE_AUTH, OPERATING_SYSTEM_AUTH.  Default=DATABASE_AUTH")
parser.add_option ("-U", dest="Dbms_admin", type="string", default="", help="DBMS administrator user")
parser.add_option ("-P", dest="Dbms_admin_pwd", type="string", default="", help="DBMS administrator password")
parser.add_option ("-o", dest="operation", type ="choice", choices=['GRANT', 'REVOKE'], default='GRANT', help="Specify which operation to perform: grant to or revoke from the user(s). Options (case-sensitive):  GRANT, REVOKE.  Default=GRANT")
parser.add_option ("-r", dest="role", type="string", default="", help="role to be granted to the user")
parser.add_option ("-u", dest="userlist", type="string", default="", help="List of users to grant to or revoke from, separated by comma.")
# Check if value entered for option
try:
	(options, args) = parser.parse_args()

	#Check if no system arguments (options) entered
	if len(sys.argv) == 1:
		print "%s: error: %s\n" % (sys.argv[0], "No command options given")
		parser.print_help()
		sys.exit(3)

	#Usage parameters for spatial database connection
	database_type = options.Database_type.upper()
	instance = options.Instance
	database = options.Database.lower()	
	account_authentication = options.Account_authentication.upper()
	dbms_admin = options.Dbms_admin
	dbms_admin_pwd = options.Dbms_admin_pwd
	userlist = options.userlist
	role = options.role
	operation = options.operation

	
	if (database_type == "SQLSERVER"):
		database_type = "SQL_SERVER"
	
	if( database_type ==""):	
		print " \n%s: error: \n%s\n" % (sys.argv[0], "DBMS type (--DBMS) must be specified.")
		parser.print_help()
		sys.exit(3)		
		
	if (role == ""):
		print " \n%s: error: \n%s\n" % (sys.argv[0], "Role name (-r) must be specified.")
		parser.print_help()
		sys.exit(3)			
	
	if(database_type == "SQL_SERVER"):
		if( account_authentication == "DATABASE_AUTH" and dbms_admin == ""):
			print "\n%s: error: %s\n" % (sys.argv[0], "DBMS administrator must be specified with database authentication")
			sys.exit(3)
		if( account_authentication == "OPERATING_SYSTEM_AUTH" and dbms_admin != ""):
			print "\nWarning: %s\n" % ("Ignoring DBMS administrator specified when using operating system authentication...")	
	else:				
		if( dbms_admin == ""):
			print "\n%s: error: %s\n" % (sys.argv[0], "DBMS administrator must be specified!")
			sys.exit(3)

	# Get the current product license
	product_license=arcpy.ProductInfo()
	
	# Checks required license level
	if product_license.upper() == "ARCVIEW" or product_license.upper() == 'ENGINE':
		print "\n" + product_license + " license found!" + " Creating a role in an enterprise geodatabase or database requires an ArcGIS for Desktop Standard or Advanced, ArcGIS Engine with the Geodatabase Update extension, or ArcGIS for Server license."
		sys.exit("Re-authorize ArcGIS before creating enterprise geodatabase.")
	else:
		print "\n" + product_license + " license available!  Continuing to create..."
		arcpy.AddMessage("+++++++++")

	# Local variables
	instance_temp = instance.replace("\\","_")
	instance_temp = instance_temp.replace("/","_")
	instance_temp = instance_temp.replace(":","_")
	Conn_File_NameT = instance_temp + "_" + database + "_" + dbms_admin   

	if os.environ.get("TEMP") == None:
		temp = "c:\\temp"	
	else:
		temp = os.environ.get("TEMP")
	
	if os.environ.get("TMP") == None:
		temp = "/usr/tmp"		
	else:
		temp = os.environ.get("TMP")  

	Connection_File_Name = Conn_File_NameT + ".sde"
	Connection_File_Name_full_path = temp + os.sep + Conn_File_NameT + ".sde"
	
	# Check for the .sde file and delete it if present
	arcpy.env.overwriteOutput=True
	if os.path.exists(Connection_File_Name_full_path):
		os.remove(Connection_File_Name_full_path)

	try:
		print "\nCreating Database Connection File...\n"	
		# Process: Create Database Connection File...
		# Usage:  out_file_location, out_file_name, DBMS_TYPE, instnace, account_authentication, username, password, database, save_username_password(must be true)
		arcpy.CreateDatabaseConnection_management(out_folder_path=temp, out_name=Connection_File_Name, database_platform=database_type, instance=instance, database=database, account_authentication=account_authentication, username=dbms_admin, password=dbms_admin_pwd, save_user_pass="TRUE")
	        for i in range(arcpy.GetMessageCount()):
			if "000565" in arcpy.GetMessage(i):   #Check if database connection was successful
				arcpy.AddReturnMessage(i)
				arcpy.AddMessage("\n+++++++++")
				arcpy.AddMessage("Exiting!!")
				arcpy.AddMessage("+++++++++\n")
				sys.exit(3)            
			else:
				arcpy.AddReturnMessage(i)
				arcpy.AddMessage("+++++++++\n")

		print "Creating database role...\n"
		arcpy.CreateRole_management(input_database=Connection_File_Name_full_path, grant_revoke=operation, role=role,  user_name=userlist)
		for i in range(arcpy.GetMessageCount()):
			arcpy.AddReturnMessage(i)
		arcpy.AddMessage("+++++++++\n")
	except:
		for i in range(arcpy.GetMessageCount()):
			arcpy.AddReturnMessage(i)
			
#Check if no value entered for option	
except SystemExit as e:
	if e.code == 2:
		parser.usage = ""
		print "\n"
		parser.print_help()   
		parser.exit(2)

環境

  • 現在のワークスペース

ライセンス情報

  • ArcGIS for Desktop Basic: ×
  • ArcGIS for Desktop Standard: ○
  • ArcGIS for Desktop Advanced: ○

関連トピック

  • ジオデータベース管理ツールセットの概要
  • データベース ユーザーの作成 (Create Database User)
このトピックへのフィードバック

ArcGIS for Desktop

  • ホーム
  • ドキュメント
  • 価格
  • サポート

ArcGIS プラットフォーム

  • ArcGIS Online
  • ArcGIS for Desktop
  • ArcGIS for Server
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

Esri について

  • 会社概要
  • 採用情報
  • スタッフ ブログ
  • ユーザ カンファレンス
  • デベロッパ サミット
Esri
© Copyright 2016 Environmental Systems Research Institute, Inc. | プライバシー | リーガル