152 newRealm.setName(rep.getRealm());
153 if (rep.getDisplayName() != null) newRealm.setDisplayName(rep.getDisplayName());
154 if (rep.getDisplayNameHtml() != null) newRealm.setDisplayNameHtml(rep.getDisplayNameHtml());
155 if (rep.isEnabled() != null) newRealm.setEnabled(rep.isEnabled());
156 if (rep.isUserManagedAccessAllowed() != null) newRealm.setUserManagedAccessAllowed(rep.isUserManagedAccessAllowed());
157 if (rep.isBruteForceProtected() != null) newRealm.setBruteForceProtected(rep.isBruteForceProtected());
158 if (rep.isPermanentLockout() != null) newRealm.setPermanentLockout(rep.isPermanentLockout());
159 if (rep.getMaxFailureWaitSeconds() != null) newRealm.setMaxFailureWaitSeconds(rep.getMaxFailureWaitSeconds());
160 if (rep.getMinimumQuickLoginWaitSeconds() != null)
161 newRealm.setMinimumQuickLoginWaitSeconds(rep.getMinimumQuickLoginWaitSeconds());
162 if (rep.getWaitIncrementSeconds() != null) newRealm.setWaitIncrementSeconds(rep.getWaitIncrementSeconds());
163 if (rep.getQuickLoginCheckMilliSeconds() != null)
164 newRealm.setQuickLoginCheckMilliSeconds(rep.getQuickLoginCheckMilliSeconds());
165 if (rep.getMaxDeltaTimeSeconds() != null) newRealm.setMaxDeltaTimeSeconds(rep.getMaxDeltaTimeSeconds());
166 if (rep.getFailureFactor() != null) newRealm.setFailureFactor(rep.getFailureFactor());
167 if (rep.isEventsEnabled() != null) newRealm.setEventsEnabled(rep.isEventsEnabled());
168 if (rep.getEnabledEventTypes() != null)
169 newRealm.setEnabledEventTypes(
new HashSet<>(rep.getEnabledEventTypes()));
170 if (rep.getEventsExpiration() != null) newRealm.setEventsExpiration(rep.getEventsExpiration());
171 if (rep.getEventsListeners() != null) newRealm.setEventsListeners(
new HashSet<>(rep.getEventsListeners()));
172 if (rep.isAdminEventsEnabled() != null) newRealm.setAdminEventsEnabled(rep.isAdminEventsEnabled());
173 if (rep.isAdminEventsDetailsEnabled() != null)
174 newRealm.setAdminEventsDetailsEnabled(rep.isAdminEventsDetailsEnabled());
176 if (rep.getNotBefore() != null) newRealm.setNotBefore(rep.getNotBefore());
178 if (rep.getDefaultSignatureAlgorithm() != null) newRealm.setDefaultSignatureAlgorithm(rep.getDefaultSignatureAlgorithm());
180 if (rep.getRevokeRefreshToken() != null) newRealm.setRevokeRefreshToken(rep.getRevokeRefreshToken());
181 else newRealm.setRevokeRefreshToken(
false);
183 if (rep.getRefreshTokenMaxReuse() != null) newRealm.setRefreshTokenMaxReuse(rep.getRefreshTokenMaxReuse());
184 else newRealm.setRefreshTokenMaxReuse(0);
186 if (rep.getAccessTokenLifespan() != null) newRealm.setAccessTokenLifespan(rep.getAccessTokenLifespan());
187 else newRealm.setAccessTokenLifespan(300);
189 if (rep.getAccessTokenLifespanForImplicitFlow() != null)
190 newRealm.setAccessTokenLifespanForImplicitFlow(rep.getAccessTokenLifespanForImplicitFlow());
192 newRealm.setAccessTokenLifespanForImplicitFlow(Constants.DEFAULT_ACCESS_TOKEN_LIFESPAN_FOR_IMPLICIT_FLOW_TIMEOUT);
194 if (rep.getSsoSessionIdleTimeout() != null) newRealm.setSsoSessionIdleTimeout(rep.getSsoSessionIdleTimeout());
195 else newRealm.setSsoSessionIdleTimeout(1800);
196 if (rep.getSsoSessionMaxLifespan() != null) newRealm.setSsoSessionMaxLifespan(rep.getSsoSessionMaxLifespan());
197 else newRealm.setSsoSessionMaxLifespan(36000);
198 if (rep.getOfflineSessionIdleTimeout() != null)
199 newRealm.setOfflineSessionIdleTimeout(rep.getOfflineSessionIdleTimeout());
200 else newRealm.setOfflineSessionIdleTimeout(Constants.DEFAULT_OFFLINE_SESSION_IDLE_TIMEOUT);
203 if (rep.getOfflineSessionMaxLifespanEnabled() != null) newRealm.setOfflineSessionMaxLifespanEnabled(rep.getOfflineSessionMaxLifespanEnabled());
204 else newRealm.setOfflineSessionMaxLifespanEnabled(
false);
206 if (rep.getOfflineSessionMaxLifespan() != null)
207 newRealm.setOfflineSessionMaxLifespan(rep.getOfflineSessionMaxLifespan());
208 else newRealm.setOfflineSessionMaxLifespan(Constants.DEFAULT_OFFLINE_SESSION_MAX_LIFESPAN);
210 if (rep.getAccessCodeLifespan() != null) newRealm.setAccessCodeLifespan(rep.getAccessCodeLifespan());
211 else newRealm.setAccessCodeLifespan(60);
213 if (rep.getAccessCodeLifespanUserAction() != null)
214 newRealm.setAccessCodeLifespanUserAction(rep.getAccessCodeLifespanUserAction());
215 else newRealm.setAccessCodeLifespanUserAction(300);
217 if (rep.getAccessCodeLifespanLogin() != null)
218 newRealm.setAccessCodeLifespanLogin(rep.getAccessCodeLifespanLogin());
219 else newRealm.setAccessCodeLifespanLogin(1800);
221 if (rep.getActionTokenGeneratedByAdminLifespan() != null)
222 newRealm.setActionTokenGeneratedByAdminLifespan(rep.getActionTokenGeneratedByAdminLifespan());
223 else newRealm.setActionTokenGeneratedByAdminLifespan(12 * 60 * 60);
225 if (rep.getActionTokenGeneratedByUserLifespan() != null)
226 newRealm.setActionTokenGeneratedByUserLifespan(rep.getActionTokenGeneratedByUserLifespan());
227 else newRealm.setActionTokenGeneratedByUserLifespan(newRealm.getAccessCodeLifespanUserAction());
229 if (rep.getSslRequired() != null)
230 newRealm.setSslRequired(SslRequired.valueOf(rep.getSslRequired().toUpperCase()));
231 if (rep.isRegistrationAllowed() != null) newRealm.setRegistrationAllowed(rep.isRegistrationAllowed());
232 if (rep.isRegistrationEmailAsUsername() != null)
233 newRealm.setRegistrationEmailAsUsername(rep.isRegistrationEmailAsUsername());
234 if (rep.isRememberMe() != null) newRealm.setRememberMe(rep.isRememberMe());
235 if (rep.isVerifyEmail() != null) newRealm.setVerifyEmail(rep.isVerifyEmail());
236 if (rep.isLoginWithEmailAllowed() != null) newRealm.setLoginWithEmailAllowed(rep.isLoginWithEmailAllowed());
237 if (rep.isDuplicateEmailsAllowed() != null) newRealm.setDuplicateEmailsAllowed(rep.isDuplicateEmailsAllowed());
238 if (rep.isResetPasswordAllowed() != null) newRealm.setResetPasswordAllowed(rep.isResetPasswordAllowed());
239 if (rep.isEditUsernameAllowed() != null) newRealm.setEditUsernameAllowed(rep.isEditUsernameAllowed());
240 if (rep.getLoginTheme() != null) newRealm.setLoginTheme(rep.getLoginTheme());
241 if (rep.getAccountTheme() != null) newRealm.setAccountTheme(rep.getAccountTheme());
242 if (rep.getAdminTheme() != null) newRealm.setAdminTheme(rep.getAdminTheme());
243 if (rep.getEmailTheme() != null) newRealm.setEmailTheme(rep.getEmailTheme());
246 if (rep.getRequiredCredentials() != null) {
247 for (String requiredCred : rep.getRequiredCredentials()) {
248 newRealm.addRequiredCredential(requiredCred);
251 newRealm.addRequiredCredential(CredentialRepresentation.PASSWORD);
254 if (rep.getPasswordPolicy() != null)
255 newRealm.setPasswordPolicy(PasswordPolicy.parse(session, rep.getPasswordPolicy()));
256 if (rep.getOtpPolicyType() != null) newRealm.setOTPPolicy(
toPolicy(rep));
257 else newRealm.setOTPPolicy(OTPPolicy.DEFAULT_POLICY);
260 if (rep.getRequiredActions() != null) {
261 for (RequiredActionProviderRepresentation action : rep.getRequiredActions()) {
262 RequiredActionProviderModel model =
toModel(action);
264 MigrationUtils.updateOTPRequiredAction(model);
266 newRealm.addRequiredActionProvider(model);
269 DefaultRequiredActions.addActions(newRealm);
275 Map<String, ClientScopeModel> clientScopes =
new HashMap<>();
276 if (rep.getClientScopes() != null) {
279 if (rep.getDefaultDefaultClientScopes() != null) {
280 for (String clientScopeName : rep.getDefaultDefaultClientScopes()) {
281 ClientScopeModel clientScope = clientScopes.get(clientScopeName);
282 if (clientScope != null) {
283 newRealm.addDefaultClientScope(clientScope,
true);
285 logger.warnf(
"Referenced client scope '%s' doesn't exists", clientScopeName);
289 if (rep.getDefaultOptionalClientScopes() != null) {
290 for (String clientScopeName : rep.getDefaultOptionalClientScopes()) {
291 ClientScopeModel clientScope = clientScopes.get(clientScopeName);
292 if (clientScope != null) {
293 newRealm.addDefaultClientScope(clientScope,
false);
295 logger.warnf(
"Referenced client scope '%s' doesn't exists", clientScopeName);
300 if (rep.getClients() != null) {
307 if (rep.getDefaultRoles() != null) {
308 for (String roleString : rep.getDefaultRoles()) {
309 newRealm.addDefaultRole(roleString.trim());
313 if (rep.getClients() != null) {
314 for (ClientRepresentation resourceRep : rep.getClients()) {
315 if (resourceRep.getDefaultRoles() != null) {
316 ClientModel clientModel = newRealm.getClientByClientId(resourceRep.getClientId());
317 clientModel.updateDefaultRoles(resourceRep.getDefaultRoles());
326 if (rep.getClientScopeMappings() != null) {
328 for (Map.Entry<String, List<ScopeMappingRepresentation>> entry : rep.getClientScopeMappings().entrySet()) {
329 ClientModel app = newRealm.getClientByClientId(entry.getKey());
331 throw new RuntimeException(
"Unable to find client role mappings for client: " + entry.getKey());
337 if (rep.getScopeMappings() != null) {
338 for (ScopeMappingRepresentation scope : rep.getScopeMappings()) {
341 for (String roleString : scope.getRoles()) {
342 RoleModel role = newRealm.getRole(roleString.trim());
344 role = newRealm.addRole(roleString.trim());
346 scopeContainer.addScopeMapping(role);
352 if (rep.getSmtpServer() != null) {
353 newRealm.setSmtpConfig(
new HashMap(rep.getSmtpServer()));
356 if (rep.getBrowserSecurityHeaders() != null) {
357 newRealm.setBrowserSecurityHeaders(rep.getBrowserSecurityHeaders());
359 newRealm.setBrowserSecurityHeaders(BrowserSecurityHeaders.defaultHeaders);
362 if (rep.getComponents() != null) {
363 MultivaluedHashMap<String, ComponentExportRepresentation> components = rep.getComponents();
364 String parentId = newRealm.getId();
370 if (rep.getGroups() != null) {
372 if (rep.getDefaultGroups() != null) {
373 for (String path : rep.getDefaultGroups()) {
374 GroupModel found = KeycloakModelUtils.findGroupByPath(newRealm, path);
375 if (found == null)
throw new RuntimeException(
"default group in realm rep doesn't exist: " + path);
376 newRealm.addDefaultGroup(found);
384 if (rep.getUsers() != null) {
385 for (UserRepresentation userRep : rep.getUsers()) {
386 UserModel user =
createUser(session, newRealm, userRep);
390 if (rep.getFederatedUsers() != null) {
391 for (UserRepresentation userRep : rep.getFederatedUsers()) {
397 if (!skipUserDependent) {
401 if (rep.isInternationalizationEnabled() != null) {
402 newRealm.setInternationalizationEnabled(rep.isInternationalizationEnabled());
404 if (rep.getSupportedLocales() != null) {
405 newRealm.setSupportedLocales(
new HashSet<String>(rep.getSupportedLocales()));
407 if (rep.getDefaultLocale() != null) {
408 newRealm.setDefaultLocale(rep.getDefaultLocale());
413 if (rep.getAttributes() != null) {
414 for (Map.Entry<String, String> attr : rep.getAttributes().entrySet()) {
415 newRealm.setAttribute(attr.getKey(), attr.getValue());
419 if (newRealm.getComponents(newRealm.getId(), KeyProvider.class.getName()).isEmpty()) {
420 if (rep.getPrivateKey() != null) {
421 DefaultKeyProviders.createProviders(newRealm, rep.getPrivateKey(), rep.getCertificate());
423 DefaultKeyProviders.createProviders(newRealm);
static void convertDeprecatedClientTemplates(RealmRepresentation realm)
Definition: RepresentationToModel.java:798
static Map< String, ClientModel > createClients(KeycloakSession session, RealmRepresentation rep, RealmModel realm)
Definition: RepresentationToModel.java:1067
static UserModel createUser(KeycloakSession session, RealmModel newRealm, UserRepresentation userRep)
Definition: RepresentationToModel.java:1498
static void importGroups(RealmModel realm, RealmRepresentation rep)
Definition: RepresentationToModel.java:533
static void importRealmAuthorizationSettings(RealmRepresentation rep, RealmModel newRealm, KeycloakSession session)
Definition: RepresentationToModel.java:1965
static void importUserFederationProvidersAndMappers(KeycloakSession session, RealmRepresentation rep, RealmModel newRealm)
Definition: RepresentationToModel.java:428
static Logger logger
Definition: RepresentationToModel.java:132
static Map< String, ClientScopeModel > createClientScopes(KeycloakSession session, List< ClientScopeRepresentation > clientScopes, RealmModel realm)
Definition: RepresentationToModel.java:1347
static void importRoles(RolesRepresentation realmRoles, RealmModel realm)
Definition: RepresentationToModel.java:491
static void importIdentityProviders(RealmRepresentation rep, RealmModel newRealm)
Definition: RepresentationToModel.java:1703
static void convertDeprecatedSocialProviders(RealmRepresentation rep)
Definition: RepresentationToModel.java:678
static void createClientScopeMappings(RealmModel realm, ClientModel clientModel, List< ScopeMappingRepresentation > mappings)
Definition: RepresentationToModel.java:1457
static void importComponents(RealmModel newRealm, MultivaluedHashMap< String, ComponentExportRepresentation > components, String parentId)
Definition: RepresentationToModel.java:471
static void importAuthenticationFlows(RealmModel newRealm, RealmRepresentation rep)
Definition: RepresentationToModel.java:585
static void convertDeprecatedApplications(KeycloakSession session, RealmRepresentation realm)
Definition: RepresentationToModel.java:729
static void importIdentityProviderMappers(RealmRepresentation rep, RealmModel newRealm)
Definition: RepresentationToModel.java:1711
static OTPPolicy toPolicy(RealmRepresentation rep)
Definition: RepresentationToModel.java:135
static void importFederatedUser(KeycloakSession session, RealmModel newRealm, UserRepresentation userRep)
Definition: RepresentationToModel.java:2463
static ScopeContainerModel getScopeContainerHavingScope(RealmModel realm, ScopeMappingRepresentation scope)
Definition: RepresentationToModel.java:1471
static CredentialModel toModel(CredentialRepresentation cred)
Definition: RepresentationToModel.java:1639