keycloakify 9.0.0-rc.0 → 9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +8 -18
  2. package/account/Template.js +1 -1
  3. package/account/Template.js.map +1 -1
  4. package/account/TemplateProps.d.ts +1 -1
  5. package/account/kcContext/KcContext.d.ts +1 -0
  6. package/account/kcContext/KcContext.js.map +1 -1
  7. package/account/kcContext/kcContextMocks.js +1 -0
  8. package/account/kcContext/kcContextMocks.js.map +1 -1
  9. package/account/lib/useGetClassName.js +1 -0
  10. package/account/lib/useGetClassName.js.map +1 -1
  11. package/account/pages/Account.js +1 -1
  12. package/account/pages/Account.js.map +1 -1
  13. package/bin/getSrcDirPath.js +30 -17
  14. package/bin/getSrcDirPath.js.map +1 -1
  15. package/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +6 -0
  16. package/bin/keycloakify/generateFtl/generateFtl.js +22 -0
  17. package/bin/keycloakify/generateFtl/generateFtl.js.map +1 -1
  18. package/bin/keycloakify/generateFtl/pageId.d.ts +1 -1
  19. package/bin/keycloakify/generateFtl/pageId.js +2 -0
  20. package/bin/keycloakify/generateFtl/pageId.js.map +1 -1
  21. package/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.js +1 -5
  22. package/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.js.map +1 -1
  23. package/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.js +32 -103
  24. package/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.js.map +1 -1
  25. package/bin/keycloakify/generateStartKeycloakTestingContainer.d.ts +1 -0
  26. package/bin/keycloakify/generateStartKeycloakTestingContainer.js +4 -3
  27. package/bin/keycloakify/generateStartKeycloakTestingContainer.js.map +1 -1
  28. package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.d.ts +0 -1
  29. package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.js +22 -13
  30. package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.js.map +1 -1
  31. package/bin/keycloakify/generateTheme/readStaticResourcesUsage.d.ts +0 -2
  32. package/bin/keycloakify/generateTheme/readStaticResourcesUsage.js +37 -51
  33. package/bin/keycloakify/generateTheme/readStaticResourcesUsage.js.map +1 -1
  34. package/bin/keycloakify/keycloakify.js +3 -2
  35. package/bin/keycloakify/keycloakify.js.map +1 -1
  36. package/bin/keycloakify/replacers/replaceImportsFromStaticInJsCode.js +7 -3
  37. package/bin/keycloakify/replacers/replaceImportsFromStaticInJsCode.js.map +1 -1
  38. package/lib/usePrepareTemplate.js +7 -8
  39. package/lib/usePrepareTemplate.js.map +1 -1
  40. package/login/Fallback.js +6 -0
  41. package/login/Fallback.js.map +1 -1
  42. package/login/Template.js +1 -1
  43. package/login/Template.js.map +1 -1
  44. package/login/TemplateProps.d.ts +1 -1
  45. package/login/kcContext/KcContext.d.ts +21 -1
  46. package/login/kcContext/KcContext.js.map +1 -1
  47. package/login/kcContext/kcContextMocks.d.ts +1 -1
  48. package/login/kcContext/kcContextMocks.js +12 -1
  49. package/login/kcContext/kcContextMocks.js.map +1 -1
  50. package/login/lib/useGetClassName.js +2 -0
  51. package/login/lib/useGetClassName.js.map +1 -1
  52. package/login/pages/Info.js +1 -1
  53. package/login/pages/Info.js.map +1 -1
  54. package/login/pages/LoginConfigTotp.js +1 -1
  55. package/login/pages/LoginConfigTotp.js.map +1 -1
  56. package/login/pages/LoginDeviceVerifyUserCode.d.ts +7 -0
  57. package/login/pages/LoginDeviceVerifyUserCode.js +15 -0
  58. package/login/pages/LoginDeviceVerifyUserCode.js.map +1 -0
  59. package/login/pages/LoginOauthGrant.d.ts +7 -0
  60. package/login/pages/LoginOauthGrant.js +15 -0
  61. package/login/pages/LoginOauthGrant.js.map +1 -0
  62. package/package.json +11 -67
  63. package/src/account/Template.tsx +1 -1
  64. package/src/account/TemplateProps.ts +1 -1
  65. package/src/account/kcContext/KcContext.ts +1 -0
  66. package/src/account/kcContext/kcContextMocks.ts +1 -0
  67. package/src/account/lib/useGetClassName.ts +1 -0
  68. package/src/account/pages/Account.tsx +4 -4
  69. package/src/bin/getSrcDirPath.ts +8 -8
  70. package/src/bin/keycloakify/generateFtl/ftl_object_to_js_code_declaring_an_object.ftl +6 -0
  71. package/src/bin/keycloakify/generateFtl/generateFtl.ts +21 -0
  72. package/src/bin/keycloakify/generateFtl/pageId.ts +2 -0
  73. package/src/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.ts +1 -6
  74. package/src/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.ts +32 -103
  75. package/src/bin/keycloakify/generateStartKeycloakTestingContainer.ts +11 -4
  76. package/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts +29 -15
  77. package/src/bin/keycloakify/generateTheme/readStaticResourcesUsage.ts +21 -28
  78. package/src/bin/keycloakify/keycloakify.ts +3 -3
  79. package/src/bin/keycloakify/replacers/replaceImportsFromStaticInJsCode.ts +14 -7
  80. package/src/lib/usePrepareTemplate.ts +7 -10
  81. package/src/login/Fallback.tsx +6 -0
  82. package/src/login/Template.tsx +1 -1
  83. package/src/login/TemplateProps.ts +3 -1
  84. package/src/login/kcContext/KcContext.ts +24 -0
  85. package/src/login/kcContext/kcContextMocks.ts +23 -1
  86. package/src/login/lib/useGetClassName.ts +2 -0
  87. package/src/login/pages/Info.tsx +4 -1
  88. package/src/login/pages/LoginConfigTotp.tsx +1 -1
  89. package/src/login/pages/LoginDeviceVerifyUserCode.tsx +68 -0
  90. package/src/login/pages/LoginOauthGrant.tsx +73 -0
  91. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountPages.java +0 -33
  92. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProvider.java +0 -76
  93. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProviderFactory.java +0 -25
  94. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountSpi.java +0 -50
  95. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProvider.java +0 -424
  96. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProviderFactory.java +0 -51
  97. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/Templates.java +0 -51
  98. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountBean.java +0 -91
  99. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountFederatedIdentityBean.java +0 -157
  100. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ApplicationsBean.java +0 -258
  101. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AuthorizationBean.java +0 -515
  102. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/FeaturesBean.java +0 -56
  103. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/LogBean.java +0 -95
  104. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/PasswordBean.java +0 -34
  105. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/RealmBean.java +0 -75
  106. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ReferrerBean.java +0 -38
  107. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/SessionsBean.java +0 -93
  108. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/TotpBean.java +0 -125
  109. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/UrlBean.java +0 -121
  110. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/AccountUrls.java +0 -115
  111. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormService.java +0 -1320
  112. package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormServiceFactory.java +0 -64
  113. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountPages.java +0 -33
  114. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProvider.java +0 -76
  115. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProviderFactory.java +0 -25
  116. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountSpi.java +0 -50
  117. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProvider.java +0 -424
  118. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProviderFactory.java +0 -51
  119. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/Templates.java +0 -51
  120. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountBean.java +0 -91
  121. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountFederatedIdentityBean.java +0 -157
  122. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ApplicationsBean.java +0 -258
  123. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AuthorizationBean.java +0 -515
  124. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/FeaturesBean.java +0 -56
  125. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/LogBean.java +0 -95
  126. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/PasswordBean.java +0 -34
  127. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/RealmBean.java +0 -75
  128. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ReferrerBean.java +0 -38
  129. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/SessionsBean.java +0 -93
  130. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/TotpBean.java +0 -125
  131. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/UrlBean.java +0 -121
  132. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/AccountUrls.java +0 -115
  133. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormService.java +0 -1320
  134. package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormServiceFactory.java +0 -64
