use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class Realms method updateRealmContent.
private WebMarkupContainer updateRealmContent(final RealmTO realmTO, final int selectedIndex) {
if (realmTO == null) {
return content;
}
content.addOrReplace(new Realm("body", realmTO, Realms.this.getPageReference(), selectedIndex) {
private static final long serialVersionUID = 8221398624379357183L;
@Override
protected void onClickTemplate(final AjaxRequestTarget target) {
templates.setTargetObject(realmTO);
templates.toggle(target, true);
}
@Override
protected void setWindowClosedReloadCallback(final BaseModal<?> modal) {
modal.setWindowClosedCallback(new ModalWindow.WindowClosedCallback() {
private static final long serialVersionUID = 8804221891699487139L;
@Override
public void onClose(final AjaxRequestTarget target) {
if (modal.getContent() instanceof ResultPage) {
Serializable result = ResultPage.class.cast(modal.getContent()).getResult();
RealmTO newRealmTO = RealmTO.class.cast(ProvisioningResult.class.cast(result).getEntity());
// reload realmChoicePanel label too - SYNCOPE-1151
target.add(realmChoicePanel.reloadRealmTree(target, Model.of(newRealmTO)));
realmChoicePanel.setCurrentRealm(newRealmTO);
send(Realms.this, Broadcast.DEPTH, new ChosenRealm<>(newRealmTO, target));
} else {
target.add(realmChoicePanel.reloadRealmTree(target));
}
target.add(content);
modal.show(false);
}
});
}
@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";
}
});
}
@Override
protected void onClickEdit(final AjaxRequestTarget target, final RealmTO realmTO) {
this.wizardBuilder.setParentPath(realmTO.getFullPath());
send(this, Broadcast.EXACT, new AjaxWizard.EditItemActionEvent<RealmTO>(realmTO, target) {
@Override
public String getEventDescription() {
return "realm.edit";
}
});
}
@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);
}
});
return content;
}
use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class RealmResource method newResourceResponse.
@Override
protected ResourceResponse newResourceResponse(final Attributes attributes) {
LOG.debug("Search all available realms");
ResourceResponse response = new ResourceResponse();
response.setContentType(MediaType.APPLICATION_JSON);
try {
HttpServletRequest request = (HttpServletRequest) attributes.getRequest().getContainerRequest();
if (!xsrfCheck(request)) {
LOG.error("XSRF TOKEN does not match");
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), "XSRF TOKEN does not match");
return response;
}
final List<RealmTO> realmTOs = SyncopeEnduserSession.get().getService(RealmService.class).list();
response.setTextEncoding(StandardCharsets.UTF_8.name());
response.setWriteCallback(new AbstractResource.WriteCallback() {
@Override
public void writeData(final Attributes attributes) throws IOException {
attributes.getResponse().write(MAPPER.writeValueAsString(realmTOs));
}
});
response.setStatusCode(Response.Status.OK.getStatusCode());
} catch (Exception e) {
LOG.error("Error retrieving available realms", e);
response.setError(Response.Status.BAD_REQUEST.getStatusCode(), new StringBuilder().append("ErrorMessage{{ ").append(e.getMessage()).append(" }}").toString());
}
return response;
}
use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class RealmLogic method update.
@PreAuthorize("hasRole('" + StandardEntitlement.REALM_UPDATE + "')")
public ProvisioningResult<RealmTO> update(final RealmTO realmTO) {
Realm realm = realmDAO.findByFullPath(realmTO.getFullPath());
if (realm == null) {
LOG.error("Could not find realm '" + realmTO.getFullPath() + "'");
throw new NotFoundException(realmTO.getFullPath());
}
PropagationByResource propByRes = binder.update(realm, realmTO);
realm = realmDAO.save(realm);
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
result.setEntity(binder.getRealmTO(realm, true));
result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
return result;
}
use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class RealmLogic method create.
@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) {
LOG.error("Could not find parent realm " + parentPath);
throw new NotFoundException(parentPath);
}
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());
}
if (!parent.getFullPath().equals(parentPath)) {
SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidPath);
sce.getElements().add("Mismatching parent realm: " + parentPath + " Vs " + parent.getFullPath());
throw sce;
}
}
String fullPath = StringUtils.appendIfMissing(parent.getFullPath(), "/") + realmTO.getName();
if (realmDAO.findByFullPath(fullPath) != null) {
throw new DuplicateException(fullPath);
}
Realm realm = realmDAO.save(binder.create(parent, realmTO));
PropagationByResource propByRes = new PropagationByResource();
realm.getResourceKeys().forEach(resource -> {
propByRes.add(ResourceOperation.CREATE, resource);
});
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
result.setEntity(binder.getRealmTO(realm, true));
result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
return result;
}
use of org.apache.syncope.common.lib.to.RealmTO in project syncope by apache.
the class RealmLogic method delete.
@PreAuthorize("hasRole('" + StandardEntitlement.REALM_DELETE + "')")
public ProvisioningResult<RealmTO> delete(final String fullPath) {
Realm realm = realmDAO.findByFullPath(fullPath);
if (realm == null) {
LOG.error("Could not find realm '" + fullPath + "'");
throw new NotFoundException(fullPath);
}
if (!realmDAO.findChildren(realm).isEmpty()) {
throw SyncopeClientException.build(ClientExceptionType.HasChildren);
}
Set<String> adminRealms = Collections.singleton(realm.getFullPath());
AnyCond keyCond = new AnyCond(AttributeCond.Type.ISNOTNULL);
keyCond.setSchema("key");
SearchCond allMatchingCond = SearchCond.getLeafCond(keyCond);
int users = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.USER);
int groups = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.GROUP);
int anyObjects = searchDAO.count(adminRealms, allMatchingCond, AnyTypeKind.ANY_OBJECT);
if (users + groups + anyObjects > 0) {
SyncopeClientException containedAnys = SyncopeClientException.build(ClientExceptionType.AssociatedAnys);
containedAnys.getElements().add(users + " user(s)");
containedAnys.getElements().add(groups + " group(s)");
containedAnys.getElements().add(anyObjects + " anyObject(s)");
throw containedAnys;
}
PropagationByResource propByRes = new PropagationByResource();
realm.getResourceKeys().forEach(resource -> {
propByRes.add(ResourceOperation.DELETE, resource);
});
List<PropagationTaskTO> tasks = propagationManager.createTasks(realm, propByRes, null);
PropagationReporter propagationReporter = taskExecutor.execute(tasks, false);
ProvisioningResult<RealmTO> result = new ProvisioningResult<>();
result.setEntity(binder.getRealmTO(realm, true));
result.getPropagationStatuses().addAll(propagationReporter.getStatuses());
realmDAO.delete(realm);
return result;
}
Aggregations