keycloak-service
公開メンバ関数 | 非公開メンバ関数 | 非公開変数類 | 全メンバ一覧
org.keycloak.authorization.protection.policy.UserManagedPermissionService クラス
org.keycloak.authorization.protection.policy.UserManagedPermissionService 連携図
Collaboration graph

公開メンバ関数

 UserManagedPermissionService (KeycloakIdentity identity, ResourceServer resourceServer, AuthorizationProvider authorization, AdminEventBuilder eventBuilder)
 
Response create (@PathParam("resourceId") String resourceId, UmaPermissionRepresentation representation)
 
Response update (@PathParam("policyId") String policyId, String payload)
 
Response delete (@PathParam("policyId") String policyId)
 
Response findById (@PathParam("policyId") String policyId)
 
Response find (@QueryParam("name") String name, @QueryParam("resource") String resource, @QueryParam("scope") String scope, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResult)
 

非公開メンバ関数

Policy getPolicy (@PathParam("policyId") String policyId)
 
void checkRequest (String resourceId, UmaPermissionRepresentation representation)
 
String getAssociatedResourceId (String policyId)
 

非公開変数類

final ResourceServer resourceServer
 
final Identity identity
 
final AuthorizationProvider authorization
 
final PermissionService delegate
 

詳解

著者
Federico M. Facca

構築子と解体子

◆ UserManagedPermissionService()

org.keycloak.authorization.protection.policy.UserManagedPermissionService.UserManagedPermissionService ( KeycloakIdentity  identity,
ResourceServer  resourceServer,
AuthorizationProvider  authorization,
AdminEventBuilder  eventBuilder 
)
inline
65  {
66  this.identity = identity;
69  delegate = new PermissionService(resourceServer, authorization, null, eventBuilder);
70  ResteasyProviderFactory.getInstance().injectProperties(delegate);
71  }
final AuthorizationProvider authorization
Definition: UserManagedPermissionService.java:62
final PermissionService delegate
Definition: UserManagedPermissionService.java:63
final ResourceServer resourceServer
Definition: UserManagedPermissionService.java:60
final Identity identity
Definition: UserManagedPermissionService.java:61

関数詳解

◆ checkRequest()

void org.keycloak.authorization.protection.policy.UserManagedPermissionService.checkRequest ( String  resourceId,
UmaPermissionRepresentation  representation 
)
inlineprivate
145  {
146  ResourceStore resourceStore = this.authorization.getStoreFactory().getResourceStore();
147  Resource resource = resourceStore.findById(resourceId, resourceServer.getId());
148 
149  if (resource == null) {
150  throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "Resource [" + resourceId + "] cannot be found", Response.Status.BAD_REQUEST);
151  }
152 
153  if (!resource.getOwner().equals(identity.getId())) {
154  throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "Only resource owner can access policies for resource [" + resourceId + "]", Status.BAD_REQUEST);
155  }
156 
157  if (!resource.isOwnerManagedAccess()) {
158  throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "Only resources with owner managed accessed can have policies", Status.BAD_REQUEST);
159  }
160 
161  if (!resourceServer.isAllowRemoteResourceManagement()) {
162  throw new ErrorResponseException(OAuthErrorException.REQUEST_NOT_SUPPORTED, "Remote Resource Management not enabled on resource server [" + resourceServer.getId() + "]", Status.FORBIDDEN);
163  }
164 
165  if (representation != null) {
166  Set<String> resourceScopes = resource.getScopes().stream().map(scope -> scope.getName()).collect(Collectors.toSet());
167  Set<String> scopes = representation.getScopes();
168 
169  if (scopes == null || scopes.isEmpty()) {
170  scopes = resourceScopes;
171  representation.setScopes(scopes);
172  }
173 
174  if (!resourceScopes.containsAll(scopes)) {
175  throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "Some of the scopes [" + scopes + "] are not valid for resource [" + resourceId + "]", Response.Status.BAD_REQUEST);
176  }
177  }
178  }
final AuthorizationProvider authorization
Definition: UserManagedPermissionService.java:62
final ResourceServer resourceServer
Definition: UserManagedPermissionService.java:60
final Identity identity
Definition: UserManagedPermissionService.java:61

◆ create()

Response org.keycloak.authorization.protection.policy.UserManagedPermissionService.create ( @PathParam("resourceId") String  resourceId,
UmaPermissionRepresentation  representation 
)
inline
77  {
78  if (representation.getId() != null) {
79  throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "Newly created uma policies should not have an id", Response.Status.BAD_REQUEST);
80  }
81 
82  checkRequest(resourceId, representation);
83 
84  representation.addResource(resourceId);
85  representation.setOwner(identity.getId());
86 
87  return findById(delegate.create(representation).getId());
88  }
Response create(String payload)
Definition: PolicyService.java:114
final PermissionService delegate
Definition: UserManagedPermissionService.java:63
Response findById(@PathParam("policyId") String policyId)
Definition: UserManagedPermissionService.java:119
final Identity identity
Definition: UserManagedPermissionService.java:61
void checkRequest(String resourceId, UmaPermissionRepresentation representation)
Definition: UserManagedPermissionService.java:145

◆ delete()

