@Override protected List<String> load() { return new RealmRestClient().list().stream(). filter(realm -> authRealms.stream(). anyMatch(authRealm -> realm.getFullPath().startsWith(authRealm))). map(RealmTO::getFullPath). sorted(). collect(Collectors.toList()); } };
@Override public Response create(final String parentPath, final RealmTO realmTO) { ProvisioningResult<RealmTO> created = logic.create(StringUtils.prependIfMissing(parentPath, SyncopeConstants.ROOT_REALM), realmTO); URI location = uriInfo.getAbsolutePathBuilder().path(created.getEntity().getName()).build(); Response.ResponseBuilder builder = Response.created(location). header(RESTHeaders.RESOURCE_KEY, created.getEntity().getFullPath()); return applyPreference(created, builder).build(); }
private Map<String, Pair<RealmTO, List<RealmTO>>> reloadRealmParentMap(final List<RealmTO> realms) { tree.clear(); tree.put(null, Pair.<RealmTO, List<RealmTO>>of(realms.get(0), new ArrayList<>())); final Map<String, List<RealmTO>> cache = new HashMap<>(); realms.forEach(realm -> { final List<RealmTO> children = new ArrayList<>(); tree.put(realm.getKey(), Pair.<RealmTO, List<RealmTO>>of(realm, children)); if (cache.containsKey(realm.getKey())) { children.addAll(cache.get(realm.getKey())); cache.remove(realm.getKey()); } if (tree.containsKey(realm.getParent())) { tree.get(realm.getParent()).getRight().add(realm); } else if (cache.containsKey(realm.getParent())) { cache.get(realm.getParent()).add(realm); } else { cache.put(realm.getParent(), new ArrayList<>(Collections.singleton(realm))); } }); return tree; }
public StatusBean(final RealmTO realm, final String resource) { this.key = realm.getKey(); this.name = realm.getFullPath(); this.resource = resource; }
private void getChildren( final List<Pair<String, RealmTO>> full, final String key, final Map<String, Pair<RealmTO, List<RealmTO>>> tree, final String indent) { if (tree.containsKey(key)) { Pair<RealmTO, List<RealmTO>> subtree = tree.get(key); subtree.getValue().forEach(child -> { full.add(Pair.of(indent + child.getName(), child)); getChildren(full, child.getKey(), tree, " " + indent + (indent.isEmpty() ? "|--- " : "")); }); } }
@Override protected void onClickCreate(final AjaxRequestTarget target) { this.wizardBuilder.setParentPath(realmChoicePanel.getCurrentRealm().getFullPath()); send(this, Broadcast.EXACT, new AjaxWizard.NewItemActionEvent<RealmTO>(new RealmTO(), target) { @Override public String getEventDescription() { return "realm.new"; } }); }
private List<ProvisioningReport> assign(final SyncDelta delta, final OrgUnit orgUnit) throws JobExecutionException { if (!profile.getTask().isPerformCreate()) { LOG.debug("PullTask not configured for create"); finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta); return Collections.<ProvisioningReport>emptyList(); } RealmTO realmTO = connObjectUtils.getRealmTO(delta.getObject(), profile.getTask(), orgUnit); if (realmTO.getFullPath() == null) { if (realmTO.getParent() == null) { realmTO.setParent(profile.getTask().getDestinatioRealm().getFullPath()); } realmTO.setFullPath(realmTO.getParent() + "/" + realmTO.getName()); } realmTO.getResources().add(profile.getTask().getResource().getKey()); ProvisioningReport result = new ProvisioningReport(); result.setOperation(ResourceOperation.CREATE); result.setAnyType(REALM_TYPE); result.setStatus(ProvisioningReport.Status.SUCCESS); result.setName(realmTO.getFullPath()); if (profile.isDryRun()) { result.setKey(null); finalize(UnmatchingRule.toEventName(UnmatchingRule.ASSIGN), Result.SUCCESS, null, null, delta); } else { for (PullActions action : profile.getActions()) { action.beforeAssign(profile, delta, realmTO); } create(realmTO, delta, UnmatchingRule.ASSIGN, result); } return Collections.singletonList(result); }
@Override public RealmTO getRealmTO(final Realm realm, final boolean admin) { RealmTO realmTO = new RealmTO(); realmTO.setKey(realm.getKey()); realmTO.setName(realm.getName()); realmTO.setParent(realm.getParent() == null ? null : realm.getParent().getKey()); realmTO.setFullPath(realm.getFullPath()); if (admin) { realmTO.setAccountPolicy(realm.getAccountPolicy() == null ? null : realm.getAccountPolicy().getKey()); realmTO.setPasswordPolicy(realm.getPasswordPolicy() == null ? null : realm.getPasswordPolicy().getKey()); realm.getActions().forEach(action -> { realmTO.getActions().add(action.getKey()); }); realm.getTemplates().forEach(template -> { realmTO.getTemplates().put(template.getAnyType().getKey(), template.get()); }); realm.getResources().forEach(resource -> { realmTO.getResources().add(resource.getKey()); }); } return realmTO; }
Realm realm = entityFactory.newEntity(Realm.class); realm.setName(realmTO.getName()); realm.setParent(parent); if (realmTO.getPasswordPolicy() != null) { Policy policy = policyDAO.find(realmTO.getPasswordPolicy()); if (policy instanceof PasswordPolicy) { realm.setPasswordPolicy((PasswordPolicy) policy); if (realmTO.getAccountPolicy() != null) { Policy policy = policyDAO.find(realmTO.getAccountPolicy()); if (policy instanceof AccountPolicy) { realm.setAccountPolicy((AccountPolicy) policy); realmTO.getActions().forEach(logicActionsKey -> { Implementation logicAction = implementationDAO.find(logicActionsKey); if (logicAction == null) { realmTO.getResources().forEach(resourceKey -> { ExternalResource resource = resourceDAO.find(resourceKey); if (resource == null) {
final RealmTO realmTO = new RealmTO(); realmTO.setKey(dynRealmTO.getKey()); realmTO.setName(dynRealmTO.getKey()); realmTO.setFullPath(dynRealmTO.getKey()); new Model<RealmTO>(), Buttons.Type.Link, new Model<>(realmTO.getKey())) {
@Override public Response update(final RealmTO realmTO) { realmTO.setFullPath(StringUtils.prependIfMissing(realmTO.getFullPath(), SyncopeConstants.ROOT_REALM)); ProvisioningResult<RealmTO> updated = logic.update(realmTO); return modificationResponse(updated); }
@PreAuthorize("hasRole('" + StandardEntitlement.REALM_CREATE + "')") public ProvisioningResult<RealmTO> create(final String parentPath, final RealmTO realmTO) { Realm parent; if (StringUtils.isBlank(realmTO.getParent())) { parent = realmDAO.findByFullPath(parentPath); if (parent == null) { realmTO.setParent(parent.getFullPath()); } else { parent = realmDAO.find(realmTO.getParent()); if (parent == null) { LOG.error("Could not find parent realm " + realmTO.getParent()); throw new NotFoundException(realmTO.getParent()); String fullPath = StringUtils.appendIfMissing(parent.getFullPath(), "/") + realmTO.getName(); if (realmDAO.findByFullPath(fullPath) != null) { throw new DuplicateException(fullPath);
tree = new HashMap<>(); RealmTO fakeRootRealm = new RealmTO(); fakeRootRealm.setName(SyncopeConstants.ROOT_REALM); fakeRootRealm.setFullPath(SyncopeConstants.ROOT_REALM); model = Model.of(fakeRootRealm);
/** * Construct. * * @param pageRef Caller page reference. */ public RealmWizardBuilder(final PageReference pageRef) { super(new RealmTO(), pageRef); }
private List<ProvisioningReport> provision(final SyncDelta delta, final OrgUnit orgUnit) throws JobExecutionException { if (!profile.getTask().isPerformCreate()) { LOG.debug("PullTask not configured for create"); finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta); return Collections.<ProvisioningReport>emptyList(); } RealmTO realmTO = connObjectUtils.getRealmTO(delta.getObject(), profile.getTask(), orgUnit); if (realmTO.getFullPath() == null) { if (realmTO.getParent() == null) { realmTO.setParent(profile.getTask().getDestinatioRealm().getFullPath()); } realmTO.setFullPath(realmTO.getParent() + "/" + realmTO.getName()); } ProvisioningReport result = new ProvisioningReport(); result.setOperation(ResourceOperation.CREATE); result.setAnyType(REALM_TYPE); result.setStatus(ProvisioningReport.Status.SUCCESS); result.setName(realmTO.getFullPath()); if (profile.isDryRun()) { result.setKey(null); finalize(UnmatchingRule.toEventName(UnmatchingRule.PROVISION), Result.SUCCESS, null, null, delta); } else { for (PullActions action : profile.getActions()) { action.beforeProvision(profile, delta, realmTO); } create(realmTO, delta, UnmatchingRule.PROVISION, result); } return Collections.singletonList(result); }
@Override public PropagationByResource update(final Realm realm, final RealmTO realmTO) { realm.setName(realmTO.getName()); realm.setParent(realmTO.getParent() == null ? null : realmDAO.find(realmTO.getParent())); if (realmTO.getAccountPolicy() == null) { realm.setAccountPolicy(null); } else { Policy policy = policyDAO.find(realmTO.getAccountPolicy()); if (policy instanceof AccountPolicy) { realm.setAccountPolicy((AccountPolicy) policy); if (realmTO.getPasswordPolicy() == null) { realm.setPasswordPolicy(null); } else { Policy policy = policyDAO.find(realmTO.getPasswordPolicy()); if (policy instanceof PasswordPolicy) { realm.setPasswordPolicy((PasswordPolicy) policy); realmTO.getActions().forEach(logicActionsKey -> { Implementation logicActions = implementationDAO.find(logicActionsKey); if (logicActions == null) { removeIf(implementation -> !realmTO.getActions().contains(implementation.getKey())); realmTO.getResources().forEach(resourceKey -> { ExternalResource resource = resourceDAO.find(resourceKey); if (resource == null) { boolean contained = realmTO.getResources().contains(resource.getKey());
@Override protected void onClickDelete(final AjaxRequestTarget target, final RealmTO realmTO) { try { if (realmTO.getKey() == null) { throw new Exception("Root realm cannot be deleted"); } realmRestClient.delete(realmTO.getFullPath()); RealmTO parent = realmChoicePanel.moveToParentRealm(realmTO.getKey()); target.add(realmChoicePanel.reloadRealmTree(target)); SyncopeConsoleSession.get().info(getString(Constants.OPERATION_SUCCEEDED)); updateRealmContent(parent, selectedIndex); target.add(content); } catch (Exception e) { LOG.error("While deleting realm", e); // Escape line breaks SyncopeConsoleSession.get().error(e.getMessage().replace("\n", " ")); } ((BasePage) Realms.this.getPage()).getNotificationPanel().refresh(target); } });