@@ -1,515 +0,0 @@
1
- /*
2
- * Copyright 2022 Red Hat, Inc. and/or its affiliates
3
- * and other contributors as indicated by the @author tags.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- package org.keycloak.forms.account.freemarker.model;
19
-
20
- import jakarta.ws.rs.core.UriInfo;
21
- import java.util.ArrayList;
22
- import java.util.Collection;
23
- import java.util.Collections;
24
- import java.util.Date;
25
- import java.util.EnumMap;
26
- import java.util.HashMap;
27
- import java.util.List;
28
- import java.util.Map;
29
- import java.util.Set;
30
- import java.util.stream.Collectors;
31
- import org.keycloak.authorization.AuthorizationProvider;
32
- import org.keycloak.authorization.model.PermissionTicket;
33
- import org.keycloak.authorization.model.Policy;
34
- import org.keycloak.authorization.model.Resource;
35
- import org.keycloak.authorization.model.ResourceServer;
36
- import org.keycloak.authorization.model.Scope;
37
- import org.keycloak.authorization.store.PermissionTicketStore;
38
- import org.keycloak.common.util.Time;
39
- import org.keycloak.models.ClientModel;
40
- import org.keycloak.models.KeycloakSession;
41
- import org.keycloak.models.RealmModel;
42
- import org.keycloak.models.UserModel;
43
- import org.keycloak.models.utils.ModelToRepresentation;
44
- import org.keycloak.representations.idm.authorization.ScopeRepresentation;
45
- import org.keycloak.services.util.ResolveRelative;
46
-
47
- /**
48
- * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
49
- */
50
- public class AuthorizationBean {
51
-
52
- private final KeycloakSession session;
53
- private final RealmModel realm;
54
- private final UserModel user;
55
- private final AuthorizationProvider authorization;
56
- private final UriInfo uriInfo;
57
- private ResourceBean resource;
58
- private List<ResourceBean> resources;
59
- private Collection<ResourceBean> userSharedResources;
60
- private Collection<ResourceBean> requestsWaitingPermission;
61
- private Collection<ResourceBean> resourcesWaitingOthersApproval;
62
-
63
- public AuthorizationBean(
64
- KeycloakSession session, RealmModel realm, UserModel user, UriInfo uriInfo) {
65
- this.session = session;
66
- this.realm = realm;
67
- this.user = user;
68
- this.uriInfo = uriInfo;
69
- authorization = session.getProvider(AuthorizationProvider.class);
70
- List<String> pathParameters = uriInfo.getPathParameters().get("resource_id");
71
-
72
- if (pathParameters != null && !pathParameters.isEmpty()) {
73
- Resource resource =
74
- authorization
75
- .getStoreFactory()
76
- .getResourceStore()
77
- .findById(realm, null, pathParameters.get(0));
78
-
79
- if (resource != null && !resource.getOwner().equals(user.getId())) {
80
- throw new RuntimeException(
81
- "User [" + user.getUsername() + "] can not access resource [" + resource.getId() + "]");
82
- }
83
- }
84
- }
85
-
86
- public Collection<ResourceBean> getResourcesWaitingOthersApproval() {
87
- if (resourcesWaitingOthersApproval == null) {
88
- Map<PermissionTicket.FilterOption, String> filters =
89
- new EnumMap<>(PermissionTicket.FilterOption.class);
90
-
91
- filters.put(PermissionTicket.FilterOption.REQUESTER, user.getId());
92
- filters.put(PermissionTicket.FilterOption.GRANTED, Boolean.FALSE.toString());
93
-
94
- resourcesWaitingOthersApproval = toResourceRepresentation(findPermissions(filters));
95
- }
96
-
97
- return resourcesWaitingOthersApproval;
98
- }
99
-
100
- public Collection<ResourceBean> getResourcesWaitingApproval() {
101
- if (requestsWaitingPermission == null) {
102
- Map<PermissionTicket.FilterOption, String> filters =
103
- new EnumMap<>(PermissionTicket.FilterOption.class);
104
-
105
- filters.put(PermissionTicket.FilterOption.OWNER, user.getId());
106
- filters.put(PermissionTicket.FilterOption.GRANTED, Boolean.FALSE.toString());
107
-
108
- requestsWaitingPermission = toResourceRepresentation(findPermissions(filters));
109
- }
110
-
111
- return requestsWaitingPermission;
112
- }
113
-
114
- public List<ResourceBean> getResources() {
115
- if (resources == null) {
116
- resources =
117
- authorization
118
- .getStoreFactory()
119
- .getResourceStore()
120
- .findByOwner(realm, null, user.getId())
121
- .stream()
122
- .filter(Resource::isOwnerManagedAccess)
123
- .map(ResourceBean::new)
124
- .collect(Collectors.toList());
125
- }
126
- return resources;
127
- }
128
-
129
- public Collection<ResourceBean> getSharedResources() {
130
- if (userSharedResources == null) {
131
- Map<PermissionTicket.FilterOption, String> filters =
132
- new EnumMap<>(PermissionTicket.FilterOption.class);
133
-
134
- filters.put(PermissionTicket.FilterOption.REQUESTER, user.getId());
135
- filters.put(PermissionTicket.FilterOption.GRANTED, Boolean.TRUE.toString());
136
-
137
- PermissionTicketStore ticketStore =
138
- authorization.getStoreFactory().getPermissionTicketStore();
139
-
140
- userSharedResources =
141
- toResourceRepresentation(ticketStore.find(realm, null, filters, null, null));
142
- }
143
- return userSharedResources;
144
- }
145
-
146
- public ResourceBean getResource() {
147
- if (resource == null) {
148
- String resourceId = uriInfo.getPathParameters().getFirst("resource_id");
149
-
150
- if (resourceId != null) {
151
- resource = getResource(resourceId);
152
- }
153
- }
154
-
155
- return resource;
156
- }
157
-
158
- private ResourceBean getResource(String id) {
159
- return new ResourceBean(
160
- authorization.getStoreFactory().getResourceStore().findById(realm, null, id));
161
- }
162
-
163
- public static class RequesterBean {
164
-
165
- private final Long createdTimestamp;
166
- private final Long grantedTimestamp;
167
- private UserModel requester;
168
- private List<PermissionScopeBean> scopes = new ArrayList<>();
169
- private boolean granted;
170
-
171
- public RequesterBean(PermissionTicket ticket, AuthorizationProvider authorization) {
172
- this.requester =
173
- authorization
174
- .getKeycloakSession()
175
- .users()
176
- .getUserById(authorization.getRealm(), ticket.getRequester());
177
- granted = ticket.isGranted();
178
- createdTimestamp = ticket.getCreatedTimestamp();
179
- grantedTimestamp = ticket.getGrantedTimestamp();
180
- }
181
-
182
- public UserModel getRequester() {
183
- return requester;
184
- }
185
-
186
- public List<PermissionScopeBean> getScopes() {
187
- return scopes;
188
- }
189
-
190
- private void addScope(PermissionTicket ticket) {
191
- if (ticket != null) {
192
- scopes.add(new PermissionScopeBean(ticket));
193
- }
194
- }
195
-
196
- public boolean isGranted() {
197
- return (granted && scopes.isEmpty())
198
- || scopes.stream().filter(permissionScopeBean -> permissionScopeBean.isGranted()).count()
199
- > 0;
200
- }
201
-
202
- public Date getCreatedDate() {
203
- return Time.toDate(createdTimestamp);
204
- }
205
-
206
- public Date getGrantedDate() {
207
- if (grantedTimestamp == null) {
208
- PermissionScopeBean permission =
209
- scopes.stream()
210
- .filter(permissionScopeBean -> permissionScopeBean.isGranted())
211
- .findFirst()
212
- .orElse(null);
213
-
214
- if (permission == null) {
215
- return null;
216
- }
217
-
218
- return permission.getGrantedDate();
219
- }
220
- return Time.toDate(grantedTimestamp);
221
- }
222
- }
223
-
224
- public static class PermissionScopeBean {
225
-
226
- private final Scope scope;
227
- private final PermissionTicket ticket;
228
-
229
- public PermissionScopeBean(PermissionTicket ticket) {
230
- this.ticket = ticket;
231
- scope = ticket.getScope();
232
- }
233
-
234
- public String getId() {
235
- return ticket.getId();
236
- }
237
-
238
- public Scope getScope() {
239
- return scope;
240
- }
241
-
242
- public boolean isGranted() {
243
- return ticket.isGranted();
244
- }
245
-
246
- private Date getGrantedDate() {
247
- if (isGranted()) {
248
- return Time.toDate(ticket.getGrantedTimestamp());
249
- }
250
- return null;
251
- }
252
- }
253
-
254
- public class ResourceBean {
255
-
256
- private final ResourceServerBean resourceServer;
257
- private final String ownerName;
258
- private final UserModel userOwner;
259
- private ClientModel clientOwner;
260
- private Resource resource;
261
- private Map<String, RequesterBean> permissions = new HashMap<>();
262
- private Collection<RequesterBean> shares;
263
-
264
- public ResourceBean(Resource resource) {
265
- RealmModel realm = authorization.getRealm();
266
- ResourceServer resourceServerModel = resource.getResourceServer();
267
- resourceServer =
268
- new ResourceServerBean(
269
- realm.getClientById(resourceServerModel.getClientId()), resourceServerModel);
270
- this.resource = resource;
271
- userOwner =
272
- authorization.getKeycloakSession().users().getUserById(realm, resource.getOwner());
273
- if (userOwner == null) {
274
- clientOwner = realm.getClientById(resource.getOwner());
275
- ownerName = clientOwner.getClientId();
276
- } else if (userOwner.getEmail() != null) {
277
- ownerName = userOwner.getEmail();
278
- } else {
279
- ownerName = userOwner.getUsername();
280
- }
281
- }
282
-
283
- public String getId() {
284
- return resource.getId();
285
- }
286
-
287
- public String getName() {
288
- return resource.getName();
289
- }
290
-
291
- public String getDisplayName() {
292
- return resource.getDisplayName();
293
- }
294
-
295
- public String getIconUri() {
296
- return resource.getIconUri();
297
- }
298
-
299
- public String getOwnerName() {
300
- return ownerName;
301
- }
302
-
303
- public UserModel getUserOwner() {
304
- return userOwner;
305
- }
306
-
307
- public ClientModel getClientOwner() {
308
- return clientOwner;
309
- }
310
-
311
- public List<ScopeRepresentation> getScopes() {
312
- return resource.getScopes().stream()
313
- .map(ModelToRepresentation::toRepresentation)
314
- .collect(Collectors.toList());
315
- }
316
-
317
- public Collection<RequesterBean> getShares() {
318
- if (shares == null) {
319
- Map<PermissionTicket.FilterOption, String> filters =
320
- new EnumMap<>(PermissionTicket.FilterOption.class);
321
-
322
- filters.put(PermissionTicket.FilterOption.RESOURCE_ID, this.resource.getId());
323
- filters.put(PermissionTicket.FilterOption.GRANTED, Boolean.TRUE.toString());
324
-
325
- shares = toPermissionRepresentation(findPermissions(filters));
326
- }
327
-
328
- return shares;
329
- }
330
-
331
- public Collection<ManagedPermissionBean> getPolicies() {
332
- ResourceServer resourceServer = getResourceServer().getResourceServerModel();
333
- RealmModel realm = resourceServer.getRealm();
334
- Map<Policy.FilterOption, String[]> filters = new EnumMap<>(Policy.FilterOption.class);
335
-
336
- filters.put(Policy.FilterOption.TYPE, new String[] {"uma"});
337
- filters.put(Policy.FilterOption.RESOURCE_ID, new String[] {this.resource.getId()});
338
- if (getUserOwner() != null) {
339
- filters.put(Policy.FilterOption.OWNER, new String[] {getUserOwner().getId()});
340
- } else {
341
- filters.put(Policy.FilterOption.OWNER, new String[] {getClientOwner().getId()});
342
- }
343
-
344
- List<Policy> policies =
345
- authorization
346
- .getStoreFactory()
347
- .getPolicyStore()
348
- .find(realm, resourceServer, filters, null, null);
349
-
350
- if (policies.isEmpty()) {
351
- return Collections.emptyList();
352
- }
353
-
354
- return policies.stream()
355
- .filter(
356
- policy -> {
357
- Map<PermissionTicket.FilterOption, String> filters1 =
358
- new EnumMap<>(PermissionTicket.FilterOption.class);
359
-
360
- filters1.put(PermissionTicket.FilterOption.POLICY_ID, policy.getId());
361
-
362
- return authorization
363
- .getStoreFactory()
364
- .getPermissionTicketStore()
365
- .find(realm, resourceServer, filters1, -1, 1)
366
- .isEmpty();
367
- })
368
- .map(ManagedPermissionBean::new)
369
- .collect(Collectors.toList());
370
- }
371
-
372
- public ResourceServerBean getResourceServer() {
373
- return resourceServer;
374
- }
375
-
376
- public Collection<RequesterBean> getPermissions() {
377
- return permissions.values();
378
- }
379
-
380
- private void addPermission(PermissionTicket ticket, AuthorizationProvider authorization) {
381
- permissions
382
- .computeIfAbsent(ticket.getRequester(), key -> new RequesterBean(ticket, authorization))
383
- .addScope(ticket);
384
- }
385
- }
386
-
387
- private Collection<RequesterBean> toPermissionRepresentation(
388
- List<PermissionTicket> permissionRequests) {
389
- Map<String, RequesterBean> requests = new HashMap<>();
390
-
391
- for (PermissionTicket ticket : permissionRequests) {
392
- Resource resource = ticket.getResource();
393
-
394
- if (!resource.isOwnerManagedAccess()) {
395
- continue;
396
- }
397
-
398
- requests
399
- .computeIfAbsent(
400
- ticket.getRequester(), resourceId -> new RequesterBean(ticket, authorization))
401
- .addScope(ticket);
402
- }
403
-
404
- return requests.values();
405
- }
406
-
407
- private Collection<ResourceBean> toResourceRepresentation(List<PermissionTicket> tickets) {
408
- Map<String, ResourceBean> requests = new HashMap<>();
409
-
410
- for (PermissionTicket ticket : tickets) {
411
- Resource resource = ticket.getResource();
412
-
413
- if (!resource.isOwnerManagedAccess()) {
414
- continue;
415
- }
416
-
417
- requests
418
- .computeIfAbsent(resource.getId(), resourceId -> getResource(resourceId))
419
- .addPermission(ticket, authorization);
420
- }
421
-
422
- return requests.values();
423
- }
424
-
425
- private List<PermissionTicket> findPermissions(
426
- Map<PermissionTicket.FilterOption, String> filters) {
427
- return authorization
428
- .getStoreFactory()
429
- .getPermissionTicketStore()
430
- .find(realm, null, filters, null, null);
431
- }
432
-
433
- public class ResourceServerBean {
434
-
435
- private ClientModel clientModel;
436
- private ResourceServer resourceServer;
437
-
438
- public ResourceServerBean(ClientModel clientModel, ResourceServer resourceServer) {
439
- this.clientModel = clientModel;
440
- this.resourceServer = resourceServer;
441
- }
442
-
443
- public String getId() {
444
- return resourceServer.getId();
445
- }
446
-
447
- public String getName() {
448
- String name = clientModel.getName();
449
-
450
- if (name != null) {
451
- return name;
452
- }
453
-
454
- return clientModel.getClientId();
455
- }
456
-
457
- public String getClientId() {
458
- return clientModel.getClientId();
459
- }
460
-
461
- public String getRedirectUri() {
462
- Set<String> redirectUris = clientModel.getRedirectUris();
463
-
464
- if (redirectUris.isEmpty()) {
465
- return null;
466
- }
467
-
468
- return redirectUris.iterator().next();
469
- }
470
-
471
- public String getBaseUri() {
472
- return ResolveRelative.resolveRelativeUri(
473
- session, clientModel.getRootUrl(), clientModel.getBaseUrl());
474
- }
475
-
476
- public ResourceServer getResourceServerModel() {
477
- return resourceServer;
478
- }
479
- }
480
-
481
- public class ManagedPermissionBean {
482
-
483
- private final Policy policy;
484
- private List<ManagedPermissionBean> policies;
485
-
486
- public ManagedPermissionBean(Policy policy) {
487
- this.policy = policy;
488
- }
489
-
490
- public String getId() {
491
- return policy.getId();
492
- }
493
-
494
- public Collection<ScopeRepresentation> getScopes() {
495
- return policy.getScopes().stream()
496
- .map(ModelToRepresentation::toRepresentation)
497
- .collect(Collectors.toList());
498
- }
499
-
500
- public String getDescription() {
501
- return this.policy.getDescription();
502
- }
503
-
504
- public Collection<ManagedPermissionBean> getPolicies() {
505
- if (this.policies == null) {
506
- this.policies =
507
- policy.getAssociatedPolicies().stream()
508
- .map(ManagedPermissionBean::new)
509
- .collect(Collectors.toList());
510
- }
511
-
512
- return this.policies;
513
- }
514
- }
515
- }
@@ -1,56 +0,0 @@
1
- /*
2
- * Copyright 2016 Red Hat, Inc. and/or its affiliates
3
- * and other contributors as indicated by the @author tags.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- package org.keycloak.forms.account.freemarker.model;
19
-
20
- /**
21
- * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
22
- */
23
- public class FeaturesBean {
24
-
25
- private final boolean identityFederation;
26
- private final boolean log;
27
- private final boolean passwordUpdateSupported;
28
- private boolean authorization;
29
-
30
- public FeaturesBean(
31
- boolean identityFederation,
32
- boolean log,
33
- boolean passwordUpdateSupported,
34
- boolean authorization) {
35
- this.identityFederation = identityFederation;
36
- this.log = log;
37
- this.passwordUpdateSupported = passwordUpdateSupported;
38
- this.authorization = authorization;
39
- }
40
-
41
- public boolean isIdentityFederation() {
42
- return identityFederation;
43
- }
44
-
45
- public boolean isLog() {
46
- return log;
47
- }
48
-
49
- public boolean isPasswordUpdateSupported() {
50
- return passwordUpdateSupported;
51
- }
52
-
53
- public boolean isAuthorization() {
54
- return authorization;
55
- }
56
- }
@@ -1,95 +0,0 @@
1
- /*
2
- * Copyright 2016 Red Hat, Inc. and/or its affiliates
3
- * and other contributors as indicated by the @author tags.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- package org.keycloak.forms.account.freemarker.model;
19
-
20
- import java.util.Date;
21
- import java.util.LinkedList;
22
- import java.util.List;
23
- import java.util.Map;
24
- import org.keycloak.events.Event;
25
-
26
- /**
27
- * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
28
- */
29
- public class LogBean {
30
-
31
- private List<EventBean> events;
32
-
33
- public LogBean(List<Event> events) {
34
- this.events = new LinkedList<EventBean>();
35
- for (Event e : events) {
36
- this.events.add(new EventBean(e));
37
- }
38
- }
39
-
40
- public List<EventBean> getEvents() {
41
- return events;
42
- }
43
-
44
- public static class EventBean {
45
-
46
- private Event event;
47
-
48
- public EventBean(Event event) {
49
- this.event = event;
50
- }
51
-
52
- public Date getDate() {
53
- return new Date(event.getTime());
54
- }
55
-
56
- public String getEvent() {
57
- return event.getType().toString().toLowerCase().replace("_", " ");
58
- }
59
-
60
- public String getClient() {
61
- return event.getClientId();
62
- }
63
-
64
- public String getIpAddress() {
65
- return event.getIpAddress();
66
- }
67
-
68
- public List<DetailBean> getDetails() {
69
- List<DetailBean> details = new LinkedList<DetailBean>();
70
- if (event.getDetails() != null) {
71
- for (Map.Entry<String, String> e : event.getDetails().entrySet()) {
72
- details.add(new DetailBean(e));
73
- }
74
- }
75
- return details;
76
- }
77
- }
78
-
79
- public static class DetailBean {
80
-
81
- private Map.Entry<String, String> entry;
82
-
83
- public DetailBean(Map.Entry<String, String> entry) {
84
- this.entry = entry;
85
- }
86
-
87
- public String getKey() {
88
- return entry.getKey();
89
- }
90
-
91
- public String getValue() {
92
- return entry.getValue().replace("_", " ");
93
- }
94
- }
95
- }
@@ -1,34 +0,0 @@
1
- /*
2
- * Copyright 2016 Red Hat, Inc. and/or its affiliates
3
- * and other contributors as indicated by the @author tags.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
-
18
- package org.keycloak.forms.account.freemarker.model;
19
-
20
- /**
21
- * @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
22
- */
23
- public class PasswordBean {
24
-
25
- private boolean passwordSet;
26
-
27
- public PasswordBean(boolean passwordSet) {
28
- this.passwordSet = passwordSet;
29
- }
30
-
31
- public boolean isPasswordSet() {
32
- return passwordSet;
33
- }
34
- }