Response org.keycloak.authorization.protection.policy.UserManagedPermissionService.delete ( @PathParam("policyId") String  policyId)
inline
110  {
111  checkRequest(getAssociatedResourceId(policyId), null);
112  PolicyTypeResourceService.class.cast(delegate.getResource(policyId)).delete();
113  return Response.noContent().build();
114  }
final PermissionService delegate
Definition: UserManagedPermissionService.java:63
void checkRequest(String resourceId, UmaPermissionRepresentation representation)
Definition: UserManagedPermissionService.java:145
String getAssociatedResourceId(String policyId)
Definition: UserManagedPermissionService.java:180
Object getResource(@PathParam("type") String type)
Definition: PolicyService.java:90

◆ find()

Response org.keycloak.authorization.protection.policy.UserManagedPermissionService.find ( @QueryParam("name") String  name,
@QueryParam("resource") String  resource,
@QueryParam("scope") String  scope,
@QueryParam("first") Integer  firstResult,
@QueryParam("max") Integer  maxResult 
)
inline
131  {
132  return delegate.findAll(null, name, "uma", resource, scope, true, identity.getId(), firstResult, maxResult);
133  }
Response findAll(@QueryParam("policyId") String id, @QueryParam("name") String name, @QueryParam("type") String type, @QueryParam("resource") String resource, @QueryParam("scope") String scope, @QueryParam("permission") Boolean permission, @QueryParam("owner") String owner, @QueryParam("first") Integer firstResult, @QueryParam("max") Integer maxResult)
Definition: PolicyService.java:179
final PermissionService delegate
Definition: UserManagedPermissionService.java:63
final Identity identity
Definition: UserManagedPermissionService.java:61

◆ findById()

Response org.keycloak.authorization.protection.policy.UserManagedPermissionService.findById ( @PathParam("policyId") String  policyId)
inline
119  {
120  checkRequest(getAssociatedResourceId(policyId), null);
121  return PolicyTypeResourceService.class.cast(delegate.getResource(policyId)).findById();
122  }
final PermissionService delegate
Definition: UserManagedPermissionService.java:63
Response findById(@PathParam("policyId") String policyId)
Definition: UserManagedPermissionService.java:119
void checkRequest(String resourceId, UmaPermissionRepresentation representation)
Definition: UserManagedPermissionService.java:145
String getAssociatedResourceId(String policyId)
Definition: UserManagedPermissionService.java:180
Object getResource(@PathParam("type") String type)
Definition: PolicyService.java:90

◆ getAssociatedResourceId()

String org.keycloak.authorization.protection.policy.UserManagedPermissionService.getAssociatedResourceId ( String  policyId)
inlineprivate
180  {
181  return getPolicy(policyId).getResources().iterator().next().getId();
182  }
Policy getPolicy(@PathParam("policyId") String policyId)
Definition: UserManagedPermissionService.java:135

◆ getPolicy()

Policy org.keycloak.authorization.protection.policy.UserManagedPermissionService.getPolicy ( @PathParam("policyId") String  policyId)
inlineprivate
135  {
136  Policy existing = authorization.getStoreFactory().getPolicyStore().findById(policyId, resourceServer.getId());
137 
138  if (existing == null) {
139  throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "Policy with [" + policyId + "] does not exist", Status.NOT_FOUND);
140  }
141 
142  return existing;
143  }
final AuthorizationProvider authorization
Definition: UserManagedPermissionService.java:62
final ResourceServer resourceServer
Definition: UserManagedPermissionService.java:60

◆ update()

Response org.keycloak.authorization.protection.policy.UserManagedPermissionService.update ( @PathParam("policyId") String  policyId,
String  payload 
)
inline
94  {
95  UmaPermissionRepresentation representation;
96 
97  try {
98  representation = JsonSerialization.readValue(payload, UmaPermissionRepresentation.class);
99  } catch (IOException e) {
100  throw new ErrorResponseException(OAuthErrorException.INVALID_REQUEST, "Failed to parse representation", Status.BAD_REQUEST);
101  }
102 
103  checkRequest(getAssociatedResourceId(policyId), representation);
104 
105  return PolicyTypeResourceService.class.cast(delegate.getResource(policyId)).update(payload);
106  }
final PermissionService delegate
Definition: UserManagedPermissionService.java:63
void checkRequest(String resourceId, UmaPermissionRepresentation representation)
Definition: UserManagedPermissionService.java:145
String getAssociatedResourceId(String policyId)
Definition: UserManagedPermissionService.java:180
Response update(@PathParam("policyId") String policyId, String payload)
Definition: UserManagedPermissionService.java:94
Object getResource(@PathParam("type") String type)
Definition: PolicyService.java:90

メンバ詳解

◆ authorization

final AuthorizationProvider org.keycloak.authorization.protection.policy.UserManagedPermissionService.authorization
private

◆ delegate

final PermissionService org.keycloak.authorization.protection.policy.UserManagedPermissionService.delegate
private

◆ identity

final Identity org.keycloak.authorization.protection.policy.UserManagedPermissionService.identity
private

◆ resourceServer

final ResourceServer org.keycloak.authorization.protection.policy.UserManagedPermissionService.resourceServer
private

このクラス詳解は次のファイルから抽出されました: