keycloakify 9.0.0-rc.1 → 9.1.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 +9 -18
- package/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.js +0 -4
- package/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.js.map +1 -1
- package/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.js +32 -103
- package/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.js.map +1 -1
- package/bin/keycloakify/generateStartKeycloakTestingContainer.d.ts +1 -0
- package/bin/keycloakify/generateStartKeycloakTestingContainer.js +4 -3
- package/bin/keycloakify/generateStartKeycloakTestingContainer.js.map +1 -1
- package/bin/keycloakify/keycloakify.js +2 -1
- package/bin/keycloakify/keycloakify.js.map +1 -1
- package/login/kcContext/KcContext.d.ts +1 -0
- package/login/kcContext/KcContext.js.map +1 -1
- package/login/kcContext/kcContextMocks.js +8 -4
- package/login/kcContext/kcContextMocks.js.map +1 -1
- package/login/pages/LoginDeviceVerifyUserCode.js +1 -2
- package/login/pages/LoginDeviceVerifyUserCode.js.map +1 -1
- package/login/pages/LoginOauthGrant.js +1 -2
- package/login/pages/LoginOauthGrant.js.map +1 -1
- package/package.json +1 -67
- package/src/bin/keycloakify/generateJavaStackFiles/bringInAccountV1.ts +0 -5
- package/src/bin/keycloakify/generateJavaStackFiles/generateJavaStackFiles.ts +32 -103
- package/src/bin/keycloakify/generateStartKeycloakTestingContainer.ts +11 -4
- package/src/bin/keycloakify/keycloakify.ts +2 -1
- package/src/login/kcContext/KcContext.ts +1 -0
- package/src/login/kcContext/kcContextMocks.ts +8 -4
- package/src/login/pages/LoginDeviceVerifyUserCode.tsx +1 -2
- package/src/login/pages/LoginOauthGrant.tsx +1 -2
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountPages.java +0 -33
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProvider.java +0 -76
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProviderFactory.java +0 -25
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountSpi.java +0 -50
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProvider.java +0 -424
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProviderFactory.java +0 -51
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/Templates.java +0 -51
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountBean.java +0 -91
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountFederatedIdentityBean.java +0 -157
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ApplicationsBean.java +0 -258
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AuthorizationBean.java +0 -515
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/FeaturesBean.java +0 -56
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/LogBean.java +0 -95
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/PasswordBean.java +0 -34
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/RealmBean.java +0 -75
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ReferrerBean.java +0 -38
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/SessionsBean.java +0 -93
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/TotpBean.java +0 -125
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/UrlBean.java +0 -121
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/AccountUrls.java +0 -115
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormService.java +0 -1310
- package/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormServiceFactory.java +0 -64
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountPages.java +0 -33
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProvider.java +0 -76
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountProviderFactory.java +0 -25
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountSpi.java +0 -50
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProvider.java +0 -424
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/FreeMarkerAccountProviderFactory.java +0 -51
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/Templates.java +0 -51
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountBean.java +0 -91
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AccountFederatedIdentityBean.java +0 -157
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ApplicationsBean.java +0 -258
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/AuthorizationBean.java +0 -515
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/FeaturesBean.java +0 -56
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/LogBean.java +0 -95
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/PasswordBean.java +0 -34
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/RealmBean.java +0 -75
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/ReferrerBean.java +0 -38
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/SessionsBean.java +0 -93
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/TotpBean.java +0 -125
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/freemarker/model/UrlBean.java +0 -121
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/AccountUrls.java +0 -115
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormService.java +0 -1310
- package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/services/resources/account/AccountFormServiceFactory.java +0 -64
@@ -1,64 +0,0 @@
|
|
1
|
-
package org.keycloak.services.resources.account;
|
2
|
-
|
3
|
-
import com.google.auto.service.AutoService;
|
4
|
-
import com.google.common.collect.ImmutableMap;
|
5
|
-
import com.google.common.collect.ImmutableSet;
|
6
|
-
import java.util.Map;
|
7
|
-
import lombok.extern.jbosslog.JBossLog;
|
8
|
-
import org.keycloak.Config.Scope;
|
9
|
-
import org.keycloak.events.EventBuilder;
|
10
|
-
import org.keycloak.models.ClientModel;
|
11
|
-
import org.keycloak.models.KeycloakSession;
|
12
|
-
import org.keycloak.models.KeycloakSessionFactory;
|
13
|
-
import org.keycloak.models.ProtocolMapperModel;
|
14
|
-
import org.keycloak.models.RealmModel;
|
15
|
-
import org.keycloak.provider.ProviderEvent;
|
16
|
-
import org.keycloak.services.resource.AccountResourceProvider;
|
17
|
-
import org.keycloak.services.resource.AccountResourceProviderFactory;
|
18
|
-
import jakarta.ws.rs.NotFoundException;
|
19
|
-
import org.keycloak.models.Constants;
|
20
|
-
|
21
|
-
@JBossLog
|
22
|
-
@AutoService(AccountResourceProviderFactory.class)
|
23
|
-
public class AccountFormServiceFactory implements AccountResourceProviderFactory {
|
24
|
-
|
25
|
-
public static final String ID = "account-v1";
|
26
|
-
|
27
|
-
@Override
|
28
|
-
public String getId() {
|
29
|
-
return ID;
|
30
|
-
}
|
31
|
-
|
32
|
-
private ClientModel getAccountManagementClient(RealmModel realm) {
|
33
|
-
ClientModel client = realm.getClientByClientId(Constants.ACCOUNT_MANAGEMENT_CLIENT_ID);
|
34
|
-
if (client == null || !client.isEnabled()) {
|
35
|
-
log.debug("account management not enabled");
|
36
|
-
throw new NotFoundException("account management not enabled");
|
37
|
-
}
|
38
|
-
return client;
|
39
|
-
}
|
40
|
-
|
41
|
-
@Override
|
42
|
-
public AccountResourceProvider create(KeycloakSession session) {
|
43
|
-
log.info("create");
|
44
|
-
RealmModel realm = session.getContext().getRealm();
|
45
|
-
ClientModel client = getAccountManagementClient(realm);
|
46
|
-
EventBuilder event = new EventBuilder(realm, session, session.getContext().getConnection());
|
47
|
-
return new AccountFormService(session, client, event);
|
48
|
-
}
|
49
|
-
|
50
|
-
@Override
|
51
|
-
public void init(Scope config) {
|
52
|
-
log.info("init");
|
53
|
-
}
|
54
|
-
|
55
|
-
@Override
|
56
|
-
public void postInit(KeycloakSessionFactory factory) {
|
57
|
-
log.info("postInit");
|
58
|
-
}
|
59
|
-
|
60
|
-
@Override
|
61
|
-
public void close() {
|
62
|
-
log.info("close");
|
63
|
-
}
|
64
|
-
}
|
package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountPages.java
DELETED
@@ -1,33 +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;
|
19
|
-
|
20
|
-
/**
|
21
|
-
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
22
|
-
*/
|
23
|
-
public enum AccountPages {
|
24
|
-
ACCOUNT,
|
25
|
-
PASSWORD,
|
26
|
-
TOTP,
|
27
|
-
FEDERATED_IDENTITY,
|
28
|
-
LOG,
|
29
|
-
SESSIONS,
|
30
|
-
APPLICATIONS,
|
31
|
-
RESOURCES,
|
32
|
-
RESOURCE_DETAIL;
|
33
|
-
}
|
@@ -1,76 +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;
|
19
|
-
|
20
|
-
import jakarta.ws.rs.core.HttpHeaders;
|
21
|
-
import jakarta.ws.rs.core.MultivaluedMap;
|
22
|
-
import jakarta.ws.rs.core.Response;
|
23
|
-
import jakarta.ws.rs.core.UriInfo;
|
24
|
-
import java.util.List;
|
25
|
-
import org.keycloak.events.Event;
|
26
|
-
import org.keycloak.models.RealmModel;
|
27
|
-
import org.keycloak.models.UserModel;
|
28
|
-
import org.keycloak.models.UserSessionModel;
|
29
|
-
import org.keycloak.models.utils.FormMessage;
|
30
|
-
import org.keycloak.provider.Provider;
|
31
|
-
|
32
|
-
/**
|
33
|
-
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
34
|
-
*/
|
35
|
-
public interface AccountProvider extends Provider {
|
36
|
-
|
37
|
-
AccountProvider setUriInfo(UriInfo uriInfo);
|
38
|
-
|
39
|
-
AccountProvider setHttpHeaders(HttpHeaders httpHeaders);
|
40
|
-
|
41
|
-
Response createResponse(AccountPages page);
|
42
|
-
|
43
|
-
AccountProvider setError(Response.Status status, String message, Object... parameters);
|
44
|
-
|
45
|
-
AccountProvider setErrors(Response.Status status, List<FormMessage> messages);
|
46
|
-
|
47
|
-
AccountProvider setSuccess(String message, Object... parameters);
|
48
|
-
|
49
|
-
AccountProvider setWarning(String message, Object... parameters);
|
50
|
-
|
51
|
-
AccountProvider setUser(UserModel user);
|
52
|
-
|
53
|
-
AccountProvider setProfileFormData(MultivaluedMap<String, String> formData);
|
54
|
-
|
55
|
-
AccountProvider setRealm(RealmModel realm);
|
56
|
-
|
57
|
-
AccountProvider setReferrer(String[] referrer);
|
58
|
-
|
59
|
-
AccountProvider setEvents(List<Event> events);
|
60
|
-
|
61
|
-
AccountProvider setSessions(List<UserSessionModel> sessions);
|
62
|
-
|
63
|
-
AccountProvider setPasswordSet(boolean passwordSet);
|
64
|
-
|
65
|
-
AccountProvider setStateChecker(String stateChecker);
|
66
|
-
|
67
|
-
AccountProvider setIdTokenHint(String idTokenHint);
|
68
|
-
|
69
|
-
AccountProvider setFeatures(
|
70
|
-
boolean social,
|
71
|
-
boolean events,
|
72
|
-
boolean passwordUpdateSupported,
|
73
|
-
boolean authorizationSupported);
|
74
|
-
|
75
|
-
AccountProvider setAttribute(String key, String value);
|
76
|
-
}
|
@@ -1,25 +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;
|
19
|
-
|
20
|
-
import org.keycloak.provider.ProviderFactory;
|
21
|
-
|
22
|
-
/**
|
23
|
-
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
24
|
-
*/
|
25
|
-
public interface AccountProviderFactory extends ProviderFactory<AccountProvider> {}
|
package/src/bin/keycloakify/generateJavaStackFiles/account-v1-java/forms/account/AccountSpi.java
DELETED
@@ -1,50 +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;
|
19
|
-
|
20
|
-
import com.google.auto.service.AutoService;
|
21
|
-
import org.keycloak.provider.Provider;
|
22
|
-
import org.keycloak.provider.ProviderFactory;
|
23
|
-
import org.keycloak.provider.Spi;
|
24
|
-
|
25
|
-
/**
|
26
|
-
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
27
|
-
*/
|
28
|
-
@AutoService(Spi.class)
|
29
|
-
public class AccountSpi implements Spi {
|
30
|
-
|
31
|
-
@Override
|
32
|
-
public boolean isInternal() {
|
33
|
-
return true;
|
34
|
-
}
|
35
|
-
|
36
|
-
@Override
|
37
|
-
public String getName() {
|
38
|
-
return "account";
|
39
|
-
}
|
40
|
-
|
41
|
-
@Override
|
42
|
-
public Class<? extends Provider> getProviderClass() {
|
43
|
-
return AccountProvider.class;
|
44
|
-
}
|
45
|
-
|
46
|
-
@Override
|
47
|
-
public Class<? extends ProviderFactory> getProviderFactoryClass() {
|
48
|
-
return AccountProviderFactory.class;
|
49
|
-
}
|
50
|
-
}
|
@@ -1,424 +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
|
-
package org.keycloak.forms.account.freemarker;
|
18
|
-
|
19
|
-
import jakarta.ws.rs.core.HttpHeaders;
|
20
|
-
import jakarta.ws.rs.core.MultivaluedMap;
|
21
|
-
import jakarta.ws.rs.core.Response;
|
22
|
-
import jakarta.ws.rs.core.Response.Status;
|
23
|
-
import jakarta.ws.rs.core.UriBuilder;
|
24
|
-
import jakarta.ws.rs.core.UriInfo;
|
25
|
-
import java.io.IOException;
|
26
|
-
import java.net.URI;
|
27
|
-
import java.text.MessageFormat;
|
28
|
-
import java.util.ArrayList;
|
29
|
-
import java.util.HashMap;
|
30
|
-
import java.util.List;
|
31
|
-
import java.util.Locale;
|
32
|
-
import java.util.Map;
|
33
|
-
import java.util.Properties;
|
34
|
-
import org.jboss.logging.Logger;
|
35
|
-
import org.keycloak.events.Event;
|
36
|
-
import org.keycloak.forms.account.AccountPages;
|
37
|
-
import org.keycloak.forms.account.AccountProvider;
|
38
|
-
import org.keycloak.forms.account.freemarker.model.AccountBean;
|
39
|
-
import org.keycloak.forms.account.freemarker.model.AccountFederatedIdentityBean;
|
40
|
-
import org.keycloak.forms.account.freemarker.model.ApplicationsBean;
|
41
|
-
import org.keycloak.forms.account.freemarker.model.AuthorizationBean;
|
42
|
-
import org.keycloak.forms.account.freemarker.model.FeaturesBean;
|
43
|
-
import org.keycloak.forms.account.freemarker.model.LogBean;
|
44
|
-
import org.keycloak.forms.account.freemarker.model.PasswordBean;
|
45
|
-
import org.keycloak.forms.account.freemarker.model.RealmBean;
|
46
|
-
import org.keycloak.forms.account.freemarker.model.ReferrerBean;
|
47
|
-
import org.keycloak.forms.account.freemarker.model.SessionsBean;
|
48
|
-
import org.keycloak.forms.account.freemarker.model.TotpBean;
|
49
|
-
import org.keycloak.forms.account.freemarker.model.UrlBean;
|
50
|
-
import org.keycloak.forms.login.MessageType;
|
51
|
-
import org.keycloak.models.KeycloakSession;
|
52
|
-
import org.keycloak.models.RealmModel;
|
53
|
-
import org.keycloak.models.UserModel;
|
54
|
-
import org.keycloak.models.UserSessionModel;
|
55
|
-
import org.keycloak.models.utils.FormMessage;
|
56
|
-
import org.keycloak.services.util.CacheControlUtil;
|
57
|
-
import org.keycloak.theme.FreeMarkerException;
|
58
|
-
import org.keycloak.theme.Theme;
|
59
|
-
import org.keycloak.theme.beans.AdvancedMessageFormatterMethod;
|
60
|
-
import org.keycloak.theme.beans.LocaleBean;
|
61
|
-
import org.keycloak.theme.beans.MessageBean;
|
62
|
-
import org.keycloak.theme.beans.MessageFormatterMethod;
|
63
|
-
import org.keycloak.theme.beans.MessagesPerFieldBean;
|
64
|
-
import org.keycloak.theme.freemarker.FreeMarkerProvider;
|
65
|
-
import org.keycloak.utils.MediaType;
|
66
|
-
import org.keycloak.utils.StringUtil;
|
67
|
-
|
68
|
-
/**
|
69
|
-
* @author <a href="mailto:sthorger@redhat.com">Stian Thorgersen</a>
|
70
|
-
*/
|
71
|
-
public class FreeMarkerAccountProvider implements AccountProvider {
|
72
|
-
|
73
|
-
private static final Logger logger = Logger.getLogger(FreeMarkerAccountProvider.class);
|
74
|
-
|
75
|
-
protected UserModel user;
|
76
|
-
protected MultivaluedMap<String, String> profileFormData;
|
77
|
-
protected Response.Status status = Response.Status.OK;
|
78
|
-
protected RealmModel realm;
|
79
|
-
protected String[] referrer;
|
80
|
-
protected List<Event> events;
|
81
|
-
protected String stateChecker;
|
82
|
-
protected String idTokenHint;
|
83
|
-
protected List<UserSessionModel> sessions;
|
84
|
-
protected boolean identityProviderEnabled;
|
85
|
-
protected boolean eventsEnabled;
|
86
|
-
protected boolean passwordUpdateSupported;
|
87
|
-
protected boolean passwordSet;
|
88
|
-
protected KeycloakSession session;
|
89
|
-
protected FreeMarkerProvider freeMarker;
|
90
|
-
protected HttpHeaders headers;
|
91
|
-
protected Map<String, Object> attributes;
|
92
|
-
|
93
|
-
protected UriInfo uriInfo;
|
94
|
-
|
95
|
-
protected List<FormMessage> messages = null;
|
96
|
-
protected MessageType messageType = MessageType.ERROR;
|
97
|
-
private boolean authorizationSupported;
|
98
|
-
|
99
|
-
public FreeMarkerAccountProvider(KeycloakSession session) {
|
100
|
-
this.session = session;
|
101
|
-
this.freeMarker = session.getProvider(FreeMarkerProvider.class);
|
102
|
-
}
|
103
|
-
|
104
|
-
public AccountProvider setUriInfo(UriInfo uriInfo) {
|
105
|
-
this.uriInfo = uriInfo;
|
106
|
-
return this;
|
107
|
-
}
|
108
|
-
|
109
|
-
@Override
|
110
|
-
public AccountProvider setHttpHeaders(HttpHeaders httpHeaders) {
|
111
|
-
this.headers = httpHeaders;
|
112
|
-
return this;
|
113
|
-
}
|
114
|
-
|
115
|
-
@Override
|
116
|
-
public Response createResponse(AccountPages page) {
|
117
|
-
Map<String, Object> attributes = new HashMap<>();
|
118
|
-
|
119
|
-
if (this.attributes != null) {
|
120
|
-
attributes.putAll(this.attributes);
|
121
|
-
}
|
122
|
-
|
123
|
-
Theme theme;
|
124
|
-
try {
|
125
|
-
theme = getTheme();
|
126
|
-
} catch (IOException e) {
|
127
|
-
logger.error("Failed to create theme", e);
|
128
|
-
return Response.serverError().build();
|
129
|
-
}
|
130
|
-
|
131
|
-
Locale locale = session.getContext().resolveLocale(user);
|
132
|
-
Properties messagesBundle = handleThemeResources(theme, locale, attributes);
|
133
|
-
|
134
|
-
URI baseUri = uriInfo.getBaseUri();
|
135
|
-
UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
|
136
|
-
for (Map.Entry<String, List<String>> e : uriInfo.getQueryParameters().entrySet()) {
|
137
|
-
baseUriBuilder.queryParam(e.getKey(), e.getValue().toArray());
|
138
|
-
}
|
139
|
-
URI baseQueryUri = baseUriBuilder.build();
|
140
|
-
|
141
|
-
if (stateChecker != null) {
|
142
|
-
attributes.put("stateChecker", stateChecker);
|
143
|
-
}
|
144
|
-
|
145
|
-
handleMessages(locale, messagesBundle, attributes);
|
146
|
-
|
147
|
-
if (referrer != null) {
|
148
|
-
attributes.put("referrer", new ReferrerBean(referrer));
|
149
|
-
}
|
150
|
-
|
151
|
-
if (realm != null) {
|
152
|
-
attributes.put("realm", new RealmBean(realm));
|
153
|
-
}
|
154
|
-
|
155
|
-
attributes.put(
|
156
|
-
"url",
|
157
|
-
new UrlBean(realm, theme, baseUri, baseQueryUri, uriInfo.getRequestUri(), idTokenHint));
|
158
|
-
|
159
|
-
if (realm.isInternationalizationEnabled()) {
|
160
|
-
UriBuilder b = UriBuilder.fromUri(baseQueryUri).path(uriInfo.getPath());
|
161
|
-
attributes.put("locale", new LocaleBean(realm, locale, b, messagesBundle));
|
162
|
-
}
|
163
|
-
|
164
|
-
attributes.put(
|
165
|
-
"features",
|
166
|
-
new FeaturesBean(
|
167
|
-
identityProviderEnabled,
|
168
|
-
eventsEnabled,
|
169
|
-
passwordUpdateSupported,
|
170
|
-
authorizationSupported));
|
171
|
-
attributes.put("account", new AccountBean(user, profileFormData));
|
172
|
-
|
173
|
-
switch (page) {
|
174
|
-
case TOTP:
|
175
|
-
attributes.put("totp", new TotpBean(session, realm, user, uriInfo.getRequestUriBuilder()));
|
176
|
-
break;
|
177
|
-
case FEDERATED_IDENTITY:
|
178
|
-
attributes.put(
|
179
|
-
"federatedIdentity",
|
180
|
-
new AccountFederatedIdentityBean(
|
181
|
-
session, realm, user, uriInfo.getBaseUri(), stateChecker));
|
182
|
-
break;
|
183
|
-
case LOG:
|
184
|
-
attributes.put("log", new LogBean(events));
|
185
|
-
break;
|
186
|
-
case SESSIONS:
|
187
|
-
attributes.put("sessions", new SessionsBean(realm, sessions));
|
188
|
-
break;
|
189
|
-
case APPLICATIONS:
|
190
|
-
attributes.put("applications", new ApplicationsBean(session, realm, user));
|
191
|
-
attributes.put("advancedMsg", new AdvancedMessageFormatterMethod(locale, messagesBundle));
|
192
|
-
break;
|
193
|
-
case PASSWORD:
|
194
|
-
attributes.put("password", new PasswordBean(passwordSet));
|
195
|
-
break;
|
196
|
-
case RESOURCES:
|
197
|
-
if (!realm.isUserManagedAccessAllowed()) {
|
198
|
-
return Response.status(Status.FORBIDDEN).build();
|
199
|
-
}
|
200
|
-
attributes.put("authorization", new AuthorizationBean(session, realm, user, uriInfo));
|
201
|
-
case RESOURCE_DETAIL:
|
202
|
-
if (!realm.isUserManagedAccessAllowed()) {
|
203
|
-
return Response.status(Status.FORBIDDEN).build();
|
204
|
-
}
|
205
|
-
attributes.put("authorization", new AuthorizationBean(session, realm, user, uriInfo));
|
206
|
-
}
|
207
|
-
|
208
|
-
return processTemplate(theme, page, attributes, locale);
|
209
|
-
}
|
210
|
-
|
211
|
-
/**
|
212
|
-
* Get Theme used for page rendering.
|
213
|
-
*
|
214
|
-
* @return theme for page rendering, never null
|
215
|
-
* @throws IOException in case of Theme loading problem
|
216
|
-
*/
|
217
|
-
protected Theme getTheme() throws IOException {
|
218
|
-
return session.theme().getTheme(Theme.Type.ACCOUNT);
|
219
|
-
}
|
220
|
-
|
221
|
-
/**
|
222
|
-
* Load message bundle and place it into <code>msg</code> template attribute. Also load Theme
|
223
|
-
* properties and place them into <code>properties</code> template attribute.
|
224
|
-
*
|
225
|
-
* @param theme actual Theme to load bundle from
|
226
|
-
* @param locale to load bundle for
|
227
|
-
* @param attributes template attributes to add resources to
|
228
|
-
* @return message bundle for other use
|
229
|
-
*/
|
230
|
-
protected Properties handleThemeResources(
|
231
|
-
Theme theme, Locale locale, Map<String, Object> attributes) {
|
232
|
-
Properties messagesBundle = new Properties();
|
233
|
-
try {
|
234
|
-
if (!StringUtil.isNotBlank(realm.getDefaultLocale())) {
|
235
|
-
messagesBundle.putAll(realm.getRealmLocalizationTextsByLocale(realm.getDefaultLocale()));
|
236
|
-
}
|
237
|
-
messagesBundle.putAll(theme.getMessages(locale));
|
238
|
-
messagesBundle.putAll(realm.getRealmLocalizationTextsByLocale(locale.toLanguageTag()));
|
239
|
-
attributes.put("msg", new MessageFormatterMethod(locale, messagesBundle));
|
240
|
-
} catch (IOException e) {
|
241
|
-
logger.warn("Failed to load messages", e);
|
242
|
-
messagesBundle = new Properties();
|
243
|
-
}
|
244
|
-
try {
|
245
|
-
attributes.put("properties", theme.getProperties());
|
246
|
-
} catch (IOException e) {
|
247
|
-
logger.warn("Failed to load properties", e);
|
248
|
-
}
|
249
|
-
return messagesBundle;
|
250
|
-
}
|
251
|
-
|
252
|
-
/**
|
253
|
-
* Handle messages to be shown on the page - set them to template attributes
|
254
|
-
*
|
255
|
-
* @param locale to be used for message text loading
|
256
|
-
* @param messagesBundle to be used for message text loading
|
257
|
-
* @param attributes template attributes to messages related info to
|
258
|
-
* @see #messageType
|
259
|
-
* @see #messages
|
260
|
-
*/
|
261
|
-
protected void handleMessages(
|
262
|
-
Locale locale, Properties messagesBundle, Map<String, Object> attributes) {
|
263
|
-
MessagesPerFieldBean messagesPerField = new MessagesPerFieldBean();
|
264
|
-
if (messages != null) {
|
265
|
-
MessageBean wholeMessage = new MessageBean(null, messageType);
|
266
|
-
for (FormMessage message : this.messages) {
|
267
|
-
String formattedMessageText = formatMessage(message, messagesBundle, locale);
|
268
|
-
if (formattedMessageText != null) {
|
269
|
-
wholeMessage.appendSummaryLine(formattedMessageText);
|
270
|
-
messagesPerField.addMessage(message.getField(), formattedMessageText, messageType);
|
271
|
-
}
|
272
|
-
}
|
273
|
-
attributes.put("message", wholeMessage);
|
274
|
-
}
|
275
|
-
attributes.put("messagesPerField", messagesPerField);
|
276
|
-
}
|
277
|
-
|
278
|
-
/**
|
279
|
-
* Process FreeMarker template and prepare Response. Some fields are used for rendering also.
|
280
|
-
*
|
281
|
-
* @param theme to be used (provided by <code>getTheme()</code>)
|
282
|
-
* @param page to be rendered
|
283
|
-
* @param attributes pushed to the template
|
284
|
-
* @param locale to be used
|
285
|
-
* @return Response object to be returned to the browser, never null
|
286
|
-
*/
|
287
|
-
protected Response processTemplate(
|
288
|
-
Theme theme, AccountPages page, Map<String, Object> attributes, Locale locale) {
|
289
|
-
try {
|
290
|
-
String result = freeMarker.processTemplate(attributes, Templates.getTemplate(page), theme);
|
291
|
-
Response.ResponseBuilder builder =
|
292
|
-
Response.status(status)
|
293
|
-
.type(MediaType.TEXT_HTML_UTF_8_TYPE)
|
294
|
-
.language(locale)
|
295
|
-
.entity(result);
|
296
|
-
builder.cacheControl(CacheControlUtil.noCache());
|
297
|
-
return builder.build();
|
298
|
-
} catch (FreeMarkerException e) {
|
299
|
-
logger.error("Failed to process template", e);
|
300
|
-
return Response.serverError().build();
|
301
|
-
}
|
302
|
-
}
|
303
|
-
|
304
|
-
public AccountProvider setPasswordSet(boolean passwordSet) {
|
305
|
-
this.passwordSet = passwordSet;
|
306
|
-
return this;
|
307
|
-
}
|
308
|
-
|
309
|
-
protected void setMessage(MessageType type, String message, Object... parameters) {
|
310
|
-
messageType = type;
|
311
|
-
messages = new ArrayList<>();
|
312
|
-
messages.add(new FormMessage(null, message, parameters));
|
313
|
-
}
|
314
|
-
|
315
|
-
protected String formatMessage(FormMessage message, Properties messagesBundle, Locale locale) {
|
316
|
-
if (message == null) return null;
|
317
|
-
if (messagesBundle.containsKey(message.getMessage())) {
|
318
|
-
return new MessageFormat(messagesBundle.getProperty(message.getMessage()), locale)
|
319
|
-
.format(message.getParameters());
|
320
|
-
} else {
|
321
|
-
return message.getMessage();
|
322
|
-
}
|
323
|
-
}
|
324
|
-
|
325
|
-
@Override
|
326
|
-
public AccountProvider setErrors(Response.Status status, List<FormMessage> messages) {
|
327
|
-
this.status = status;
|
328
|
-
this.messageType = MessageType.ERROR;
|
329
|
-
this.messages = new ArrayList<>(messages);
|
330
|
-
return this;
|
331
|
-
}
|
332
|
-
|
333
|
-
@Override
|
334
|
-
public AccountProvider setError(Response.Status status, String message, Object... parameters) {
|
335
|
-
this.status = status;
|
336
|
-
setMessage(MessageType.ERROR, message, parameters);
|
337
|
-
return this;
|
338
|
-
}
|
339
|
-
|
340
|
-
@Override
|
341
|
-
public AccountProvider setSuccess(String message, Object... parameters) {
|
342
|
-
setMessage(MessageType.SUCCESS, message, parameters);
|
343
|
-
return this;
|
344
|
-
}
|
345
|
-
|
346
|
-
@Override
|
347
|
-
public AccountProvider setWarning(String message, Object... parameters) {
|
348
|
-
setMessage(MessageType.WARNING, message, parameters);
|
349
|
-
return this;
|
350
|
-
}
|
351
|
-
|
352
|
-
@Override
|
353
|
-
public AccountProvider setUser(UserModel user) {
|
354
|
-
this.user = user;
|
355
|
-
return this;
|
356
|
-
}
|
357
|
-
|
358
|
-
@Override
|
359
|
-
public AccountProvider setProfileFormData(MultivaluedMap<String, String> formData) {
|
360
|
-
this.profileFormData = formData;
|
361
|
-
return this;
|
362
|
-
}
|
363
|
-
|
364
|
-
@Override
|
365
|
-
public AccountProvider setRealm(RealmModel realm) {
|
366
|
-
this.realm = realm;
|
367
|
-
return this;
|
368
|
-
}
|
369
|
-
|
370
|
-
@Override
|
371
|
-
public AccountProvider setReferrer(String[] referrer) {
|
372
|
-
this.referrer = referrer;
|
373
|
-
return this;
|
374
|
-
}
|
375
|
-
|
376
|
-
@Override
|
377
|
-
public AccountProvider setEvents(List<Event> events) {
|
378
|
-
this.events = events;
|
379
|
-
return this;
|
380
|
-
}
|
381
|
-
|
382
|
-
@Override
|
383
|
-
public AccountProvider setSessions(List<UserSessionModel> sessions) {
|
384
|
-
this.sessions = sessions;
|
385
|
-
return this;
|
386
|
-
}
|
387
|
-
|
388
|
-
@Override
|
389
|
-
public AccountProvider setStateChecker(String stateChecker) {
|
390
|
-
this.stateChecker = stateChecker;
|
391
|
-
return this;
|
392
|
-
}
|
393
|
-
|
394
|
-
@Override
|
395
|
-
public AccountProvider setIdTokenHint(String idTokenHint) {
|
396
|
-
this.idTokenHint = idTokenHint;
|
397
|
-
return this;
|
398
|
-
}
|
399
|
-
|
400
|
-
@Override
|
401
|
-
public AccountProvider setFeatures(
|
402
|
-
boolean identityProviderEnabled,
|
403
|
-
boolean eventsEnabled,
|
404
|
-
boolean passwordUpdateSupported,
|
405
|
-
boolean authorizationSupported) {
|
406
|
-
this.identityProviderEnabled = identityProviderEnabled;
|
407
|
-
this.eventsEnabled = eventsEnabled;
|
408
|
-
this.passwordUpdateSupported = passwordUpdateSupported;
|
409
|
-
this.authorizationSupported = authorizationSupported;
|
410
|
-
return this;
|
411
|
-
}
|
412
|
-
|
413
|
-
@Override
|
414
|
-
public AccountProvider setAttribute(String key, String value) {
|
415
|
-
if (attributes == null) {
|
416
|
-
attributes = new HashMap<>();
|
417
|
-
}
|
418
|
-
attributes.put(key, value);
|
419
|
-
return this;
|
420
|
-
}
|
421
|
-
|
422
|
-
@Override
|
423
|
-
public void close() {}
|
424
|
-
}
|