ROLEサービスを利用して権限をチェックするためには RESTful APIを呼び出すか、クライアントSDKを利用する必要があります。
RESTful APIとクライアントSDKを使用するには、アプリケーションキーと秘密鍵が必要です。 [CONSOLE]の右上で発行されたキー情報を確認できます。
RESTful APIを簡単に呼び出すためのROLE専用クライアントSDKです。 独自のキャッシュ機能を持っているため、より効率的にROLEサービスを利用できます。 現在はJAVA言語のみサポートしています。
JDK 11
バージョン以上の環境
JAVAクライアントSDKを使用するにはpom.xmlにmaven repository及びdepencencyを設定する必要があります。
[Maven Repository] Maven Central Repositoryに保存されているので別途設定は必要ありません。 もし、他のリポジトリを使う場合やMaven Centralが参照できない環境では次のように設定。
<repositories>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
[Maven Dependency]
<dependencies>
<dependency>
<groupId>com.nhncloud.role</groupId>
<artifactId>nhncloud-role-sdk</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
JAVAクライアントSDKを使用するには、まずRoleClientFactoryオブジェクトを利用してRoleClientオブジェクトのインスタンスを作成する必要があります。 RoleClientオブジェクトを作成したら、そのオブジェクトで提供するメソッドを呼び出して様々な作業を処理します。
[RoleConfig]
Key | Type | Required | Description |
---|---|---|---|
appKey | String | Yes | サーバーから発行されたアプリケーションキー |
secretKey | String | Yes | サーバーから発行された秘密鍵 |
domain | String | No | ドメインアドレス デフォルトで設定された値を使用し、別途設定する必要はありません。 |
connectTimeout | Integer | No | 接続のタイムアウトを設定することができ、時間単位はミリ秒。 デフォルト値はokHttpのデフォルト値である10秒。 |
readTimeout | Integer | No | Readタイムアウトを設定できます。単位はミリ秒で、デフォルトはokHttpのデフォルトである10秒です。 |
String appKey = "appKey";
String secretKey = "secretKey";
// RoleClientオブジェクトを作成する正しい方法
// ドメインは別途設定する必要はありません。
RoleClient client = RoleClientFactory.getClient(RoleConfig.builder()
.appKey(appKey)
.secretKey(secretKey)
.connectTimeout(30_000)
.readTimeout(60_000)
.build());
// 以下のように直接コンストラクタを呼び出してはいけません。
RoleClient client = new RoleClient(RoleConfig.builder()
.appKey(appKey)
.secretKey(secretKey)
.connectTimeout(30_000)
.readTimeout(60_000)
.build());
RoleClientのコンストラクタを直接呼び出さないように注意してください。
SDK共通機能で使う部分
[Pageable]
Key | Type | Required | Description |
---|---|---|---|
page | Integer | No | ページ番号 |
itemsPerPage | Integer | No | リストごとに照会されるアイテムの数 |
sort | List<String> | No | データソート基準 |
[Page]
Key | Type | Required | Description |
---|---|---|---|
totalItems | Integer | Yes | 全体数 |
items | List<T> | Yes | 照会されたリスト |
ユーザー情報の登録、照会、修正、削除機能及びユーザーロールの変更履歴の照会
[User]
Key | Type | Required | Description |
---|---|---|---|
userId | String | Yes | ユーザーID |
description | String | No | 説明 |
regYmdt | OffsetDateTime | No | ユーザー作成日時。戻り時に設定される。 |
roleCounts | List<UserRoleCount> | No | ユーザーに割り当てられたロール数 |
roleRelations | List<UserRoleRelation> | No | 関連ロール |
[UserRoleCount]
Key | Type | Required | Description |
---|---|---|---|
scopeId | String | No | スコープID |
roleCount | Integer | No | スコープID別のロール数 |
[UserRoleRelation]
Key | Type | Required | Description |
---|---|---|---|
scopeId | String | Yes | 適用対象ID |
roleId | String | Yes | ロールID |
roleApplyPolicyCode | RoleApplyPolicyCode | No | ロール使用有無: ALLOW, DENY |
conditions | List<Condition> | No | ロール条件属性 |
regYmdt | Date | Yes | 作成日時 |
[Condition]
Key | Type | Required | Description |
---|---|---|---|
attributeId | String | Yes | 条件属性ID |
attributeOperatorType | Required | Yes | 条件属性演算子タイプ |
attributeValues | List<String> | No | 条件属性値 |
User user = User.builder()
.userId("")
.description("")
.roleRelations(List.of(UserRoleRelation.builder()
.roleId("")
.scopeId("")
.roleApplyPolicyCode(RoleApplyPolicyCode.ALLOW)
.conditions(List.of(Condition.builder()
.attributeId("")
.attributeOperatorTypeCode(AttributeOperatorTypeCode.STRING)
.attributeValues(List.of(""))))
.build()))
.build();
client.createUsers(List.of(user));
[GetUserRequest]
Key | Type | Required | Description |
---|---|---|---|
userId | String | Yes | ユーザーID |
searchRoleOptionCode | SearchRoleOptionCode | No | 関連関係権限を含めて検索するかどうか: DIRECT_ROLE, INDIRECT_ROLE |
roleIds | List<String> | No | ロールIDリスト |
scopeIds | List<String> | No | 適用対象IDリスト |
GetUserRequest request = GetUserRequest.builder()
.userId("")
.build();
User user = client.getUser(request);
⚠️レスポンス時に使用されるモデルはCommon
を参照
[GetUserRequest]
Key | Type | Required | Description |
---|---|---|---|
userIds | List<String> | No | ユーザーIDリスト(完全一致) |
userIdPreLike | String | No | ユーザーID(前方一致) |
scopeIds | List<String> | No | スコープIDリスト(完全一致) |
scopeIdPreLike | String | No | スコープID(前方一致) |
roleIds | List<String> | No | ロールIDリスト(完全一致) |
roleIdPreLike | String | No | ロールID(前方一致) |
descriptionLike | String | No | ユーザー説明(部分一致) |
searchRoleOptionCode | SearchRoleOptionCode | No | アクセス可能なロールリストの検索方法 |
needRoleRelations | Boolean | No | レスポンス時にロール関連関係を含めるかどうか(デフォルト値: true) |
needRoleTags | Boolean | No | レスポンス時にロール関連関係を含める時、ロールタグを含めるかどうか(デフォルト値: false) |
needRoleCount | Boolean | No | レスポンス時にユーザーが持っているロール数を含めるかどうか(デフォルト値: false) |
GetUserRequest request = GetUsersRequest.builder()
.userId("")
.build();
Pageable pageable = Pageable.builder()
.page(1)
.itemsPerPage(10)
.build();
Page<User> user = client.getUsers(request, pageable);
[PutUserRequest]
Key | Type | Required | Description |
---|---|---|---|
user | User | Yes | ⚠️リクエスト時に使用されるモデルはUser を参照 |
createUserIfNotExist | Boolean | No | リクエスト時にユーザーが存在しない場合、作成するかどうか |
User user = User.builder()
.userId("")
.description("")
.roleRelations(List.of(UserRoleRelation.builder()
.roleId("")
.scopeId("")
.roleApplyPolicyCode(RoleApplyPolicyCode.ALLOW)
.conditions(List.of(Condition.builder()
.attributeId("")
.attributeOperatorTypeCode(AttributeOperatorTypeCode.STRING)
.attributeValues(List.of(""))))
.build()))
.build();
PutUserRequest request = PutUserRequest.builder()
.user(user)
.createUserIfNotExist(true)
.build();
client.updateUser(request);
String userId = "";
client.deleteUser(userId);
[DeleteUsersRequest]
Key | Type | Required | Description |
---|---|---|---|
userIds | Set<String> | Yes | ユーザーIDリスト |
DeleteUsersRequest request = DeleteUsersRequest.builder()
.userIds(Set.of(""))
.build();
client.deleteUsers(request);
[GetUserRoleHistoriesRequest]
Key | Type | Required | Description |
---|---|---|---|
userId | String | No | ユーザーID |
roleId | String | No | ロールID |
scopeId | String | No | 適用対象ID |
fromDateTime | OffsetDateTime | No | 変更開始日時 |
toDateTime | OffsetDateTime | No | 変更終了日時 |
GetUserRoleHistoriesRequest request = GetUserRoleHistoriesRequest.builder()
.userId("")
.roleId("")
.build();
Page<UserRoleHistory> userRoleHistories = client.getUserRoleHistories(request, Pageable.builder()
.page(0)
.itemsPerPage(10)
.build());
[UserRoleHistory]
Key | Type | Required | Description |
---|---|---|---|
userHistorySeq | long | Yes | 順番 |
userId | String | Yes | ユーザーID |
roleId | String | No | ロールID |
scopeId | String | No | 適用対象ID |
roleApplyPolicyCode | RoleApplyPolicyCode | No | ロール使用有無: ALLOW, DENY |
conditions | List<ConditionBundle> | No | ロール条件属性 |
command | UserRoleHistoryCommandCode | Yes | コマンド |
executionTime | OffsetDateTime | Yes | 変更日時 |
operatorUuid | String | Yes | 作業者UUID |
[PutUserScopeRequest]
Key | Type | Required | Description |
---|---|---|---|
userId | String | Yes | ユーザーID |
scopeId | String | Yes | 適用対象ID |
description | String | No | 説明 |
createUserIfNotExist | Boolean | No | リクエスト時にユーザーが存在しない場合、作成するかどうか |
roleRelations | List<UserRoleRelation> | No | 関連ロール |
PutUserRequest request = PutUserScopeRequest.builder()
.userId("")
.description("")
.createUserIfNotExist(true)
.roleRelations(List.of(UserRoleRelation.builder()
.roleId("")
.scopeId("")
.roleApplyPolicyCode(RoleApplyPolicyCode.ALLOW)
.conditions(List.of(Condition.builder()
.attributeId("")
.attributeOperatorTypeCode(AttributeOperatorTypeCode.STRING)
.attributeValues(List.of(""))))
.build()))
.build();
client.updateUserInScope(request);
Operation情報登録、照会、修正、削除
[Operation]
Key | Type | Required | Description |
---|---|---|---|
operationId | String | Yes | オペレーションID |
description | String | No | 説明 |
Operation operation = Operation.builder()
.operationId("")
.description("")
.build();
client.createOperation(operation);
⚠️レスポンス時に使われるモデルはModel
を参照
String operationId = "";
Operation operation = client.getOperation(operationId);
⚠️レスポンス時に使われるモデルはCommon
を参照
[GetOperationsRequest]
Key | Type | Required | Description |
---|---|---|---|
operationIds | List<String> | No | オペレーションIDリスト |
operationIdPreLike | String | No | オペレーションID(前方一致) |
descriptionLike | String | No | 説明(部分一致) |
GetOperationsRequest request = GetOperationsRequest.builder()
.operationId("")
.build();
Pageable pageable = Pageable.builder()
.page(1)
.itemsPerPage(10)
.build();
Page<Operation> operations = client.getOperations(request, pageable);
⚠️レスポンス時に使われるモデルはOperation
を参照
Operation operation = Operation.builder()
.operationId("")
.description("")
.build();
client.updateOperation(operation);
String operationId = "";
client.deleteOperation(userId);
[DeleteOperationsRequest]
Key | Type | Required | Description |
---|---|---|---|
operationIds | Set<String> | Yes | オペレーションIDリスト |
DeleteOperationsRequest request = DeleteOperationsRequest.builder()
.operationIds(Set.of(""))
.build();
client.deleteOperations(request);
属性情報の登録、照会、修正、削除
[Attribute]
Key | Type | Required | Description |
---|---|---|---|
attributeId | String | Yes | 条件属性ID |
attributeName | String | No | 条件属性名 |
description | String | No | 説明 |
attributeDataType | AttributeDataType | Yes | 条件属性データタイプ |
attributeCreationType | AttributeCreationType | No | 条件属性作成タイプ |
attributeTagIds | List<String> | No | 条件属性タグリスト |
attributeRoleRelationIds | List<String> | No | 関連ロールリスト |
Attribute attribute = Attribute.builder()
.attributeId("")
.attributeName("")
.description("")
.attributeDataTypeCode(AttributeDataTypeCode.STRING)
.attributeTagIds(List.of())
.attributeRoleRelationIds(List.of())
.build();
client.createAttribute(attribute);
String attributeId = "";
Attribute attribute = client.getAttribute(attributeId);
⚠️ レスポンス時に使われるモデルはCommon
を参照
[GetAttributesRequest]
Key | Type | Required | Description |
---|---|---|---|
attributeIds | List<String> | No | 条件属性IDリスト |
attributeIdPreLike | String | No | 条件属性ID(前方一致) |
roleIds | List<String> | No | ロールIDリスト |
roleIdPreLike | String | No | ロールID(前方一致) |
attributeTagIds | List<String> | No | 条件属性IDリスト |
descriptionLike | String | No | 説明(部分一致) |
attributeDataType | AttributeDataType | No | 条件属性データタイプ |
GetAttributesRequest request = GetAttributesRequest.builder()
.attributeIds(List.Of())
.roleIds(List.Of())
.attributeTagIds(List.Of())
.attributeDataTypeCode(AttributeDataTypeCode.STRING)
.build();
Pageable pageable = Pageable.builder()
.page(1)
.itemsPerPage(10)
.build();
Page<GetAttributeResponse> attributes = client.getAttributes(request, pageable);
[GetAttributeResponse]
Key | Type | Required | Description |
---|---|---|---|
attribute | Attribute | Yes | 条件属性モデル |
attributeTagById | Map<String, AttributeTag> | No | 条件属性タグ情報 |
attributeRoleRelationByRoleId | Map<String, AttributeRoleRelation> | No | 条件属性と関連するロール |
attributeInUse | Boolean | Yes | 条件属性データ型 |
⚠️ リクエスト時に使用されるモデルはAttribute
を参照
Attribute attribute = Attribute.build()
.attributeId("")
.attributeName("")
.description("")
.build();
client.updateAttribute(attribute);
[DeleteAttributeRequest]
Key | Type | Required | Description |
---|---|---|---|
attributeId | String | Yes | 条件属性ID |
forceDelete | boolean | No | 強制削除を行うかどうか(デフォルト値: false) |
DeleteAttributeRequest request = DeleteAttributeRequest.build()
.attributeId("")
.forceDelete(false)
.build();
client.deleteAttribute(request);
[DeleteAttributesRequest]
Key | Type | Required | Description |
---|---|---|---|
attributeIds | Set<String> | Yes | 条件属性IDリスト |
forceDelete | boolean | No | 強制削除を行うかどうか(デフォルト値: false) |
DeleteAttributesRequest request = DeleteAttributesRequest.builder()
.operationIds(Set.of(""))
.build();
client.deleteAttributes(request);
スコープ情報の登録、照会、修正、削除
[Scope]
Key | Type | Required | Description |
---|---|---|---|
scopeId | String | Yes | スコープID |
description | String | No | 説明 |
Scope scope = Scope.builder()
.scopeId("")
.description("")
.build();
client.createScope(scope);
⚠️レスポンス時に使用されるモデルはModel
を参照
String scopeId = "";
Scope scope = client.getScope(scopeId);
⚠️レスポンス時に使用されるモデルはCommon
を参照
[GetScopesRequest]
Key | Type | Required | Description |
---|---|---|---|
scopeIds | List<String> | No | スコープIDリスト |
scopeIdPreLike | String | No | スコープID(前方一致) |
descriptionLike | String | No | 説明(部分一致) |
GetScopesRequest request = GetScopesRequest.builder()
.scopeIdPreLike("")
.build();
Pageable pageable = Pageable.builder()
.page(1)
.itemsPerPage(10)
.build();
Page<Scope> scopes = client.getScopes(request, pageable);
⚠️リクエスト時に使用されるモデルはScope
を参照
Scope scope = Scope.builder()
.scopeId("")
.description("")
.build();
client.updateScope(scope);
String scopeId = "";
client.deleteScope(userId);
[DeleteScopesRequest]
Key | Type | Required | Description |
---|---|---|---|
scopeIds | Set<String> | Yes | スコープIDリスト |
DeleteScopesRequest request = DeleteScopesRequest.builder()
.scopeIds(Set.of(""))
.build();
client.deleteScopes(request);
ロール情報登録、照会、修正、削除及び登録されたロールの設定可能なAttributeリストの照会、DENY(未使用)に変更可能かどうか
[Role]
Key | Type | Required | Description |
---|---|---|---|
roleMetaData | RoleMetaData | Yes | ロール |
roleRelations | List<RoleRelation> | No | 関連関係ロールIDリスト |
roleTags | List<RoleTag> | No | ロールタグリスト |
[RoleMetaData]
Key | Type | Required | Description |
---|---|---|---|
roleId | String | Yes | ロールID |
roleName | String | No | ロール名 |
roleGroup | String | No | ロールグループ |
description | String | No | 説明 |
exposureOrder | Integer | No | 表示順序 |
[RoleRelation]
Key | Type | Required | Description |
---|---|---|---|
relatedRoleId | String | Yes | ロール関連関係ID |
roleApplyPolicyCode | RoleApplyPolicyCode | No | ロール使用有無: ALLOW, DENY |
conditions | List<Condition> | No | ロール条件属性 |
[Condition]
Key | Type | Required | Description |
---|---|---|---|
attributeId | String | Yes | 条件属性ID |
attributeOperatorType | Required | Yes | 条件属性演算子タイプ |
attributeValues | List<String> | No | 条件属性値 |
Role role = Role.builder()
.roleMetaData(RoleMetaData.build("")
.roleId("")
.roleName("")
.roleGroup("")
.description("")
.exposureOrder(0)
.build())
.roleRelations(RoleRelation.build()
.relatedRoleId("")
.roleApplyPolicyCode(RoleApplyPolicyCode.ALLOW)
.conditions(Condition.build()
.attributeId("")
.attributeOperatorTypeCode(AttributeOperatorTypeCode.STRING)
.attributeValues(List.of())
.build())
.build())
.roleTags(List.of())
.build();
client.createRole(role);
⚠️レスポンス時に使用されるモデルはModel
を参照
String roleId = "";
Role role = client.getRole(roleId);
[GetRoleRequest]
Key | Type | Required | Description |
---|---|---|---|
roleIds | List<String> | No | ロールIDリスト(完全一致) |
roleIdPreLike | String | No | スコープID(前方一致) |
relatedRoleIds | List<String> | No | 関連関係ロールIDリスト(完全一致) |
descriptionLike | String | No | 説明(部分一致) |
roleNameLike | String | No | ロール名(部分一致) |
roleGroup | String | No | ロールグループ(完全一致) |
roleGroupLike | String | No | ロールグループ(部分一致) |
roleTagIdExpr | String | No | ロールタグ条件(セパレータ';':OR, ',':AND) |
roleTagIds | List<String> | No | ロールタグIDリスト(完全一致) |
attributeIds | List<String> | No | 条件属性IDリスト(完全一致) |
attributeTagIds | List<String> | No | 条件属性タグIDリスト(完全一致) |
needAttributes | Boolean | No | レスポンス時に条件属性情報を含めるかどうか |
needRoleTags | Boolean | No | レスポンス時にロールタグIDリストを含めるかどうか |
needRoleRelations | Boolean | No | レスポンス時に関連関係ロールIDリストを含めるかどうか |
searchRoleOptionCode | SearchRoleOptionCode | No | ロール検索時に下位ロールを含めるかどうか |
GetRoleRequest request = GetRoleRequest.builder()
.roleIds("")
.build();
Pageable pageable = Pageable.builder()
.page(1)
.itemsPerPage(10)
.build();
Page<Role> roles = client.getRoles(request, pageable);
⚠️リクエスト時に使用されるモデルはRole
参考を参照
Role role = Role.builder()
.roleMetaData(RoleMetaData.build()
.roleId("")
.roleName("")
.roleGroup("")
.description""()
.exposureOrder(0)
.build())
.roleRelations(RoleRelation.build()
.relatedRoleId("")
.roleApplyPolicyCode(RoleApplyPolicyCode.ALLOW)
.conditions(Condition.build()
.attributeId("")
.attributeOperatorTypeCode(AttributeOperatorTypeCode.STRING)
.attributeValues(List.of())
.build())
.build())
.roleTags(List.of())
.build();
client.updateRole(role);
String roleId = "";
client.deleteRole(roleId);
[DeleteRolesRequest]
Key | Type | Required | Description |
---|---|---|---|
roleIds | Set<String> | Yes | ロールIDリスト |
DeleteRolesRequest request = DeleteRolesRequest.builder()
.roleIds(Set.of(""))
.build();
client.deleteRoles(request);
[GetRoleAttributesRequest]
Key | Type | Required | Description |
---|---|---|---|
roleId | String | Yes | ロールID |
attributeIds | List<String> | No | 条件属性IDリスト(完全一致) |
attributeTagIds | List<String> | No | 条件属性タグIDリスト(完全一致) |
attributeNameLike | Boolean | No | レスポンス時の条件属性名(部分一致) |
GetRoleAttributesRequest request = GetRoleAttributesRequest.builder()
.roleId("")
.attributeIds(List.of())
.attributeTagIds(List.of())
.attributeNameLike(List.of())
.build();
Pageable pageable = Pageable.builder()
.page(1)
.itemsPerPage(10)
.build();
Page<Attribute> attributes = client.getRoleAttributes(request, pageable);
⚠️レスポンス時に使用されるモデルは3. 属性
Modelを参照
String roleId = "";
boolean result = client.isDeniable(roleId);
ロール関連関係の登録、修正、削除
[CreateRoleRelationRequest]
Key | Type | Required | Description |
---|---|---|---|
roleId | String | Yes | ロールID |
roleRelations | List<RoleRelation> | No | ⚠️ 5. ロール のRoleRelation Modelを参照 |
CreateRoleRelationRequest role = CreateRoleRelationRequest.builder()
.roleId("")
.roleRelations(RoleRelation.build()
.relatedRoleId("")
.roleApplyPolicyCode(RoleApplyPolicyCode.ALLOW)
.conditions(Condition.build()
.attributeId("")
.attributeOperatorTypeCode(AttributeOperatorTypeCode.STRING)
.attributeValues(List.of())
.build())
.build())
.build();
client.createRoleRelations(role);
[UpdateRoleRelationRequest]
Key | Type | Required | Description |
---|---|---|---|
roleId | String | Yes | ロールID |
roleRelations | List<RoleRelation> | No | ⚠️ 5. ロール のRoleRelation Modelを参照 |
UpdateRoleRelationRequest role = UpdateRoleRelationRequest.builder()
.roleId("")
.roleRelations(RoleRelation.build()
.relatedRoleId("")
.roleApplyPolicyCode(RoleApplyPolicyCode.ALLOW)
.conditions(Condition.build()
.attributeId("")
.attributeOperatorTypeCode(AttributeOperatorTypeCode.STRING)
.attributeValues(List.of())
.build())
.build())
.build();
client.updateRoleRelation(role);
[DeleteRoleRelationRequest]
Key | Type | Required | Description |
---|---|---|---|
roleId | String | Yes | ロールID |
relatedRoleIds | List<String> | No | 関連ロールIDリスト |
DeleteRoleRelationRequest role = DeleteRoleRelationRequest.builder()
.roleId("")
.relatedRoleIds(List.Of(""))
.build();
client.deleteRoleRelations(role);
リソース情報の登録、照会、修正、削除
[Resource]
Key | Type | Required | Description |
---|---|---|---|
resourceId | String | No | リソースID |
description | String | No | 説明 |
name | String | No | リソース名 |
path | String | Yes | リソースパス |
uiPath | String | Yes | リソースUIパス |
priority | Integer | Yes | 優先順位 |
metadata | String | No | メタデータ |
newResourceId | String | No | 既に作成されたリソースIDをアップデートしたい場合にのみ使用 |
Resource resource = Resource.builder()
.resourceId("")
.description("")
.name("")
.path("")
.uiPath("")
.priority(0)
.metadata("")
.build();
client.createResource(resource);
⚠️レスポンス時に使用されるモデルはModel
を参照
String resourceId = "";
Resource resource = client.getResource(resourceId);
⚠️レスポンス時に使用されるモデルはCommon
を参照
[GetResourcesRequest]
Key | Type | Required | Description |
---|---|---|---|
resourceIdPreLike | String | No | リソースID(前方一致) |
resourcePath | String | No | リソースパス(完全一致) |
resourcePathLike | String | No | リソースパス(前方一致) |
resourceUiPath | String | No | リソースUIパス(前方一致) |
resourceIds | List<String> | No | リソースIDリスト |
resourcePaths | List<String> | No | リソースパスリスト(完全一致) |
resourceUiPaths | List<String> | No | リソースUIパスリスト(完全一致) |
userIds | List<String> | No | リソースにアクセス可能なユーザーIDリスト |
scopeIds | List<String> | No | リソースにアクセス可能なスコープIDリスト |
roleIds | List<String> | No | リソースに付与されたロールIDリスト |
operationIds | List<String> | No | リソースに付与されたオペレーションIDリスト |
searchRoleOptionCode | SearchRoleOptionCode | No | ロール検索時に下位ロールを含めるかどうか |
GetResourcesRequest request = GetResourcesRequest.builder()
.resourceIdPreLike("")
.resourcePathLike("")
.userIds(List.of())
.searchRoleOptionCode(SearchRoleOptionCode.DIRECT)
.build();
Pageable pageable = Pageable.builder()
.page(1)
.itemsPerPage(10)
.build();
Page<Resource> resources = client.getResources(request, pageable);
⚠️リクエスト時に使用されるモデルはResource
を参照
Resource resource = Resource.builder()
.resourceId("")
.description("")
.name("")
.path("")
.uiPath("")
.priority(0)
.metadata("")
.build();
client.updateResource(operation);
String resourceId = "";
client.deleteResource(resourceId);
[DeleteResourcesRequest]
Key | Type | Required | Description |
---|---|---|---|
resourceIds | Set<String> | Yes | リソースIDリスト |
DeleteResourcesRequest request = DeleteResourcesRequest.builder()
.roleIds(Set.of(""))
.build();
client.deleteResources(request);
リソースの階層構造を照会します。 uiPath(resourceUiPath)を基準に階層構造が形成され、ユーザーが定義したキャッシュ時間だけキャッシュされます。
[GetResourceHierarchyRequest]
Key | Type | Required | Description |
---|---|---|---|
userIds | List<String> | No | ユーザーIDリスト |
roleIds | List<String> | No | ロールIDリスト |
operationIds | List<String> | No | オペレーションIDリスト |
scopeIds | List<String> | No | スコープIDリスト |
resourceIds | List<String> | No | リソースIDリスト |
resourcePath | String | No | リソースパス |
resourceUiPath | String | No | リソースUIパス |
GetResourceHierarchyRequest request = GetResourceHierarchyRequest.builder()
.resourceIds(List.of(""))
.build());
List<ResourceHierarchy> responses = client.getResourceHierarchy(request);
[ResourceHierarchy]
Key | Type | Required | Description |
---|---|---|---|
resourceId | String | Yes | リソースID |
description | String | No | リソースの説明 |
name | String | Yes | リソース名 |
path | String | Yes | リソースパス |
uiPath | String | Yes | リソースUIパス このパスに基づいて階層構造が作成されます。 |
priority | Integer | Yes | 優先順位 |
resources | List<ResourceHierarchy> | No | 下位リソース |
ユーザーが特定のロールを持っているか、リソースに対するアクセス権を持っているかどうかを確認します。 リソースの場合、ユーザーが定義したキャッシュ時間だけキャッシュされます。
1.特定のリソースの認可結果確認
[GetResourceAuthorizationRequest]
Key | Type | Required | Description |
---|---|---|---|
authRequestId | String | No | ユーザーが定義したID値 どの認証条件に対するレスポンスであるかを明確に知る必要がある場合に使用します。 |
operationId | String | Yes | オペレーションID |
resourceId | String | No | リソースID(リソースパスがない場合は必須) |
resourcePath | String | No | リソースパス(リソースIDがない場合は必須) |
scopeId | String | No | スコープID |
attributes | List<AuthorizationAttribute> | No | 条件属性リスト |
[AuthorizationAttribute]
Key | Type | Required | Description |
---|---|---|---|
attributeId | String | Yes | 条件属性ID |
attributeValue | String | Yes | 条件属性値 |
String userId = "userId";
GetResourceAuthorizationRequest request = GetResourceAuthorizationRequest.builder()
.operationId("")
.resourceId("")
.scopeId("")
.attributes(List.of(AuthorizationAttribute.builder()
.attributeId("")
.attributeValue("")
.build()));
.build();
boolean response = client.hasAuthorizationByResource(userId, request);
String userId = "userId";
List<GetResourceAuthorizationRequest> requests = requests = List.of(GetResourceAuthorizationRequest.builder()
.authRequestId("")
.operationId("")
.resourceId("")
.scopeId("")
.build(),
GetResourceAuthorizationRequest.builder()
.authRequestId("")
.operationId("")
.resourcePath("")
.build());
List<GetResourceAuthorizationResponse> responses = client.hasAuthorizationByResources(userId, requests);
[GetResourceAuthorizationResponse]
Key | Type | Required | Description |
---|---|---|---|
authRequestId | String | No | ユーザーが定義したID値 リクエスト時に送った値がそのまま返されます。 |
operationId | String | Yes | オペレーションID |
resourceId | String | Yes | リソースID |
resourcePath | String | No | リソースパス |
scopeId | String | Yes | スコープID |
permission | Boolean | Yes | 認可結果 true:権限あり false:権限なし |
attributes | List<AuthorizationAttribute> | No | 条件属性リスト |
[GetRoleAuthorizationRequest]
Key | Type | Required | Description |
---|---|---|---|
authRequestId | String | No | ユーザーが定義したID値 どの認証条件に対する応答であるかを明確に知る必要がある場合に使用。 |
attributes | List<AuthorizationAttribute> | No | 条件属性リスト |
roleId | String | Yes | ロールID |
scopeId | String | No | スコープID |
String userId = "userId";
GetRoleAuthorizationRequest getUserRequest = GetRoleAuthorizationRequest.builder()
.authRequestId("")
.roleId("")
.scopeId("")
.attributes(List.of(AuthorizationAttribute.builder()
.attributeId("")
.attributeValue("")
.build()))
.build();
boolean response = client.hasAuthorizationByRole(userId, request);
String userId = "userId";
GetRoleAuthorizationRequest requests = List.of(GetRoleAuthorizationRequest.builder()
.authRequestId("")
.roleId("")
.scopeId("")
.attributes(List.of(AuthorizationAttribute.builder()
.attributeId("")
.attributeValue("")
.build()))
.build(),
GetRoleAuthorizationRequest.builder()
.authRequestId("")
.roleId("")
.scopeId("")
.attributes(List.of(AuthorizationAttribute.builder()
.attributeId("")
.attributeValue("")
.build()))
.build());
List<GetRoleAuthorizationResponse> responses = client.hasAuthorizationByRoles(userId, requests);
[GetRoleAuthorizationResponse]
Key | Type | Required | Description |
---|---|---|---|
authRequestId | String | No | ユーザーが定義したID値 リクエスト時に送った値がそのまま返されます。 |
roleId | String | Yes | ロールID |
scopeId | String | Yes | スコープID |
permission | Boolean | Yes | 認可結果 true:権限あり false:権限なし |
attributes | List<AuthorizationAttribute> | No | 条件属性リスト |
クライアントSDKでは、下記の3つの場合に、それぞれクライアント側のキャッシュを使用します。
LRUで管理しており、キャッシュのデフォルト値は300秒のTTL(time to live)と1,000,000個Sizeです。 この値を修正するにはNHN Cloudコンソールに接続します。 NHN Cloudコンソールで変更した設定は、変更されるとすぐに反映され、変更されると同時に既存のキャッシュはすべて削除されます。
ROLEのデータをAtomicに追加/変更/削除したい場合は、RoleClientオブジェクトのbeginTransaction()を呼び出してRoleSessionオブジェクトを取得して使います。
例えば、下記のように複数のRoleを同時に登録する際、途中でエラーが発生すると、いくつかは登録されて、いくつかは登録できない場合があります。
RoleClient client = RoleClientFactory.getClient(RoleConfig.builder()
.appKey("")
.secretKey("")
.build());
try {
User user = User.build()
.userId("U1")
.description("desc")
.build();
client.userCreate(user);
Role role = Role.builder()
.roleMetaData(RoleMetaData.build()
.roleId("M1")
.roleName("MEMBER")
.exposureOrder(1)
.build())
.build();
// もし、ここでExceptionが発生したら
// U1は作成されますが、M1は作成されません。
client.createRole(role);
} catch (Exception e) {
// エラー発生時、独自にRollbackロジックを実装する必要があります。
client.userDelete("U1");
}
RoleSessionオブジェクトを使うと、上のような状況で部分的な失敗をなくすことができます。
RoleClient client = RoleClientFactory.getClient(RoleConfig.builder()
.appKey("")
.secretKey("")
.build());
RoleSession session = client.beginTransaction();
try {
User user = User.build()
.userId("U1")
.description("desc")
.build();
session.userCreate(user);
Role role = Role.builder()
.roleMetaData(RoleMetaData.build()
.roleId("M1")
.roleName("MEMBER")
.exposureOrder(1)
.build())
.build();
// もし、ここでExceptionが発生しても、部分的な失敗は発生しません。
session.createRole(role);
// エラーが発生しなかった場合、サーバーに変更事項を反映します。
session.commit();
} catch (Exception e) {
// エラーが発生した時、rollback関数を使ってsessionに保存された変更内容を空にします。
session.rollback();
}
RoleSessionオブジェクトを使う時、commit()メソッドを呼び出す前までは追加/修正/変更がサーバーに反映されないので、commit()する前に変更したデータを読まないように注意する必要があります。
RoleSessionオブジェクトをcommit()したりrollback()した後、再使用できます。
RoleSessionは
SDK使用ガイド
で定義されたサービスのうち、照会を除いた登録、修正、削除に対して同じように使用できます。