keycloakify 8.0.0 → 9.0.0-rc.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.
- package/README.md +14 -54
- package/account/kcContext/KcContext.js.map +1 -1
- package/account/kcContext/createGetKcContext.js +2 -6
- package/account/kcContext/createGetKcContext.js.map +1 -1
- package/account/kcContext/kcContextMocks.js +4 -3
- package/account/kcContext/kcContextMocks.js.map +1 -1
- package/bin/constants.d.ts +7 -0
- package/bin/constants.js +10 -0
- package/bin/constants.js.map +1 -0
- package/bin/copy-keycloak-resources-to-public.js +34 -22
- package/bin/copy-keycloak-resources-to-public.js.map +1 -1
- package/bin/download-builtin-keycloak-theme.d.ts +4 -1
- package/bin/download-builtin-keycloak-theme.js +8 -6
- package/bin/download-builtin-keycloak-theme.js.map +1 -1
- package/bin/eject-keycloak-page.js +5 -3
- package/bin/eject-keycloak-page.js.map +1 -1
- package/bin/getSrcDirPath.d.ts +1 -1
- package/bin/getSrcDirPath.js +4 -4
- package/bin/getSrcDirPath.js.map +1 -1
- package/bin/initialize-email-theme.js +9 -9
- package/bin/initialize-email-theme.js.map +1 -1
- package/bin/keycloakify/BuildOptions.d.ts +8 -6
- package/bin/keycloakify/BuildOptions.js +63 -71
- package/bin/keycloakify/BuildOptions.js.map +1 -1
- package/bin/keycloakify/generateFtl/generateFtl.d.ts +2 -3
- package/bin/keycloakify/generateFtl/generateFtl.js +3 -4
- package/bin/keycloakify/generateFtl/generateFtl.js.map +1 -1
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountPages.java +33 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProvider.java +76 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProviderFactory.java +25 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountSpi.java +50 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProvider.java +424 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProviderFactory.java +51 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/Templates.java +51 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountBean.java +91 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountFederatedIdentityBean.java +157 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ApplicationsBean.java +258 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AuthorizationBean.java +515 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/FeaturesBean.java +56 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/LogBean.java +95 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/PasswordBean.java +34 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/RealmBean.java +75 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ReferrerBean.java +38 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/SessionsBean.java +93 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/TotpBean.java +125 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/UrlBean.java +121 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/AccountUrls.java +115 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormService.java +1320 -0
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormServiceFactory.java +64 -0
- package/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.d.ts +7 -0
- package/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.js +194 -0
- package/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.js.map +1 -0
- package/bin/keycloakify/{generateJavaStackFiles.d.ts → generateJavaStackFiles/generateJavaStackFiles.d.ts} +6 -6
- package/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.js +276 -0
- package/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.js.map +1 -0
- package/bin/keycloakify/generateJavaStackFiles/index.d.ts +1 -0
- package/bin/keycloakify/generateJavaStackFiles/index.js +18 -0
- package/bin/keycloakify/generateJavaStackFiles/index.js.map +1 -0
- package/bin/keycloakify/generateStartKeycloakTestingContainer.d.ts +1 -3
- package/bin/keycloakify/generateStartKeycloakTestingContainer.js +15 -6
- package/bin/keycloakify/generateStartKeycloakTestingContainer.js.map +1 -1
- package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.d.ts +5 -2
- package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.js +11 -8
- package/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.js.map +1 -1
- package/bin/keycloakify/generateTheme/generateMessageProperties.d.ts +1 -1
- package/bin/keycloakify/generateTheme/generateTheme.d.ts +6 -5
- package/bin/keycloakify/generateTheme/generateTheme.js +59 -49
- package/bin/keycloakify/generateTheme/generateTheme.js.map +1 -1
- package/bin/keycloakify/generateTheme/readExtraPageNames.d.ts +1 -1
- package/bin/keycloakify/generateTheme/readExtraPageNames.js.map +1 -1
- package/bin/keycloakify/generateTheme/readFieldNameUsage.d.ts +1 -1
- package/bin/keycloakify/generateTheme/readStaticResourcesUsage.d.ts +1 -1
- package/bin/keycloakify/keycloakify.js +49 -90
- package/bin/keycloakify/keycloakify.js.map +1 -1
- package/bin/keycloakify/parsedPackageJson.d.ts +29 -31
- package/bin/keycloakify/parsedPackageJson.js +7 -8
- package/bin/keycloakify/parsedPackageJson.js.map +1 -1
- package/bin/promptKeycloakVersion.js +1 -1
- package/bin/promptKeycloakVersion.js.map +1 -1
- package/bin/tools/downloadAndUnzip.d.ts +1 -1
- package/bin/tools/downloadAndUnzip.js +24 -26
- package/bin/tools/downloadAndUnzip.js.map +1 -1
- package/bin/tools/getAbsoluteAndInOsFormatPath.d.ts +4 -0
- package/bin/tools/getAbsoluteAndInOsFormatPath.js +15 -0
- package/bin/tools/getAbsoluteAndInOsFormatPath.js.map +1 -0
- package/bin/tools/pathJoin.js +1 -1
- package/bin/tools/pathJoin.js.map +1 -1
- package/login/kcContext/KcContext.js.map +1 -1
- package/login/kcContext/createGetKcContext.js +2 -6
- package/login/kcContext/createGetKcContext.js.map +1 -1
- package/login/kcContext/kcContextMocks.js +5 -4
- package/login/kcContext/kcContextMocks.js.map +1 -1
- package/package.json +92 -21
- package/src/account/kcContext/KcContext.ts +2 -1
- package/src/account/kcContext/createGetKcContext.ts +2 -7
- package/src/account/kcContext/kcContextMocks.ts +5 -3
- package/src/bin/constants.ts +9 -0
- package/src/bin/copy-keycloak-resources-to-public.ts +20 -19
- package/src/bin/download-builtin-keycloak-theme.ts +14 -6
- package/src/bin/eject-keycloak-page.ts +5 -9
- package/src/bin/getSrcDirPath.ts +4 -4
- package/src/bin/initialize-email-theme.ts +7 -7
- package/src/bin/keycloakify/BuildOptions.ts +78 -59
- package/src/bin/keycloakify/generateFtl/generateFtl.ts +4 -7
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountPages.java +33 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProvider.java +76 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProviderFactory.java +25 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountSpi.java +50 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProvider.java +424 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProviderFactory.java +51 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/Templates.java +51 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountBean.java +91 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountFederatedIdentityBean.java +157 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ApplicationsBean.java +258 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AuthorizationBean.java +515 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/FeaturesBean.java +56 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/LogBean.java +95 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/PasswordBean.java +34 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/RealmBean.java +75 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ReferrerBean.java +38 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/SessionsBean.java +93 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/TotpBean.java +125 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/UrlBean.java +121 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/AccountUrls.java +115 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormService.java +1320 -0
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormServiceFactory.java +64 -0
- package/src/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.ts +92 -0
- package/src/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.ts +211 -0
- package/src/bin/keycloakify/generateJavaStackFiles/index.ts +1 -0
- package/src/bin/keycloakify/generateStartKeycloakTestingContainer.ts +21 -22
- package/src/bin/keycloakify/generateTheme/downloadKeycloakStaticResources.ts +19 -15
- package/src/bin/keycloakify/generateTheme/generateMessageProperties.ts +1 -1
- package/src/bin/keycloakify/generateTheme/generateTheme.ts +78 -72
- package/src/bin/keycloakify/generateTheme/readExtraPageNames.ts +2 -1
- package/src/bin/keycloakify/generateTheme/readFieldNameUsage.ts +1 -1
- package/src/bin/keycloakify/generateTheme/readStaticResourcesUsage.ts +1 -1
- package/src/bin/keycloakify/keycloakify.ts +21 -44
- package/src/bin/keycloakify/parsedPackageJson.ts +11 -13
- package/src/bin/promptKeycloakVersion.ts +1 -1
- package/src/bin/tools/downloadAndUnzip.ts +6 -7
- package/src/bin/tools/getAbsoluteAndInOsFormatPath.ts +15 -0
- package/src/bin/tools/pathJoin.ts +1 -1
- package/src/login/kcContext/KcContext.ts +2 -1
- package/src/login/kcContext/createGetKcContext.ts +2 -7
- package/src/login/kcContext/kcContextMocks.ts +7 -5
- package/bin/keycloakify/generateJavaStackFiles.js +0 -103
- package/bin/keycloakify/generateJavaStackFiles.js.map +0 -1
- package/bin/mockTestingResourcesPath.d.ts +0 -3
- package/bin/mockTestingResourcesPath.js +0 -8
- package/bin/mockTestingResourcesPath.js.map +0 -1
- package/bin/tools/jar.d.ts +0 -33
- package/bin/tools/jar.js +0 -241
- package/bin/tools/jar.js.map +0 -1
- package/bin/tools/walk.d.ts +0 -8
- package/bin/tools/walk.js +0 -125
- package/bin/tools/walk.js.map +0 -1
- package/src/bin/keycloakify/generateJavaStackFiles.ts +0 -84
- package/src/bin/mockTestingResourcesPath.ts +0 -5
- package/src/bin/tools/jar.ts +0 -99
- package/src/bin/tools/walk.ts +0 -19
@@ -0,0 +1,75 @@
|
|
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
|
+
package org.keycloak.forms.account.freemarker.model;
|
18
|
+
|
19
|
+
import java.util.Set;
|
20
|
+
import java.util.stream.Collectors;
|
21
|
+
import org.keycloak.models.RealmModel;
|
22
|
+
|
23
|
+
/**
|
24
|
+
* @author <a href="mailto:gerbermichi@me.com">Michael Gerber</a>
|
25
|
+
*/
|
26
|
+
public class RealmBean {
|
27
|
+
|
28
|
+
private RealmModel realm;
|
29
|
+
|
30
|
+
public RealmBean(RealmModel realmModel) {
|
31
|
+
realm = realmModel;
|
32
|
+
}
|
33
|
+
|
34
|
+
public String getName() {
|
35
|
+
return realm.getName();
|
36
|
+
}
|
37
|
+
|
38
|
+
public String getDisplayName() {
|
39
|
+
String displayName = realm.getDisplayName();
|
40
|
+
if (displayName != null && displayName.length() > 0) {
|
41
|
+
return displayName;
|
42
|
+
} else {
|
43
|
+
return getName();
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
public String getDisplayNameHtml() {
|
48
|
+
String displayNameHtml = realm.getDisplayNameHtml();
|
49
|
+
if (displayNameHtml != null && displayNameHtml.length() > 0) {
|
50
|
+
return displayNameHtml;
|
51
|
+
} else {
|
52
|
+
return getDisplayName();
|
53
|
+
}
|
54
|
+
}
|
55
|
+
|
56
|
+
public boolean isInternationalizationEnabled() {
|
57
|
+
return realm.isInternationalizationEnabled();
|
58
|
+
}
|
59
|
+
|
60
|
+
public Set<String> getSupportedLocales() {
|
61
|
+
return realm.getSupportedLocalesStream().collect(Collectors.toSet());
|
62
|
+
}
|
63
|
+
|
64
|
+
public boolean isEditUsernameAllowed() {
|
65
|
+
return realm.isEditUsernameAllowed();
|
66
|
+
}
|
67
|
+
|
68
|
+
public boolean isRegistrationEmailAsUsername() {
|
69
|
+
return realm.isRegistrationEmailAsUsername();
|
70
|
+
}
|
71
|
+
|
72
|
+
public boolean isUserManagedAccessAllowed() {
|
73
|
+
return realm.isUserManagedAccessAllowed();
|
74
|
+
}
|
75
|
+
}
|
@@ -0,0 +1,38 @@
|
|
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 ReferrerBean {
|
24
|
+
|
25
|
+
private String[] referrer;
|
26
|
+
|
27
|
+
public ReferrerBean(String[] referrer) {
|
28
|
+
this.referrer = referrer;
|
29
|
+
}
|
30
|
+
|
31
|
+
public String getName() {
|
32
|
+
return referrer[0];
|
33
|
+
}
|
34
|
+
|
35
|
+
public String getUrl() {
|
36
|
+
return referrer[1];
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,93 @@
|
|
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.HashSet;
|
22
|
+
import java.util.LinkedList;
|
23
|
+
import java.util.List;
|
24
|
+
import java.util.Set;
|
25
|
+
import org.keycloak.common.util.Time;
|
26
|
+
import org.keycloak.models.ClientModel;
|
27
|
+
import org.keycloak.models.RealmModel;
|
28
|
+
import org.keycloak.models.UserSessionModel;
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
32
|
+
*/
|
33
|
+
public class SessionsBean {
|
34
|
+
|
35
|
+
private List<UserSessionBean> events;
|
36
|
+
private RealmModel realm;
|
37
|
+
|
38
|
+
public SessionsBean(RealmModel realm, List<UserSessionModel> sessions) {
|
39
|
+
this.events = new LinkedList<>();
|
40
|
+
for (UserSessionModel session : sessions) {
|
41
|
+
this.events.add(new UserSessionBean(realm, session));
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
public List<UserSessionBean> getSessions() {
|
46
|
+
return events;
|
47
|
+
}
|
48
|
+
|
49
|
+
public static class UserSessionBean {
|
50
|
+
|
51
|
+
private UserSessionModel session;
|
52
|
+
private RealmModel realm;
|
53
|
+
|
54
|
+
public UserSessionBean(RealmModel realm, UserSessionModel session) {
|
55
|
+
this.realm = realm;
|
56
|
+
this.session = session;
|
57
|
+
}
|
58
|
+
|
59
|
+
public String getId() {
|
60
|
+
return session.getId();
|
61
|
+
}
|
62
|
+
|
63
|
+
public String getIpAddress() {
|
64
|
+
return session.getIpAddress();
|
65
|
+
}
|
66
|
+
|
67
|
+
public Date getStarted() {
|
68
|
+
return Time.toDate(session.getStarted());
|
69
|
+
}
|
70
|
+
|
71
|
+
public Date getLastAccess() {
|
72
|
+
return Time.toDate(session.getLastSessionRefresh());
|
73
|
+
}
|
74
|
+
|
75
|
+
public Date getExpires() {
|
76
|
+
int maxLifespan =
|
77
|
+
session.isRememberMe() && realm.getSsoSessionMaxLifespanRememberMe() > 0
|
78
|
+
? realm.getSsoSessionMaxLifespanRememberMe()
|
79
|
+
: realm.getSsoSessionMaxLifespan();
|
80
|
+
int max = session.getStarted() + maxLifespan;
|
81
|
+
return Time.toDate(max);
|
82
|
+
}
|
83
|
+
|
84
|
+
public Set<String> getClients() {
|
85
|
+
Set<String> clients = new HashSet<>();
|
86
|
+
for (String clientUUID : session.getAuthenticatedClientSessions().keySet()) {
|
87
|
+
ClientModel client = realm.getClientById(clientUUID);
|
88
|
+
clients.add(client.getClientId());
|
89
|
+
}
|
90
|
+
return clients;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
@@ -0,0 +1,125 @@
|
|
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 static org.keycloak.utils.CredentialHelper.createUserStorageCredentialRepresentation;
|
21
|
+
|
22
|
+
import jakarta.ws.rs.core.UriBuilder;
|
23
|
+
import java.util.Collections;
|
24
|
+
import java.util.List;
|
25
|
+
import java.util.stream.Collectors;
|
26
|
+
import org.keycloak.authentication.otp.OTPApplicationProvider;
|
27
|
+
import org.keycloak.credential.CredentialModel;
|
28
|
+
import org.keycloak.models.KeycloakSession;
|
29
|
+
import org.keycloak.models.OTPPolicy;
|
30
|
+
import org.keycloak.models.RealmModel;
|
31
|
+
import org.keycloak.models.UserModel;
|
32
|
+
import org.keycloak.models.credential.OTPCredentialModel;
|
33
|
+
import org.keycloak.models.utils.HmacOTP;
|
34
|
+
import org.keycloak.models.utils.RepresentationToModel;
|
35
|
+
import org.keycloak.representations.idm.CredentialRepresentation;
|
36
|
+
import org.keycloak.utils.TotpUtils;
|
37
|
+
|
38
|
+
/**
|
39
|
+
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
40
|
+
*/
|
41
|
+
public class TotpBean {
|
42
|
+
|
43
|
+
private final RealmModel realm;
|
44
|
+
private final String totpSecret;
|
45
|
+
private final String totpSecretEncoded;
|
46
|
+
private final String totpSecretQrCode;
|
47
|
+
private final boolean enabled;
|
48
|
+
private KeycloakSession session;
|
49
|
+
private final UriBuilder uriBuilder;
|
50
|
+
private final List<CredentialModel> otpCredentials;
|
51
|
+
private final List<String> supportedApplications;
|
52
|
+
|
53
|
+
public TotpBean(
|
54
|
+
KeycloakSession session, RealmModel realm, UserModel user, UriBuilder uriBuilder) {
|
55
|
+
this.session = session;
|
56
|
+
this.uriBuilder = uriBuilder;
|
57
|
+
this.enabled = user.credentialManager().isConfiguredFor(OTPCredentialModel.TYPE);
|
58
|
+
if (enabled) {
|
59
|
+
List<CredentialModel> otpCredentials =
|
60
|
+
user.credentialManager()
|
61
|
+
.getStoredCredentialsByTypeStream(OTPCredentialModel.TYPE)
|
62
|
+
.collect(Collectors.toList());
|
63
|
+
|
64
|
+
if (otpCredentials.isEmpty()) {
|
65
|
+
// Credential is configured on userStorage side. Create the "fake" credential similar like
|
66
|
+
// we do for the new account console
|
67
|
+
CredentialRepresentation credential =
|
68
|
+
createUserStorageCredentialRepresentation(OTPCredentialModel.TYPE);
|
69
|
+
this.otpCredentials = Collections.singletonList(RepresentationToModel.toModel(credential));
|
70
|
+
} else {
|
71
|
+
this.otpCredentials = otpCredentials;
|
72
|
+
}
|
73
|
+
} else {
|
74
|
+
this.otpCredentials = Collections.EMPTY_LIST;
|
75
|
+
}
|
76
|
+
|
77
|
+
this.realm = realm;
|
78
|
+
this.totpSecret = HmacOTP.generateSecret(20);
|
79
|
+
this.totpSecretEncoded = TotpUtils.encode(totpSecret);
|
80
|
+
this.totpSecretQrCode = TotpUtils.qrCode(totpSecret, realm, user);
|
81
|
+
|
82
|
+
OTPPolicy otpPolicy = realm.getOTPPolicy();
|
83
|
+
this.supportedApplications =
|
84
|
+
session.getAllProviders(OTPApplicationProvider.class).stream()
|
85
|
+
.filter(p -> p.supports(otpPolicy))
|
86
|
+
.map(OTPApplicationProvider::getName)
|
87
|
+
.collect(Collectors.toList());
|
88
|
+
}
|
89
|
+
|
90
|
+
public boolean isEnabled() {
|
91
|
+
return enabled;
|
92
|
+
}
|
93
|
+
|
94
|
+
public String getTotpSecret() {
|
95
|
+
return totpSecret;
|
96
|
+
}
|
97
|
+
|
98
|
+
public String getTotpSecretEncoded() {
|
99
|
+
return totpSecretEncoded;
|
100
|
+
}
|
101
|
+
|
102
|
+
public String getTotpSecretQrCode() {
|
103
|
+
return totpSecretQrCode;
|
104
|
+
}
|
105
|
+
|
106
|
+
public String getManualUrl() {
|
107
|
+
return uriBuilder.replaceQueryParam("mode", "manual").build().toString();
|
108
|
+
}
|
109
|
+
|
110
|
+
public String getQrUrl() {
|
111
|
+
return uriBuilder.replaceQueryParam("mode", "qr").build().toString();
|
112
|
+
}
|
113
|
+
|
114
|
+
public OTPPolicy getPolicy() {
|
115
|
+
return realm.getOTPPolicy();
|
116
|
+
}
|
117
|
+
|
118
|
+
public List<String> getSupportedApplications() {
|
119
|
+
return supportedApplications;
|
120
|
+
}
|
121
|
+
|
122
|
+
public List<CredentialModel> getOtpCredentials() {
|
123
|
+
return otpCredentials;
|
124
|
+
}
|
125
|
+
}
|
@@ -0,0 +1,121 @@
|
|
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.io.IOException;
|
21
|
+
import java.net.URI;
|
22
|
+
import org.jboss.logging.Logger;
|
23
|
+
import org.keycloak.models.RealmModel;
|
24
|
+
import org.keycloak.services.AccountUrls;
|
25
|
+
import org.keycloak.theme.Theme;
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
29
|
+
*/
|
30
|
+
public class UrlBean {
|
31
|
+
|
32
|
+
private static final Logger logger = Logger.getLogger(UrlBean.class);
|
33
|
+
private String realm;
|
34
|
+
private Theme theme;
|
35
|
+
private URI baseURI;
|
36
|
+
private URI baseQueryURI;
|
37
|
+
private URI currentURI;
|
38
|
+
private String idTokenHint;
|
39
|
+
|
40
|
+
public UrlBean(
|
41
|
+
RealmModel realm,
|
42
|
+
Theme theme,
|
43
|
+
URI baseURI,
|
44
|
+
URI baseQueryURI,
|
45
|
+
URI currentURI,
|
46
|
+
String idTokenHint) {
|
47
|
+
this.realm = realm.getName();
|
48
|
+
this.theme = theme;
|
49
|
+
this.baseURI = baseURI;
|
50
|
+
this.baseQueryURI = baseQueryURI;
|
51
|
+
this.currentURI = currentURI;
|
52
|
+
this.idTokenHint = idTokenHint;
|
53
|
+
}
|
54
|
+
|
55
|
+
public String getApplicationsUrl() {
|
56
|
+
return AccountUrls.accountApplicationsPage(baseQueryURI, realm).toString();
|
57
|
+
}
|
58
|
+
|
59
|
+
public String getAccountUrl() {
|
60
|
+
return AccountUrls.accountPage(baseQueryURI, realm).toString();
|
61
|
+
}
|
62
|
+
|
63
|
+
public String getPasswordUrl() {
|
64
|
+
return AccountUrls.accountPasswordPage(baseQueryURI, realm).toString();
|
65
|
+
}
|
66
|
+
|
67
|
+
public String getSocialUrl() {
|
68
|
+
return AccountUrls.accountFederatedIdentityPage(baseQueryURI, realm).toString();
|
69
|
+
}
|
70
|
+
|
71
|
+
public String getTotpUrl() {
|
72
|
+
return AccountUrls.accountTotpPage(baseQueryURI, realm).toString();
|
73
|
+
}
|
74
|
+
|
75
|
+
public String getLogUrl() {
|
76
|
+
return AccountUrls.accountLogPage(baseQueryURI, realm).toString();
|
77
|
+
}
|
78
|
+
|
79
|
+
public String getSessionsUrl() {
|
80
|
+
return AccountUrls.accountSessionsPage(baseQueryURI, realm).toString();
|
81
|
+
}
|
82
|
+
|
83
|
+
public String getLogoutUrl() {
|
84
|
+
return AccountUrls.accountLogout(baseQueryURI, currentURI, realm, idTokenHint).toString();
|
85
|
+
}
|
86
|
+
|
87
|
+
public String getResourceUrl() {
|
88
|
+
return AccountUrls.accountResourcesPage(baseQueryURI, realm).toString();
|
89
|
+
}
|
90
|
+
|
91
|
+
public String getResourceDetailUrl(String id) {
|
92
|
+
return AccountUrls.accountResourceDetailPage(id, baseQueryURI, realm).toString();
|
93
|
+
}
|
94
|
+
|
95
|
+
public String getResourceGrant(String id) {
|
96
|
+
return AccountUrls.accountResourceGrant(id, baseQueryURI, realm).toString();
|
97
|
+
}
|
98
|
+
|
99
|
+
public String getResourceShare(String id) {
|
100
|
+
return AccountUrls.accountResourceShare(id, baseQueryURI, realm).toString();
|
101
|
+
}
|
102
|
+
|
103
|
+
public String getResourcesPath() {
|
104
|
+
URI uri = AccountUrls.themeRoot(baseURI);
|
105
|
+
return uri.getPath() + "/" + theme.getType().toString().toLowerCase() + "/" + theme.getName();
|
106
|
+
}
|
107
|
+
|
108
|
+
public String getResourcesCommonPath() {
|
109
|
+
URI uri = AccountUrls.themeRoot(baseURI);
|
110
|
+
String commonPath = "";
|
111
|
+
try {
|
112
|
+
commonPath = theme.getProperties().getProperty("import");
|
113
|
+
} catch (IOException ex) {
|
114
|
+
logger.warn("Failed to load properties", ex);
|
115
|
+
}
|
116
|
+
if (commonPath == null || commonPath.isEmpty()) {
|
117
|
+
commonPath = "/common/keycloak";
|
118
|
+
}
|
119
|
+
return uri.getPath() + "/" + commonPath;
|
120
|
+
}
|
121
|
+
}
|
@@ -0,0 +1,115 @@
|
|
1
|
+
package org.keycloak.services;
|
2
|
+
|
3
|
+
import jakarta.ws.rs.core.UriBuilder;
|
4
|
+
import java.net.URI;
|
5
|
+
import lombok.extern.jbosslog.JBossLog;
|
6
|
+
import org.keycloak.OAuth2Constants;
|
7
|
+
import org.keycloak.protocol.oidc.OIDCLoginProtocol;
|
8
|
+
import org.keycloak.protocol.oidc.OIDCLoginProtocolService;
|
9
|
+
import org.keycloak.services.resources.LoginActionsService;
|
10
|
+
import org.keycloak.services.resources.RealmsResource;
|
11
|
+
import org.keycloak.services.resources.account.AccountFormService;
|
12
|
+
|
13
|
+
@JBossLog
|
14
|
+
public class AccountUrls extends Urls {
|
15
|
+
|
16
|
+
private static UriBuilder realmLogout(URI baseUri) {
|
17
|
+
return tokenBase(baseUri).path(OIDCLoginProtocolService.class, "logout");
|
18
|
+
}
|
19
|
+
|
20
|
+
public static UriBuilder accountBase(URI baseUri) {
|
21
|
+
return realmBase(baseUri).path(RealmsResource.class, "getAccountService");
|
22
|
+
}
|
23
|
+
|
24
|
+
private static UriBuilder tokenBase(URI baseUri) {
|
25
|
+
return realmBase(baseUri).path("{realm}/protocol/" + OIDCLoginProtocol.LOGIN_PROTOCOL);
|
26
|
+
}
|
27
|
+
|
28
|
+
public static URI accountApplicationsPage(URI baseUri, String realmName) {
|
29
|
+
return accountBase(baseUri).path(AccountFormService.class, "applicationsPage").build(realmName);
|
30
|
+
}
|
31
|
+
|
32
|
+
public static URI accountPage(URI baseUri, String realmName) {
|
33
|
+
return accountPageBuilder(baseUri).build(realmName);
|
34
|
+
}
|
35
|
+
|
36
|
+
public static UriBuilder accountPageBuilder(URI baseUri) {
|
37
|
+
return accountBase(baseUri).path(AccountFormService.class, "accountPage");
|
38
|
+
}
|
39
|
+
|
40
|
+
public static URI accountPasswordPage(URI baseUri, String realmName) {
|
41
|
+
return accountBase(baseUri).path(AccountFormService.class, "passwordPage").build(realmName);
|
42
|
+
}
|
43
|
+
|
44
|
+
public static URI accountFederatedIdentityPage(URI baseUri, String realmName) {
|
45
|
+
return accountBase(baseUri)
|
46
|
+
.path(AccountFormService.class, "federatedIdentityPage")
|
47
|
+
.build(realmName);
|
48
|
+
}
|
49
|
+
|
50
|
+
public static URI accountFederatedIdentityUpdate(URI baseUri, String realmName) {
|
51
|
+
return accountBase(baseUri)
|
52
|
+
.path(AccountFormService.class, "processFederatedIdentityUpdate")
|
53
|
+
.build(realmName);
|
54
|
+
}
|
55
|
+
|
56
|
+
public static URI accountTotpPage(URI baseUri, String realmName) {
|
57
|
+
return accountBase(baseUri).path(AccountFormService.class, "totpPage").build(realmName);
|
58
|
+
}
|
59
|
+
|
60
|
+
public static URI accountLogPage(URI baseUri, String realmName) {
|
61
|
+
return accountBase(baseUri).path(AccountFormService.class, "logPage").build(realmName);
|
62
|
+
}
|
63
|
+
|
64
|
+
public static URI accountSessionsPage(URI baseUri, String realmName) {
|
65
|
+
return accountBase(baseUri).path(AccountFormService.class, "sessionsPage").build(realmName);
|
66
|
+
}
|
67
|
+
|
68
|
+
public static URI accountLogout(
|
69
|
+
URI baseUri, URI redirectUri, String realmName, String idTokenHint) {
|
70
|
+
return realmLogout(baseUri)
|
71
|
+
.queryParam(OAuth2Constants.POST_LOGOUT_REDIRECT_URI, redirectUri)
|
72
|
+
.queryParam(OAuth2Constants.ID_TOKEN_HINT, idTokenHint)
|
73
|
+
.build(realmName);
|
74
|
+
}
|
75
|
+
|
76
|
+
public static URI accountResourcesPage(URI baseUri, String realmName) {
|
77
|
+
return accountBase(baseUri).path(AccountFormService.class, "resourcesPage").build(realmName);
|
78
|
+
}
|
79
|
+
|
80
|
+
public static URI accountResourceDetailPage(String resourceId, URI baseUri, String realmName) {
|
81
|
+
return accountBase(baseUri)
|
82
|
+
.path(AccountFormService.class, "resourceDetailPage")
|
83
|
+
.build(realmName, resourceId);
|
84
|
+
}
|
85
|
+
|
86
|
+
public static URI accountResourceGrant(String resourceId, URI baseUri, String realmName) {
|
87
|
+
return accountBase(baseUri)
|
88
|
+
.path(AccountFormService.class, "grantPermission")
|
89
|
+
.build(realmName, resourceId);
|
90
|
+
}
|
91
|
+
|
92
|
+
public static URI accountResourceShare(String resourceId, URI baseUri, String realmName) {
|
93
|
+
return accountBase(baseUri)
|
94
|
+
.path(AccountFormService.class, "shareResource")
|
95
|
+
.build(realmName, resourceId);
|
96
|
+
}
|
97
|
+
|
98
|
+
public static URI loginActionUpdatePassword(URI baseUri, String realmName) {
|
99
|
+
return loginActionsBase(baseUri)
|
100
|
+
.path(LoginActionsService.class, "updatePassword")
|
101
|
+
.build(realmName);
|
102
|
+
}
|
103
|
+
|
104
|
+
public static URI loginActionUpdateTotp(URI baseUri, String realmName) {
|
105
|
+
return loginActionsBase(baseUri).path(LoginActionsService.class, "updateTotp").build(realmName);
|
106
|
+
}
|
107
|
+
|
108
|
+
public static URI loginActionEmailVerification(URI baseUri, String realmName) {
|
109
|
+
return loginActionEmailVerificationBuilder(baseUri).build(realmName);
|
110
|
+
}
|
111
|
+
|
112
|
+
public static String localeCookiePath(URI baseUri, String realmName) {
|
113
|
+
return realmBase(baseUri).path(realmName).build().getRawPath();
|
114
|
+
}
|
115
|
+
}
|