You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2013/07/23 13:52:07 UTC
svn commit: r1505995 [2/4] - in /syncope/trunk: ./ build-tools/
build-tools/src/main/resources/
client/src/main/java/org/apache/syncope/client/http/
client/src/main/java/org/apache/syncope/client/rest/
client/src/main/java/org/apache/syncope/client/ser...
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java?rev=1505995&r1=1505994&r2=1505995&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/PolicyController.java Tue Jul 23 11:52:05 2013
@@ -20,9 +20,7 @@ package org.apache.syncope.core.rest.con
import java.util.ArrayList;
import java.util.List;
-import java.util.Locale;
import java.util.Set;
-import javax.servlet.http.HttpServletResponse;
import org.apache.syncope.common.to.AccountPolicyTO;
import org.apache.syncope.common.to.PasswordPolicyTO;
import org.apache.syncope.common.to.PolicyTO;
@@ -43,15 +41,9 @@ import org.apache.syncope.core.persisten
import org.apache.syncope.core.rest.data.PolicyDataBinder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.servlet.ModelAndView;
+import org.springframework.stereotype.Component;
-@Controller
-@RequestMapping("/policy")
+@Component
public class PolicyController extends AbstractController {
@Autowired
@@ -66,23 +58,8 @@ public class PolicyController extends Ab
@Autowired
private PolicyDataBinder binder;
- @RequestMapping(method = RequestMethod.POST, value = "/password/create")
- public PasswordPolicyTO create(final HttpServletResponse response, @RequestBody final PasswordPolicyTO policyTO) {
- return createInternal(policyTO);
- }
-
- @RequestMapping(method = RequestMethod.POST, value = "/account/create")
- public AccountPolicyTO create(final HttpServletResponse response, @RequestBody final AccountPolicyTO policyTO) {
- return createInternal(policyTO);
- }
-
- @RequestMapping(method = RequestMethod.POST, value = "/sync/create")
- public SyncPolicyTO create(final HttpServletResponse response, @RequestBody final SyncPolicyTO policyTO) {
- return createInternal(policyTO);
- }
-
@PreAuthorize("hasRole('POLICY_CREATE')")
- public <T extends PolicyTO> T createInternal(final T policyTO) {
+ public <T extends PolicyTO> T create(final T policyTO) {
LOG.debug("Creating policy " + policyTO);
final Policy policy = binder.getPolicy(null, policyTO);
@@ -106,8 +83,7 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/password/update")
- public PasswordPolicyTO update(@RequestBody final PasswordPolicyTO policyTO) {
+ public PasswordPolicyTO update(final PasswordPolicyTO policyTO) {
Policy policy = policyDAO.find(policyTO.getId());
if (!(policy instanceof PasswordPolicy)) {
throw new NotFoundException("PasswordPolicy with id " + policyTO.getId());
@@ -117,8 +93,7 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/account/update")
- public AccountPolicyTO update(@RequestBody final AccountPolicyTO policyTO) {
+ public AccountPolicyTO update(final AccountPolicyTO policyTO) {
Policy policy = policyDAO.find(policyTO.getId());
if (!(policy instanceof AccountPolicy)) {
throw new NotFoundException("AccountPolicy with id " + policyTO.getId());
@@ -128,8 +103,7 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/sync/update")
- public SyncPolicyTO update(@RequestBody final SyncPolicyTO policyTO) {
+ public SyncPolicyTO update(final SyncPolicyTO policyTO) {
Policy policy = policyDAO.find(policyTO.getId());
if (!(policy instanceof SyncPolicy)) {
throw new NotFoundException("SyncPolicy with id " + policyTO.getId());
@@ -139,24 +113,24 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/{kind}/list")
- public List<PolicyTO> list(@PathVariable("kind") final String kind) {
+ @SuppressWarnings("unchecked")
+ public <T extends PolicyTO> List<T> list(final PolicyType type) {
LOG.debug("Listing policies");
- List<? extends Policy> policies = policyDAO.find(PolicyType.valueOf(kind.toUpperCase(Locale.ENGLISH)));
- final List<PolicyTO> policyTOs = new ArrayList<PolicyTO>();
+ List<? extends Policy> policies = policyDAO.find(type);
+
+ final List<T> policyTOs = new ArrayList<T>();
for (Policy policy : policies) {
- policyTOs.add(binder.getPolicyTO(policy));
+ policyTOs.add((T) binder.getPolicyTO(policy));
}
auditManager.audit(Category.policy, PolicySubCategory.list, Result.success,
- "Successfully listed all policies (" + kind + "): " + policyTOs.size());
+ "Successfully listed all policies (" + type + "): " + policyTOs.size());
return policyTOs;
}
@PreAuthorize("hasRole('POLICY_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/password/global/read")
public PasswordPolicyTO getGlobalPasswordPolicy() {
LOG.debug("Reading global password policy");
@@ -172,7 +146,6 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/account/global/read")
public AccountPolicyTO getGlobalAccountPolicy() {
LOG.debug("Reading global account policy");
@@ -188,7 +161,6 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/sync/global/read")
public SyncPolicyTO getGlobalSyncPolicy() {
LOG.debug("Reading global sync policy");
@@ -204,8 +176,7 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/read/{id}")
- public <T extends PolicyTO> T read(@PathVariable("id") final Long id) {
+ public <T extends PolicyTO> T read(final Long id) {
LOG.debug("Reading policy with id {}", id);
Policy policy = policyDAO.find(id);
@@ -220,8 +191,7 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/delete/{id}")
- public PolicyTO delete(@PathVariable("id") final Long id) {
+ public PolicyTO delete(final Long id) {
Policy policy = policyDAO.find(id);
if (policy == null) {
throw new NotFoundException("Policy " + id + " not found");
@@ -237,14 +207,13 @@ public class PolicyController extends Ab
}
@PreAuthorize("hasRole('POLICY_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/syncCorrelationRuleClasses")
- public ModelAndView getSyncCorrelationRuleClasses() {
+ public Set<String> getSyncCorrelationRuleClasses() {
final Set<String> correlationRules =
classNamesLoader.getClassNames(ImplementationClassNamesLoader.Type.SYNC_CORRELATION_RULES);
auditManager.audit(Category.policy, AuditElements.PolicySubCategory.getCorrelationRuleClasses,
Result.success, "Successfully listed all correlation rule classes: " + correlationRules.size());
- return new ModelAndView().addObject(correlationRules);
+ return correlationRules;
}
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java?rev=1505995&r1=1505994&r2=1505995&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ReportController.java Tue Jul 23 11:52:05 2013
@@ -19,7 +19,6 @@
package org.apache.syncope.core.rest.controller;
import java.io.ByteArrayInputStream;
-import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Date;
@@ -29,8 +28,6 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.zip.ZipInputStream;
-import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.core.MediaType;
import org.apache.cocoon.optional.pipeline.components.sax.fop.FopSerializer;
import org.apache.cocoon.pipeline.NonCachingPipeline;
import org.apache.cocoon.pipeline.Pipeline;
@@ -39,7 +36,6 @@ import org.apache.cocoon.sax.component.X
import org.apache.cocoon.sax.component.XMLSerializer;
import org.apache.cocoon.sax.component.XSLTTransformer;
import org.apache.commons.io.IOUtils;
-import org.apache.syncope.common.SyncopeConstants;
import org.apache.syncope.common.report.ReportletConf;
import org.apache.syncope.common.to.ReportExecTO;
import org.apache.syncope.common.to.ReportTO;
@@ -67,17 +63,10 @@ import org.springframework.beans.factory
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
+import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.servlet.ModelAndView;
-@Controller
-@RequestMapping("/report")
+@Component
public class ReportController extends AbstractController {
@Autowired
@@ -98,15 +87,8 @@ public class ReportController extends Ab
@Autowired
private ReportDataBinder binder;
- @RequestMapping(method = RequestMethod.POST, value = "/create")
- public ReportTO create(final HttpServletResponse response, @RequestBody final ReportTO reportTO) {
- ReportTO createdReportTO = createInternal(reportTO);
- response.setStatus(HttpServletResponse.SC_CREATED);
- return createdReportTO;
- }
-
@PreAuthorize("hasRole('REPORT_CREATE')")
- public ReportTO createInternal(final ReportTO reportTO) {
+ public ReportTO create(final ReportTO reportTO) {
LOG.debug("Creating report " + reportTO);
Report report = new Report();
@@ -133,8 +115,7 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/update")
- public ReportTO update(@RequestBody final ReportTO reportTO) {
+ public ReportTO update(final ReportTO reportTO) {
LOG.debug("Report update called with parameter {}", reportTO);
Report report = reportDAO.find(reportTO.getId());
@@ -165,13 +146,11 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/count")
- public ModelAndView count() {
- return new ModelAndView().addObject(reportDAO.count());
+ public int count() {
+ return reportDAO.count();
}
@PreAuthorize("hasRole('REPORT_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/list")
public List<ReportTO> list() {
List<Report> reports = reportDAO.findAll();
List<ReportTO> result = new ArrayList<ReportTO>(reports.size());
@@ -186,8 +165,7 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/list/{page}/{size}")
- public List<ReportTO> list(@PathVariable("page") final int page, @PathVariable("size") final int size) {
+ public List<ReportTO> list(final int page, final int size) {
List<Report> reports = reportDAO.findAll(page, size);
List<ReportTO> result = new ArrayList<ReportTO>(reports.size());
for (Report report : reports) {
@@ -200,15 +178,9 @@ public class ReportController extends Ab
return result;
}
- @RequestMapping(method = RequestMethod.GET, value = "/reportletConfClasses")
- public ModelAndView getReportletConfClasses() {
- Set<String> reportletConfClasses = getReportletConfClassesInternal();
- return new ModelAndView().addObject(reportletConfClasses);
- }
-
@PreAuthorize("hasRole('REPORT_LIST')")
@SuppressWarnings("rawtypes")
- public Set<String> getReportletConfClassesInternal() {
+ public Set<String> getReportletConfClasses() {
Set<String> reportletConfClasses = new HashSet<String>();
for (Class<Reportlet> reportletClass : binder.getAllReportletClasses()) {
@@ -220,12 +192,12 @@ public class ReportController extends Ab
auditManager.audit(Category.report, ReportSubCategory.getReportletConfClasses, Result.success,
"Successfully listed all ReportletConf classes: " + reportletConfClasses.size());
+
return reportletConfClasses;
}
@PreAuthorize("hasRole('REPORT_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/read/{reportId}")
- public ReportTO read(@PathVariable("reportId") final Long reportId) {
+ public ReportTO read(final Long reportId) {
Report report = reportDAO.find(reportId);
if (report == null) {
throw new NotFoundException("Report " + reportId);
@@ -238,9 +210,8 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/execution/read/{executionId}")
@Transactional(readOnly = true)
- public ReportExecTO readExecution(@PathVariable("executionId") final Long executionId) {
+ public ReportExecTO readExecution(final Long executionId) {
ReportExec reportExec = reportExecDAO.find(executionId);
if (reportExec == null) {
throw new NotFoundException("Report execution " + executionId);
@@ -252,31 +223,8 @@ public class ReportController extends Ab
return binder.getReportExecTO(reportExec);
}
- @RequestMapping(method = RequestMethod.GET, value = "/execution/export/{executionId}")
- @Transactional(readOnly = true)
- public void exportExecutionResult(final HttpServletResponse response,
- @PathVariable("executionId") final Long executionId,
- @RequestParam(value = "fmt", required = false) final ReportExecExportFormat fmt) {
-
- OutputStream os;
- try {
- os = response.getOutputStream();
- } catch (IOException e) {
- throw new IllegalStateException("Could not get output stream", e);
- }
- ReportExec reportExec = getAndCheckReportExecInternal(executionId);
-
- ReportExecExportFormat format = (fmt == null) ? ReportExecExportFormat.XML : fmt;
-
- response.setContentType(MediaType.APPLICATION_OCTET_STREAM);
- response.addHeader(SyncopeConstants.CONTENT_DISPOSITION_HEADER,
- "attachment; filename=" + reportExec.getReport().getName() + "." + format.name().toLowerCase());
-
- exportExecutionResultInternal(os, reportExec, format);
- }
-
@PreAuthorize("hasRole('REPORT_READ')")
- public void exportExecutionResultInternal(final OutputStream os, final ReportExec reportExec,
+ public void exportExecutionResult(final OutputStream os, final ReportExec reportExec,
final ReportExecExportFormat format) {
LOG.debug("Exporting result of {} as {}", reportExec, format);
@@ -340,7 +288,7 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_READ')")
- public ReportExec getAndCheckReportExecInternal(final Long executionId) {
+ public ReportExec getAndCheckReportExec(final Long executionId) {
ReportExec reportExec = reportExecDAO.find(executionId);
if (reportExec == null) {
throw new NotFoundException("Report execution " + executionId);
@@ -359,8 +307,7 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_EXECUTE')")
- @RequestMapping(method = RequestMethod.POST, value = "/execute/{reportId}")
- public ReportExecTO execute(@PathVariable("reportId") final Long reportId) {
+ public ReportExecTO execute(final Long reportId) {
Report report = reportDAO.find(reportId);
if (report == null) {
throw new NotFoundException("Report " + reportId);
@@ -402,8 +349,7 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/delete/{reportId}")
- public ReportTO delete(@PathVariable("reportId") final Long reportId) {
+ public ReportTO delete(final Long reportId) {
Report report = reportDAO.find(reportId);
if (report == null) {
throw new NotFoundException("Report " + reportId);
@@ -422,8 +368,7 @@ public class ReportController extends Ab
}
@PreAuthorize("hasRole('REPORT_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/execution/delete/{executionId}")
- public ReportExecTO deleteExecution(@PathVariable("executionId") final Long executionId) {
+ public ReportExecTO deleteExecution(final Long executionId) {
ReportExec reportExec = reportExecDAO.find(executionId);
if (reportExec == null) {
throw new NotFoundException("Report execution " + executionId);
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java?rev=1505995&r1=1505994&r2=1505995&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/ResourceController.java Tue Jul 23 11:52:05 2013
@@ -21,7 +21,6 @@ package org.apache.syncope.core.rest.con
import java.util.List;
import java.util.Set;
import javax.persistence.EntityExistsException;
-import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.syncope.common.to.BulkAction;
import org.apache.syncope.common.to.BulkActionRes;
@@ -62,17 +61,10 @@ import org.identityconnectors.framework.
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
+import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.servlet.ModelAndView;
-@Controller
-@RequestMapping("/resource")
+@Component
public class ResourceController extends AbstractController {
@Autowired
@@ -106,8 +98,7 @@ public class ResourceController extends
private ConnectorFactory connFactory;
@PreAuthorize("hasRole('RESOURCE_CREATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/create")
- public ResourceTO create(final HttpServletResponse response, @RequestBody final ResourceTO resourceTO) {
+ public ResourceTO create(final ResourceTO resourceTO) {
LOG.debug("Resource creation: {}", resourceTO);
if (StringUtils.isBlank(resourceTO.getName())) {
@@ -128,13 +119,11 @@ public class ResourceController extends
auditManager.audit(Category.resource, ResourceSubCategory.create, Result.success,
"Successfully created resource: " + resource.getName());
- response.setStatus(HttpServletResponse.SC_CREATED);
return binder.getResourceTO(resource);
}
@PreAuthorize("hasRole('RESOURCE_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/update")
- public ResourceTO update(@RequestBody final ResourceTO resourceTO) {
+ public ResourceTO update(final ResourceTO resourceTO) {
LOG.debug("Role update request: {}", resourceTO);
ExternalResource resource = resourceDAO.find(resourceTO.getName());
@@ -152,8 +141,7 @@ public class ResourceController extends
}
@PreAuthorize("hasRole('RESOURCE_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/delete/{resourceName}")
- public ResourceTO delete(@PathVariable("resourceName") final String resourceName) {
+ public ResourceTO delete(final String resourceName) {
ExternalResource resource = resourceDAO.find(resourceName);
if (resource == null) {
throw new NotFoundException("Resource '" + resourceName + "'");
@@ -171,8 +159,7 @@ public class ResourceController extends
@PreAuthorize("hasRole('RESOURCE_READ')")
@Transactional(readOnly = true)
- @RequestMapping(method = RequestMethod.GET, value = "/read/{resourceName}")
- public ResourceTO read(@PathVariable("resourceName") final String resourceName) {
+ public ResourceTO read(final String resourceName) {
ExternalResource resource = resourceDAO.find(resourceName);
if (resource == null) {
throw new NotFoundException("Resource '" + resourceName + "'");
@@ -185,20 +172,18 @@ public class ResourceController extends
}
@PreAuthorize("hasRole('RESOURCE_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/propagationActionsClasses")
- public ModelAndView getPropagationActionsClasses() {
+ public Set<String> getPropagationActionsClasses() {
Set<String> actionsClasses = classNamesLoader.getClassNames(
ImplementationClassNamesLoader.Type.PROPAGATION_ACTIONS);
auditManager.audit(Category.resource, AuditElements.ResourceSubCategory.getPropagationActionsClasses,
Result.success, "Successfully listed all PropagationActions classes: " + actionsClasses.size());
- return new ModelAndView().addObject(actionsClasses);
+ return actionsClasses;
}
@Transactional(readOnly = true)
- @RequestMapping(method = RequestMethod.GET, value = "/list")
- public List<ResourceTO> list(@RequestParam(required = false, value = "connInstanceId") final Long connInstanceId) {
+ public List<ResourceTO> list(final Long connInstanceId) {
List<ExternalResource> resources;
if (connInstanceId == null) {
@@ -220,10 +205,7 @@ public class ResourceController extends
@PreAuthorize("hasRole('RESOURCE_GETCONNECTOROBJECT')")
@Transactional(readOnly = true)
- @RequestMapping(method = RequestMethod.GET, value = "/{resourceName}/read/{type}/{id}")
- public ConnObjectTO getConnectorObject(@PathVariable("resourceName") final String resourceName,
- @PathVariable("type") final AttributableType type, @PathVariable("id") final Long id) {
-
+ public ConnObjectTO getConnectorObject(final String resourceName, final AttributableType type, final Long id) {
ExternalResource resource = resourceDAO.find(resourceName);
if (resource == null) {
throw new NotFoundException("Resource '" + resourceName + "'");
@@ -244,14 +226,15 @@ public class ResourceController extends
throw new IllegalArgumentException("Not supported for MEMBERSHIP");
}
if (attributable == null) {
- throw new NotFoundException(type + " " + id );
+ throw new NotFoundException(type + " " + id);
}
final AttributableUtil attrUtil = AttributableUtil.getInstance(type);
AbstractMappingItem accountIdItem = attrUtil.getAccountIdItem(resource);
if (accountIdItem == null) {
- throw new NotFoundException("AccountId mapping for " + type + " " + id + " on resource '" + resourceName + "'");
+ throw new NotFoundException("AccountId mapping for " + type + " " + id + " on resource '" + resourceName
+ + "'");
}
final String accountIdValue =
MappingUtil.getAccountIdValue(attributable, resource, attrUtil.getAccountIdItem(resource));
@@ -282,9 +265,8 @@ public class ResourceController extends
}
@PreAuthorize("hasRole('CONNECTOR_READ')")
- @RequestMapping(method = RequestMethod.POST, value = "/check")
@Transactional(readOnly = true)
- public ModelAndView check(@RequestBody final ResourceTO resourceTO) {
+ public boolean check(final ResourceTO resourceTO) {
final ConnInstance connInstance = binder.getConnInstance(resourceTO);
final Connector connector = connFactory.createConnector(connInstance, connInstance.getConfiguration());
@@ -304,28 +286,24 @@ public class ResourceController extends
result = false;
}
- return new ModelAndView().addObject(result);
+ return result;
}
@PreAuthorize("hasRole('RESOURCE_DELETE') and #bulkAction.operation == #bulkAction.operation.DELETE")
- @RequestMapping(method = RequestMethod.POST, value = "/bulk")
- public BulkActionRes bulkAction(@RequestBody final BulkAction bulkAction) {
+ public BulkActionRes bulkAction(final BulkAction bulkAction) {
LOG.debug("Bulk action '{}' called on '{}'", bulkAction.getOperation(), bulkAction.getTargets());
BulkActionRes res = new BulkActionRes();
- switch (bulkAction.getOperation()) {
- case DELETE:
- for (String name : bulkAction.getTargets()) {
- try {
- res.add(delete(name).getName(), BulkActionRes.Status.SUCCESS);
- } catch (Exception e) {
- LOG.error("Error performing delete for resource {}", name, e);
- res.add(name, BulkActionRes.Status.FAILURE);
- }
+ if (bulkAction.getOperation() == BulkAction.Type.DELETE) {
+ for (String name : bulkAction.getTargets()) {
+ try {
+ res.add(delete(name).getName(), BulkActionRes.Status.SUCCESS);
+ } catch (Exception e) {
+ LOG.error("Error performing delete for resource {}", name, e);
+ res.add(name, BulkActionRes.Status.FAILURE);
}
- break;
- default:
+ }
}
return res;
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java?rev=1505995&r1=1505994&r2=1505995&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/RoleController.java Tue Jul 23 11:52:05 2013
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
-import javax.servlet.http.HttpServletResponse;
import org.apache.syncope.common.mod.RoleMod;
import org.apache.syncope.common.search.NodeCond;
import org.apache.syncope.common.services.InvalidSearchConditionException;
@@ -56,16 +55,10 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Controller;
+import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.servlet.ModelAndView;
-@Controller
-@RequestMapping("/role")
+@Component
public class RoleController {
/**
@@ -104,9 +97,8 @@ public class RoleController {
private ConnObjectUtil connObjectUtil;
@PreAuthorize("hasRole('ROLE_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/read/{roleId}")
@Transactional(readOnly = true)
- public RoleTO read(@PathVariable("roleId") final Long roleId) {
+ public RoleTO read(final Long roleId) {
SyncopeRole role = binder.getRoleFromId(roleId);
Set<Long> allowedRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
@@ -121,9 +113,8 @@ public class RoleController {
}
@PreAuthorize("isAuthenticated()")
- @RequestMapping(method = RequestMethod.GET, value = "/selfRead/{roleId}")
@Transactional(readOnly = true)
- public RoleTO selfRead(@PathVariable("roleId") final Long roleId) {
+ public RoleTO selfRead(final Long roleId) {
// Explicit search instead of using binder.getRoleFromId() in order to bypass auth checks - will do here
SyncopeRole role = roleDAO.find(roleId);
if (role == null) {
@@ -151,9 +142,8 @@ public class RoleController {
}
@PreAuthorize("hasRole('ROLE_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/parent/{roleId}")
@Transactional(readOnly = true)
- public RoleTO parent(@PathVariable("roleId") final Long roleId) {
+ public RoleTO parent(final Long roleId) {
SyncopeRole role = binder.getRoleFromId(roleId);
Set<Long> allowedRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
@@ -174,9 +164,8 @@ public class RoleController {
}
@PreAuthorize("hasRole('ROLE_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/children/{roleId}")
@Transactional(readOnly = true)
- public List<RoleTO> children(@PathVariable("roleId") final Long roleId) {
+ public List<RoleTO> children(final Long roleId) {
SyncopeRole role = binder.getRoleFromId(roleId);
Set<Long> allowedRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
@@ -196,19 +185,16 @@ public class RoleController {
}
@PreAuthorize("hasRole('ROLE_READ')")
- @RequestMapping(method = RequestMethod.POST, value = "/search")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public List<RoleTO> search(@RequestBody final NodeCond searchCondition)
+ public List<RoleTO> search(final NodeCond searchCondition)
throws InvalidSearchConditionException {
return search(searchCondition, -1, -1);
}
@PreAuthorize("hasRole('ROLE_READ')")
- @RequestMapping(method = RequestMethod.POST, value = "/search/{page}/{size}")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public List<RoleTO> search(@RequestBody final NodeCond searchCondition, @PathVariable("page") final int page,
- @PathVariable("size") final int size)
+ public List<RoleTO> search(final NodeCond searchCondition, final int page, final int size)
throws InvalidSearchConditionException {
LOG.debug("Role search called with condition {}", searchCondition);
@@ -234,9 +220,8 @@ public class RoleController {
}
@PreAuthorize("hasRole('ROLE_READ')")
- @RequestMapping(method = RequestMethod.POST, value = "/search/count")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public ModelAndView searchCount(@RequestBody final NodeCond searchCondition)
+ public int searchCount(final NodeCond searchCondition)
throws InvalidSearchConditionException {
if (!searchCondition.isValid()) {
@@ -245,11 +230,9 @@ public class RoleController {
}
final Set<Long> adminRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
- return new ModelAndView().addObject(searchDAO.count(adminRoleIds, searchCondition,
- AttributableUtil.getInstance(AttributableType.ROLE)));
+ return searchDAO.count(adminRoleIds, searchCondition, AttributableUtil.getInstance(AttributableType.ROLE));
}
- @RequestMapping(method = RequestMethod.GET, value = "/list")
@Transactional(readOnly = true)
public List<RoleTO> list() {
List<SyncopeRole> roles = roleDAO.findAll();
@@ -266,8 +249,7 @@ public class RoleController {
}
@PreAuthorize("hasRole('ROLE_CREATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/create")
- public RoleTO create(final HttpServletResponse response, @RequestBody final RoleTO roleTO) {
+ public RoleTO create(final RoleTO roleTO) {
LOG.debug("Role create called with parameters {}", roleTO);
Set<Long> allowedRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
@@ -298,13 +280,11 @@ public class RoleController {
auditManager.audit(Category.role, RoleSubCategory.create, Result.success,
"Successfully created role: " + savedTO.getId());
- response.setStatus(HttpServletResponse.SC_CREATED);
return savedTO;
}
@PreAuthorize("hasRole('ROLE_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/update")
- public RoleTO update(@RequestBody final RoleMod roleMod) {
+ public RoleTO update(final RoleMod roleMod) {
LOG.debug("Role update called with {}", roleMod);
SyncopeRole role = binder.getRoleFromId(roleMod.getId());
@@ -334,8 +314,7 @@ public class RoleController {
}
@PreAuthorize("hasRole('ROLE_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/delete/{roleId}")
- public RoleTO delete(@PathVariable("roleId") final Long roleId) {
+ public RoleTO delete(final Long roleId) {
LOG.debug("Role delete called for {}", roleId);
// Generate propagation tasks for deleting users from role resources, if they are on those resources only
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java?rev=1505995&r1=1505994&r2=1505995&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/SchemaController.java Tue Jul 23 11:52:05 2013
@@ -21,32 +21,33 @@ package org.apache.syncope.core.rest.con
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityExistsException;
-import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
+import org.apache.syncope.common.to.AbstractSchemaTO;
+import org.apache.syncope.common.to.DerSchemaTO;
import org.apache.syncope.common.to.SchemaTO;
-import org.apache.syncope.common.types.AuditElements.Category;
-import org.apache.syncope.common.types.AuditElements.Result;
-import org.apache.syncope.common.types.AuditElements.SchemaSubCategory;
+import org.apache.syncope.common.to.VirSchemaTO;
+import org.apache.syncope.common.types.AttributableType;
+import org.apache.syncope.common.types.AuditElements;
+import org.apache.syncope.common.types.SchemaType;
import org.apache.syncope.common.types.SyncopeClientExceptionType;
import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException;
import org.apache.syncope.common.validation.SyncopeClientException;
import org.apache.syncope.core.audit.AuditManager;
+import org.apache.syncope.core.persistence.beans.AbstractDerSchema;
import org.apache.syncope.core.persistence.beans.AbstractSchema;
+import org.apache.syncope.core.persistence.beans.AbstractVirSchema;
+import org.apache.syncope.core.persistence.dao.DerSchemaDAO;
import org.apache.syncope.core.persistence.dao.NotFoundException;
import org.apache.syncope.core.persistence.dao.SchemaDAO;
+import org.apache.syncope.core.persistence.dao.VirSchemaDAO;
import org.apache.syncope.core.rest.data.SchemaDataBinder;
import org.apache.syncope.core.util.AttributableUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.stereotype.Component;
-@Controller
-@RequestMapping("/schema")
+@Component
public class SchemaController extends AbstractController {
@Autowired
@@ -56,12 +57,41 @@ public class SchemaController extends Ab
private SchemaDAO schemaDAO;
@Autowired
+ private DerSchemaDAO derSchemaDAO;
+
+ @Autowired
+ private VirSchemaDAO virSchemaDAO;
+
+ @Autowired
private SchemaDataBinder binder;
+ private boolean doesSchemaExist(final SchemaType schemaType, final String name, final AttributableUtil attrUtil) {
+ boolean found;
+
+ switch (schemaType) {
+ case VIRTUAL:
+ found = virSchemaDAO.find(name, attrUtil.virSchemaClass()) != null;
+ break;
+
+ case DERIVED:
+ found = derSchemaDAO.find(name, attrUtil.derSchemaClass()) != null;
+ break;
+
+ case NORMAL:
+ found = schemaDAO.find(name, attrUtil.schemaClass()) != null;
+ break;
+
+ default:
+ found = false;
+ }
+
+ return found;
+ }
+
@PreAuthorize("hasRole('SCHEMA_CREATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/{kind}/create")
- public SchemaTO create(final HttpServletResponse response, @RequestBody final SchemaTO schemaTO,
- @PathVariable("kind") final String kind) {
+ @SuppressWarnings("unchecked")
+ public <T extends AbstractSchemaTO> T create(final AttributableType attrType, final SchemaType schemaType,
+ final T schemaTO) {
if (StringUtils.isBlank(schemaTO.getName())) {
SyncopeClientCompositeErrorException sccee =
@@ -72,95 +102,199 @@ public class SchemaController extends Ab
throw sccee;
}
- AttributableUtil attrUtil = getAttributableUtil(kind);
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);
- if (schemaDAO.find(schemaTO.getName(), attrUtil.schemaClass()) != null) {
- throw new EntityExistsException(attrUtil.schemaClass().getSimpleName()
- + " '" + schemaTO.getName() + "'");
+ if (doesSchemaExist(schemaType, schemaTO.getName(), attrUtil)) {
+ throw new EntityExistsException(schemaType + "/" + attrType + "/" + schemaTO.getName());
}
- AbstractSchema schema = attrUtil.newSchema();
- binder.create(schemaTO, schema);
- schema = schemaDAO.save(schema);
+ T created;
+ switch (schemaType) {
+ case VIRTUAL:
+ AbstractVirSchema virSchema = attrUtil.newVirSchema();
+ binder.create((VirSchemaTO) schemaTO, virSchema);
+ virSchema = virSchemaDAO.save(virSchema);
+
+ created = (T) binder.getVirSchemaTO(virSchema);
+ break;
+
+ case DERIVED:
+ AbstractDerSchema derSchema = attrUtil.newDerSchema();
+ binder.create((DerSchemaTO) schemaTO, derSchema);
+ derSchema = derSchemaDAO.save(derSchema);
+
+ created = (T) binder.getDerSchemaTO(derSchema);
+ break;
+
+ case NORMAL:
+ default:
+ AbstractSchema normalSchema = attrUtil.newSchema();
+ binder.create((SchemaTO) schemaTO, normalSchema);
+ normalSchema = schemaDAO.save(normalSchema);
+
+ created = (T) binder.getSchemaTO(normalSchema, attrUtil);
+ }
- auditManager.audit(Category.schema, SchemaSubCategory.create, Result.success,
- "Successfully created schema: " + kind + "/" + schema.getName());
+ auditManager.audit(AuditElements.Category.schema, AuditElements.SchemaSubCategory.create,
+ AuditElements.Result.success,
+ "Successfully created schema: " + schemaType + "/" + attrType + "/" + created.getName());
- response.setStatus(HttpServletResponse.SC_CREATED);
- return binder.getSchemaTO(schema, attrUtil);
+ return created;
}
@PreAuthorize("hasRole('SCHEMA_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/{kind}/delete/{schema}")
- public SchemaTO delete(@PathVariable("kind") final String kind, @PathVariable("schema") final String schemaName)
- throws NotFoundException {
+ public void delete(final AttributableType attrType, final SchemaType schemaType, final String schemaName) {
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);
- Class<? extends AbstractSchema> reference = getAttributableUtil(kind).schemaClass();
- AbstractSchema schema = schemaDAO.find(schemaName, reference);
- if (schema == null) {
- throw new NotFoundException("Schema '" + schemaName + "'");
+ if (!doesSchemaExist(schemaType, schemaName, attrUtil)) {
+ throw new NotFoundException(schemaType + "/" + attrType + "/" + schemaName);
}
- SchemaTO schemaToDelete = binder.getSchemaTO(schema, getAttributableUtil(kind));
-
- schemaDAO.delete(schemaName, getAttributableUtil(kind));
-
- auditManager.audit(Category.schema, SchemaSubCategory.delete, Result.success,
- "Successfully deleted schema: " + kind + "/" + schema.getName());
+ switch (schemaType) {
+ case VIRTUAL:
+ virSchemaDAO.delete(schemaName, attrUtil);
+ break;
+
+ case DERIVED:
+ derSchemaDAO.delete(schemaName, attrUtil);
+ break;
+
+ case NORMAL:
+ default:
+ schemaDAO.delete(schemaName, attrUtil);
+ }
- return schemaToDelete;
+ auditManager.audit(AuditElements.Category.schema, AuditElements.SchemaSubCategory.delete,
+ AuditElements.Result.success,
+ "Successfully deleted schema: " + schemaType + "/" + attrType + "/" + schemaName);
}
- @RequestMapping(method = RequestMethod.GET, value = "/{kind}/list")
- public List<SchemaTO> list(@PathVariable("kind") final String kind) {
- AttributableUtil attributableUtil = getAttributableUtil(kind);
- List<AbstractSchema> schemas = schemaDAO.findAll(attributableUtil.schemaClass());
-
- List<SchemaTO> schemaTOs = new ArrayList<SchemaTO>(schemas.size());
- for (AbstractSchema schema : schemas) {
- schemaTOs.add(binder.getSchemaTO(schema, attributableUtil));
+ @SuppressWarnings("unchecked")
+ public <T extends AbstractSchemaTO> List<T> list(final AttributableType attrType, final SchemaType schemaType) {
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);
+
+ List<T> result;
+ switch (schemaType) {
+ case VIRTUAL:
+ List<AbstractVirSchema> virSchemas = virSchemaDAO.findAll(attrUtil.virSchemaClass());
+ result = (List<T>) new ArrayList<VirSchemaTO>(virSchemas.size());
+ for (AbstractVirSchema derSchema : virSchemas) {
+ result.add((T) binder.getVirSchemaTO(derSchema));
+ }
+ break;
+
+ case DERIVED:
+ List<AbstractDerSchema> derSchemas = derSchemaDAO.findAll(attrUtil.derSchemaClass());
+ result = (List<T>) new ArrayList<DerSchemaTO>(derSchemas.size());
+ for (AbstractDerSchema derSchema : derSchemas) {
+ result.add((T) binder.getDerSchemaTO(derSchema));
+ }
+ break;
+
+ case NORMAL:
+ default:
+ List<AbstractSchema> schemas = schemaDAO.findAll(attrUtil.schemaClass());
+ result = (List<T>) new ArrayList<SchemaTO>(schemas.size());
+ for (AbstractSchema schema : schemas) {
+ result.add((T) binder.getSchemaTO(schema, attrUtil));
+ }
}
- auditManager.audit(Category.schema, SchemaSubCategory.list, Result.success,
- "Successfully listed all schemas: " + kind + "/" + schemaTOs.size());
+ auditManager.audit(AuditElements.Category.schema, AuditElements.SchemaSubCategory.list,
+ AuditElements.Result.success,
+ "Successfully listed schemas: " + schemaType + "/" + attrType + " " + result.size());
- return schemaTOs;
+ return result;
}
@PreAuthorize("hasRole('SCHEMA_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/{kind}/read/{schema}")
- public SchemaTO read(@PathVariable("kind") final String kind, @PathVariable("schema") final String schemaName)
- throws NotFoundException {
+ @SuppressWarnings("unchecked")
+ public <T extends AbstractSchemaTO> T read(final AttributableType attrType, final SchemaType schemaType,
+ final String schemaName) {
+
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);
+
+ T read;
+ switch (schemaType) {
+ case VIRTUAL:
+ AbstractVirSchema virSchema = virSchemaDAO.find(schemaName, attrUtil.virSchemaClass());
+ if (virSchema == null) {
+ throw new NotFoundException("Virtual Schema '" + schemaName + "'");
+ }
+
+ read = (T) binder.getVirSchemaTO(virSchema);
+ break;
+
+ case DERIVED:
+ AbstractDerSchema derSchema = derSchemaDAO.find(schemaName, attrUtil.derSchemaClass());
+ if (derSchema == null) {
+ throw new NotFoundException("Derived schema '" + schemaName + "'");
+ }
+
+ read = (T) binder.getDerSchemaTO(derSchema);
+ break;
+
+ case NORMAL:
+ default:
+ AbstractSchema schema = schemaDAO.find(schemaName, attrUtil.schemaClass());
+ if (schema == null) {
+ throw new NotFoundException("Schema '" + schemaName + "'");
+ }
- AttributableUtil attributableUtil = getAttributableUtil(kind);
- AbstractSchema schema = schemaDAO.find(schemaName, attributableUtil.schemaClass());
- if (schema == null) {
- throw new NotFoundException("Schema '" + schemaName + "'");
+ read = (T) binder.getSchemaTO(schema, attrUtil);
}
- auditManager.audit(Category.schema, SchemaSubCategory.read, Result.success,
- "Successfully read schema: " + kind + "/" + schema.getName());
+ auditManager.audit(AuditElements.Category.schema, AuditElements.SchemaSubCategory.read,
+ AuditElements.Result.success,
+ "Successfully read schema: " + schemaType + "/" + attrType + "/" + schemaName);
- return binder.getSchemaTO(schema, attributableUtil);
+ return read;
}
@PreAuthorize("hasRole('SCHEMA_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/{kind}/update")
- public SchemaTO update(@RequestBody final SchemaTO schemaTO, @PathVariable("kind") final String kind)
- throws NotFoundException {
+ public <T extends AbstractSchemaTO> void update(final AttributableType attrType, final SchemaType schemaType,
+ final String schemaName, final T schemaTO) {
- AttributableUtil attributableUtil = getAttributableUtil(kind);
- AbstractSchema schema = schemaDAO.find(schemaTO.getName(), attributableUtil.schemaClass());
- if (schema == null) {
- throw new NotFoundException("Schema '" + schemaTO.getName() + "'");
+ final AttributableUtil attrUtil = AttributableUtil.getInstance(attrType);
+
+ if (!doesSchemaExist(schemaType, schemaName, attrUtil)) {
+ throw new NotFoundException(schemaType + "/" + attrType + "/" + schemaName);
}
- binder.update(schemaTO, schema, attributableUtil);
- schema = schemaDAO.save(schema);
+ switch (schemaType) {
+ case VIRTUAL:
+ AbstractVirSchema virSchema = virSchemaDAO.find(schemaName, attrUtil.virSchemaClass());
+ if (virSchema == null) {
+ throw new NotFoundException("Virtual Schema '" + schemaName + "'");
+ }
+
+ binder.update((VirSchemaTO) schemaTO, virSchema);
+ virSchemaDAO.save(virSchema);
+ break;
+
+ case DERIVED:
+ AbstractDerSchema derSchema = derSchemaDAO.find(schemaName, attrUtil.derSchemaClass());
+ if (derSchema == null) {
+ throw new NotFoundException("Derived schema '" + schemaName + "'");
+ }
+
+ binder.update((DerSchemaTO) schemaTO, derSchema);
+ derSchemaDAO.save(derSchema);
+ break;
+
+ case NORMAL:
+ default:
+ AbstractSchema schema = schemaDAO.find(schemaName, attrUtil.schemaClass());
+ if (schema == null) {
+ throw new NotFoundException("Schema '" + schemaName + "'");
+ }
- auditManager.audit(Category.schema, SchemaSubCategory.update, Result.success,
- "Successfully updated schema: " + kind + "/" + schema.getName());
+ binder.update((SchemaTO) schemaTO, schema, attrUtil);
+ schemaDAO.save(schema);
+ }
- return binder.getSchemaTO(schema, attributableUtil);
+ auditManager.audit(AuditElements.Category.schema, AuditElements.SchemaSubCategory.update,
+ AuditElements.Result.success,
+ "Successfully updated schema: " + schemaType + "/" + attrType + "/" + schemaName);
}
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java?rev=1505995&r1=1505994&r2=1505995&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/TaskController.java Tue Jul 23 11:52:05 2013
@@ -22,7 +22,6 @@ import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;
-import javax.servlet.http.HttpServletResponse;
import org.apache.syncope.common.to.BulkAction;
import org.apache.syncope.common.to.BulkActionRes;
import org.apache.syncope.common.to.SchedTaskTO;
@@ -35,6 +34,7 @@ import org.apache.syncope.common.types.A
import org.apache.syncope.common.types.PropagationMode;
import org.apache.syncope.common.types.PropagationTaskExecStatus;
import org.apache.syncope.common.types.SyncopeClientExceptionType;
+import org.apache.syncope.common.types.TaskType;
import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException;
import org.apache.syncope.common.validation.SyncopeClientException;
import org.apache.syncope.core.audit.AuditManager;
@@ -60,16 +60,9 @@ import org.springframework.beans.factory
import org.springframework.http.HttpStatus;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.stereotype.Controller;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.servlet.ModelAndView;
+import org.springframework.stereotype.Component;
-@Controller
-@RequestMapping("/task")
+@Component
public class TaskController extends AbstractController {
@Autowired
@@ -99,23 +92,11 @@ public class TaskController extends Abst
@Autowired
private ImplementationClassNamesLoader classNamesLoader;
- @RequestMapping(method = RequestMethod.POST, value = "/create/sync")
- public TaskTO createSyncTask(final HttpServletResponse response, @RequestBody final SyncTaskTO taskTO) {
- return createSchedTask(response, taskTO);
- }
-
- @RequestMapping(method = RequestMethod.POST, value = "/create/sched")
- public TaskTO createSchedTask(final HttpServletResponse response, @RequestBody final SchedTaskTO taskTO) {
- TaskTO createdTaskTO = createSchedTaskInternal(taskTO);
- response.setStatus(HttpServletResponse.SC_CREATED);
- return createdTaskTO;
- }
-
@PreAuthorize("hasRole('TASK_CREATE')")
- public TaskTO createSchedTaskInternal(final SchedTaskTO taskTO) {
+ public TaskTO createSchedTask(final SchedTaskTO taskTO) {
LOG.debug("Creating task " + taskTO);
- TaskUtil taskUtil = getTaskUtil(taskTO);
+ TaskUtil taskUtil = TaskUtil.getInstance(taskTO);
SchedTask task = binder.createSchedTask(taskTO, taskUtil);
task = taskDAO.save(task);
@@ -140,14 +121,12 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/update/sync")
- public TaskTO updateSync(@RequestBody final SyncTaskTO taskTO) {
+ public TaskTO updateSync(final SyncTaskTO taskTO) {
return updateSched(taskTO);
}
@PreAuthorize("hasRole('TASK_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/update/sched")
- public TaskTO updateSched(@RequestBody final SchedTaskTO taskTO) {
+ public TaskTO updateSched(final SchedTaskTO taskTO) {
LOG.debug("Task update called with parameter {}", taskTO);
SchedTask task = taskDAO.find(taskTO.getId());
@@ -155,7 +134,7 @@ public class TaskController extends Abst
throw new NotFoundException("Task " + taskTO.getId());
}
- TaskUtil taskUtil = getTaskUtil(task);
+ TaskUtil taskUtil = TaskUtil.getInstance(task);
SyncopeClientCompositeErrorException scce = new SyncopeClientCompositeErrorException(HttpStatus.BAD_REQUEST);
@@ -179,25 +158,20 @@ public class TaskController extends Abst
return binder.getTaskTO(task, taskUtil);
}
- @RequestMapping(method = RequestMethod.GET, value = "/{kind}/count")
- public ModelAndView count(@PathVariable("kind") final String kind) {
- return new ModelAndView().addObject(countInternal(kind));
- }
-
@PreAuthorize("hasRole('TASK_LIST')")
- public int countInternal(final String kind) {
- return taskDAO.count(getTaskUtil(kind).taskClass());
+ public int count(final TaskType taskType) {
+ return taskDAO.count(TaskUtil.getInstance(taskType).taskClass());
}
@PreAuthorize("hasRole('TASK_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/{kind}/list")
- public List<TaskTO> list(@PathVariable("kind") final String kind) {
- TaskUtil taskUtil = getTaskUtil(kind);
+ @SuppressWarnings("unchecked")
+ public <T extends TaskTO> List<T> list(final TaskType taskType) {
+ TaskUtil taskUtil = TaskUtil.getInstance(taskType);
List<Task> tasks = taskDAO.findAll(taskUtil.taskClass());
- List<TaskTO> taskTOs = new ArrayList<TaskTO>(tasks.size());
+ List<T> taskTOs = new ArrayList<T>(tasks.size());
for (Task task : tasks) {
- taskTOs.add(binder.getTaskTO(task, taskUtil));
+ taskTOs.add((T) binder.getTaskTO(task, taskUtil));
}
auditManager.audit(Category.task, TaskSubCategory.list, Result.success,
@@ -207,16 +181,14 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/{kind}/list/{page}/{size}")
- public List<TaskTO> list(@PathVariable("kind") final String kind, @PathVariable("page") final int page,
- @PathVariable("size") final int size) {
-
- TaskUtil taskUtil = getTaskUtil(kind);
+ @SuppressWarnings("unchecked")
+ public <T extends TaskTO> List<T> list(final TaskType taskType, final int page, final int size) {
+ TaskUtil taskUtil = TaskUtil.getInstance(taskType);
List<Task> tasks = taskDAO.findAll(page, size, taskUtil.taskClass());
- List<TaskTO> taskTOs = new ArrayList<TaskTO>(tasks.size());
+ List<T> taskTOs = new ArrayList<T>(tasks.size());
for (Task task : tasks) {
- taskTOs.add(binder.getTaskTO(task, taskUtil));
+ taskTOs.add((T) binder.getTaskTO(task, taskUtil));
}
auditManager.audit(Category.task, TaskSubCategory.list, Result.success,
@@ -227,35 +199,32 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/jobClasses")
- public ModelAndView getJobClasses() {
+ public Set<String> getJobClasses() {
Set<String> jobClasses = classNamesLoader.getClassNames(ImplementationClassNamesLoader.Type.TASKJOB);
auditManager.audit(Category.task, TaskSubCategory.getJobClasses, Result.success,
"Successfully listed all Job classes: " + jobClasses.size());
- return new ModelAndView().addObject(jobClasses);
+ return jobClasses;
}
@PreAuthorize("hasRole('TASK_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/syncActionsClasses")
- public ModelAndView getSyncActionsClasses() {
+ public Set<String> getSyncActionsClasses() {
Set<String> actionsClasses = classNamesLoader.getClassNames(ImplementationClassNamesLoader.Type.SYNC_ACTIONS);
auditManager.audit(Category.task, TaskSubCategory.getSyncActionsClasses, Result.success,
"Successfully listed all SyncActions classes: " + actionsClasses.size());
- return new ModelAndView().addObject(actionsClasses);
+ return actionsClasses;
}
@PreAuthorize("hasRole('TASK_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/read/{taskId}")
- public TaskTO read(@PathVariable("taskId") final Long taskId) {
+ public TaskTO read(final Long taskId) {
Task task = taskDAO.find(taskId);
if (task == null) {
throw new NotFoundException("Task " + taskId);
}
- TaskUtil taskUtil = getTaskUtil(task);
+ TaskUtil taskUtil = TaskUtil.getInstance(task);
auditManager.audit(Category.task, TaskSubCategory.read, Result.success,
"Successfully read task: " + task.getId() + "/" + taskUtil);
@@ -264,8 +233,7 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/execution/read/{executionId}")
- public TaskExecTO readExecution(@PathVariable("executionId") final Long executionId) {
+ public TaskExecTO readExecution(final Long executionId) {
TaskExec taskExec = taskExecDAO.find(executionId);
if (taskExec == null) {
throw new NotFoundException("Task execution " + executionId);
@@ -278,19 +246,16 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_EXECUTE')")
- @RequestMapping(method = RequestMethod.POST, value = "/execute/{taskId}")
- public TaskExecTO execute(@PathVariable("taskId") final Long taskId,
- @RequestParam(value = "dryRun", defaultValue = "false") final boolean dryRun) {
-
+ public TaskExecTO execute(final Long taskId, final boolean dryRun) {
Task task = taskDAO.find(taskId);
if (task == null) {
throw new NotFoundException("Task " + taskId);
}
- TaskUtil taskUtil = getTaskUtil(task);
+ TaskUtil taskUtil = TaskUtil.getInstance(task);
TaskExecTO result = null;
LOG.debug("Execution started for {}", task);
- switch (taskUtil) {
+ switch (taskUtil.getType()) {
case PROPAGATION:
final TaskExec propExec = taskExecutor.execute((PropagationTask) task);
result = binder.getTaskExecTO(propExec);
@@ -301,8 +266,8 @@ public class TaskController extends Abst
result = binder.getTaskExecTO(notExec);
break;
- case SCHED:
- case SYNC:
+ case SCHEDULED:
+ case SYNCHRONIZATION:
try {
jobInstanceLoader.registerJob(task,
((SchedTask) task).getJobClassName(),
@@ -345,11 +310,7 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/execution/report/{executionId}")
- public TaskExecTO report(@PathVariable("executionId") final Long executionId,
- @RequestParam("executionStatus") final PropagationTaskExecStatus status,
- @RequestParam("message") final String message) {
-
+ public TaskExecTO report(final Long executionId, final PropagationTaskExecStatus status, final String message) {
TaskExec exec = taskExecDAO.find(executionId);
if (exec == null) {
throw new NotFoundException("Task execution " + executionId);
@@ -358,8 +319,8 @@ public class TaskController extends Abst
SyncopeClientException sce = new SyncopeClientException(
SyncopeClientExceptionType.InvalidPropagationTaskExecReport);
- TaskUtil taskUtil = getTaskUtil(exec.getTask());
- if (TaskUtil.PROPAGATION == taskUtil) {
+ TaskUtil taskUtil = TaskUtil.getInstance(exec.getTask());
+ if (TaskType.PROPAGATION == taskUtil.getType()) {
PropagationTask task = (PropagationTask) exec.getTask();
if (task.getPropagationMode() != PropagationMode.TWO_PHASES) {
sce.addElement("Propagation mode: " + task.getPropagationMode());
@@ -404,17 +365,16 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/delete/{taskId}")
- public TaskTO delete(@PathVariable("taskId") final Long taskId) {
+ public TaskTO delete(final Long taskId) {
Task task = taskDAO.find(taskId);
if (task == null) {
throw new NotFoundException("Task " + taskId);
}
- TaskUtil taskUtil = getTaskUtil(task);
+ TaskUtil taskUtil = TaskUtil.getInstance(task);
TaskTO taskToDelete = binder.getTaskTO(task, taskUtil);
- if (TaskUtil.SCHED == taskUtil || TaskUtil.SYNC == taskUtil) {
+ if (TaskType.SCHEDULED == taskUtil.getType() || TaskType.SYNCHRONIZATION == taskUtil.getType()) {
jobInstanceLoader.unregisterJob(task);
}
@@ -427,8 +387,7 @@ public class TaskController extends Abst
}
@PreAuthorize("hasRole('TASK_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/execution/delete/{executionId}")
- public TaskExecTO deleteExecution(@PathVariable("executionId") final Long executionId) {
+ public TaskExecTO deleteExecution(final Long executionId) {
TaskExec taskExec = taskExecDAO.find(executionId);
if (taskExec == null) {
throw new NotFoundException("Task execution " + executionId);
@@ -447,8 +406,7 @@ public class TaskController extends Abst
+ "(hasRole('TASK_EXECUTE') and "
+ "(#bulkAction.operation == #bulkAction.operation.EXECUTE or "
+ "#bulkAction.operation == #bulkAction.operation.DRYRUN))")
- @RequestMapping(method = RequestMethod.POST, value = "/bulk")
- public BulkActionRes bulkAction(@RequestBody final BulkAction bulkAction) {
+ public BulkActionRes bulkAction(final BulkAction bulkAction) {
LOG.debug("Bulk action '{}' called on '{}'", bulkAction.getOperation(), bulkAction.getTargets());
BulkActionRes res = new BulkActionRes();
@@ -464,6 +422,7 @@ public class TaskController extends Abst
}
}
break;
+
case DRYRUN:
for (String taskId : bulkAction.getTargets()) {
try {
@@ -475,6 +434,7 @@ public class TaskController extends Abst
}
}
break;
+
case EXECUTE:
for (String taskId : bulkAction.getTargets()) {
try {
@@ -486,6 +446,7 @@ public class TaskController extends Abst
}
}
break;
+
default:
}
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java?rev=1505995&r1=1505994&r2=1505995&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/UserController.java Tue Jul 23 11:52:05 2013
@@ -18,14 +18,12 @@
*/
package org.apache.syncope.core.rest.controller;
-import java.util.AbstractMap.SimpleEntry;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import javax.servlet.http.HttpServletResponse;
import org.apache.syncope.common.mod.UserMod;
import org.apache.syncope.common.search.NodeCond;
import org.apache.syncope.common.services.InvalidSearchConditionException;
@@ -36,7 +34,6 @@ import org.apache.syncope.common.to.Memb
import org.apache.syncope.common.to.PropagationRequestTO;
import org.apache.syncope.common.to.PropagationStatusTO;
import org.apache.syncope.common.to.UserTO;
-import org.apache.syncope.common.to.WorkflowFormTO;
import org.apache.syncope.common.types.AttributableType;
import org.apache.syncope.common.types.AuditElements.Category;
import org.apache.syncope.common.types.AuditElements.Result;
@@ -63,15 +60,8 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.stereotype.Controller;
+import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.web.bind.annotation.PathVariable;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestMethod;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.servlet.ModelAndView;
/**
* Note that this controller does not extend AbstractController, hence does not provide any Spring's Transactional logic
@@ -79,8 +69,7 @@ import org.springframework.web.servlet.M
*
* @see AbstractController
*/
-@Controller
-@RequestMapping("/user")
+@Component
public class UserController {
/**
@@ -118,42 +107,15 @@ public class UserController {
@Autowired
protected ConnObjectUtil connObjectUtil;
- @RequestMapping(method = RequestMethod.GET, value = "/verifyPassword/{username}")
- public ModelAndView verifyPassword(@PathVariable("username") String username,
- @RequestParam("password") final String password) {
-
- return new ModelAndView().addObject(verifyPasswordInternal(username, password));
- }
-
- @PreAuthorize("hasRole('USER_READ')")
- @Transactional(readOnly = true)
- public Boolean verifyPasswordInternal(final String username, final String password) {
- auditManager.audit(Category.user, UserSubCategory.create, Result.success,
- "Verified password for: " + username);
- return binder.verifyPassword(username, password);
- }
-
- @RequestMapping(method = RequestMethod.GET, value = "/count")
- public ModelAndView count() {
- return new ModelAndView().addObject(countInternal());
- }
-
@PreAuthorize("hasRole('USER_LIST')")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public int countInternal() {
+ public int count() {
return userDAO.count(EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames()));
}
- @RequestMapping(method = RequestMethod.POST, value = "/search/count")
- public ModelAndView searchCount(@RequestBody final NodeCond searchCondition)
- throws InvalidSearchConditionException {
-
- return new ModelAndView().addObject(searchCountInternal(searchCondition));
- }
-
@PreAuthorize("hasRole('USER_READ')")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public int searchCountInternal(final NodeCond searchCondition) throws InvalidSearchConditionException {
+ public int searchCount(final NodeCond searchCondition) throws InvalidSearchConditionException {
if (!searchCondition.isValid()) {
LOG.error("Invalid search condition: {}", searchCondition);
throw new InvalidSearchConditionException();
@@ -164,7 +126,6 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/list")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
public List<UserTO> list() {
List<SyncopeUser> users =
@@ -182,9 +143,8 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/list/{page}/{size}")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public List<UserTO> list(@PathVariable("page") final int page, @PathVariable("size") final int size) {
+ public List<UserTO> list(final int page, final int size) {
Set<Long> adminRoleIds = EntitlementUtil.getRoleIds(EntitlementUtil.getOwnedEntitlementNames());
List<SyncopeUser> users = userDAO.findAll(adminRoleIds, page, size);
@@ -200,9 +160,8 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/read/{userId}")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public UserTO read(@PathVariable("userId") final Long userId) {
+ public UserTO read(final Long userId) {
UserTO result = binder.getUserTO(userId);
auditManager.audit(Category.user, UserSubCategory.read, Result.success,
@@ -212,9 +171,8 @@ public class UserController {
}
@PreAuthorize("#username == authentication.name or hasRole('USER_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/readByUsername/{username}")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public UserTO read(@PathVariable final String username) {
+ public UserTO read(final String username) {
UserTO result = binder.getUserTO(username);
auditManager.audit(Category.user, UserSubCategory.read, Result.success,
@@ -224,7 +182,6 @@ public class UserController {
}
@PreAuthorize("isAuthenticated()")
- @RequestMapping(method = RequestMethod.GET, value = "/read/self")
@Transactional(readOnly = true)
public UserTO read() {
UserTO userTO = binder.getAuthenticatedUserTO();
@@ -236,19 +193,16 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_READ')")
- @RequestMapping(method = RequestMethod.POST, value = "/search")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public List<UserTO> search(@RequestBody final NodeCond searchCondition)
+ public List<UserTO> search(final NodeCond searchCondition)
throws InvalidSearchConditionException {
return search(searchCondition, -1, -1);
}
@PreAuthorize("hasRole('USER_READ')")
- @RequestMapping(method = RequestMethod.POST, value = "/search/{page}/{size}")
@Transactional(readOnly = true, rollbackFor = {Throwable.class})
- public List<UserTO> search(@RequestBody final NodeCond searchCondition, @PathVariable("page") final int page,
- @PathVariable("size") final int size)
+ public List<UserTO> search(final NodeCond searchCondition, final int page, final int size)
throws InvalidSearchConditionException {
LOG.debug("User search called with condition {}", searchCondition);
@@ -273,15 +227,8 @@ public class UserController {
return result;
}
- @RequestMapping(method = RequestMethod.POST, value = "/create")
- public UserTO create(final HttpServletResponse response, @RequestBody final UserTO userTO) {
- UserTO savedTO = createInternal(userTO);
- response.setStatus(HttpServletResponse.SC_CREATED);
- return savedTO;
- }
-
@PreAuthorize("hasRole('USER_CREATE')")
- public UserTO createInternal(final UserTO userTO) {
+ public UserTO create(final UserTO userTO) {
LOG.debug("User create called with {}", userTO);
Set<Long> requestRoleIds = new HashSet<Long>(userTO.getMemberships().size());
@@ -323,8 +270,7 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/update")
- public UserTO update(@RequestBody final UserMod userMod) {
+ public UserTO update(final UserMod userMod) {
LOG.debug("User update called with {}", userMod);
final String changedPwd = userMod.getPassword();
@@ -409,21 +355,14 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.GET, value = "/activate/{userId}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO activate(@PathVariable("userId") final Long userId,
- @RequestParam(required = true) final String token) {
-
+ public UserTO activate(final Long userId, final String token) {
return activate(userId, token, null);
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/activate/{userId}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO activate(@PathVariable("userId") final Long userId,
- @RequestParam(required = true) final String token,
- @RequestBody final PropagationRequestTO propagationRequestTO) {
-
+ public UserTO activate(final Long userId, final String token, final PropagationRequestTO propagationRequestTO) {
LOG.debug("About to activate " + userId);
SyncopeUser user = binder.getUserFromId(userId);
@@ -432,21 +371,14 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.GET, value = "/activateByUsername/{username}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO activate(@PathVariable("username") final String username,
- @RequestParam(required = true) final String token) {
-
+ public UserTO activate(final String username, final String token) {
return activate(username, token, null);
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/activateByUsername/{username}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO activate(@PathVariable("username") final String username,
- @RequestParam(required = true) final String token,
- @RequestBody final PropagationRequestTO propagationRequestTO) {
-
+ public UserTO activate(final String username, final String token, final PropagationRequestTO propagationRequestTO) {
LOG.debug("About to activate " + username);
SyncopeUser user = binder.getUserFromUsername(username);
@@ -455,19 +387,14 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.GET, value = "/suspend/{userId}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO suspend(@PathVariable("userId") final Long userId) {
-
+ public UserTO suspend(final Long userId) {
return suspend(userId, null);
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/suspend/{userId}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO suspend(@PathVariable("userId") final Long userId,
- @RequestBody final PropagationRequestTO propagationRequestTO) {
-
+ public UserTO suspend(final Long userId, final PropagationRequestTO propagationRequestTO) {
LOG.debug("About to suspend " + userId);
SyncopeUser user = binder.getUserFromId(userId);
@@ -476,19 +403,14 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.GET, value = "/suspendByUsername/{username}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO suspend(@PathVariable("username") final String username) {
-
+ public UserTO suspend(final String username) {
return suspend(username, null);
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/suspendByUsername/{username}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO suspend(@PathVariable("username") final String username,
- @RequestBody final PropagationRequestTO propagationRequestTO) {
-
+ public UserTO suspend(final String username, final PropagationRequestTO propagationRequestTO) {
LOG.debug("About to suspend " + username);
SyncopeUser user = binder.getUserFromUsername(username);
@@ -497,19 +419,14 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.GET, value = "/reactivate/{userId}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO reactivate(@PathVariable("userId") final Long userId) {
-
+ public UserTO reactivate(final Long userId) {
return reactivate(userId, null);
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/reactivate/{userId}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO reactivate(@PathVariable("userId") final Long userId,
- @RequestBody final PropagationRequestTO propagationRequestTO) {
-
+ public UserTO reactivate(final Long userId, final PropagationRequestTO propagationRequestTO) {
LOG.debug("About to reactivate " + userId);
SyncopeUser user = binder.getUserFromId(userId);
@@ -517,19 +434,14 @@ public class UserController {
return setStatus(user, null, propagationRequestTO, true, "reactivate");
}
- @RequestMapping(method = RequestMethod.GET, value = "/reactivateByUsername/{username}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO reactivate(@PathVariable("username") final String username) {
-
+ public UserTO reactivate(final String username) {
return reactivate(username, null);
}
@PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/reactivateByUsername/{username}")
@Transactional(rollbackFor = {Throwable.class})
- public UserTO reactivate(@PathVariable("username") final String username,
- @RequestBody final PropagationRequestTO propagationRequestTO) {
-
+ public UserTO reactivate(final String username, final PropagationRequestTO propagationRequestTO) {
LOG.debug("About to reactivate " + username);
SyncopeUser user = binder.getUserFromUsername(username);
@@ -538,16 +450,14 @@ public class UserController {
}
@PreAuthorize("hasRole('USER_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/delete/{userId}")
- public UserTO delete(@PathVariable("userId") final Long userId) {
+ public UserTO delete(final Long userId) {
LOG.debug("User delete called with {}", userId);
return doDelete(userId);
}
@PreAuthorize("hasRole('USER_DELETE')")
- @RequestMapping(method = RequestMethod.GET, value = "/deleteByUsername/{username}")
- public UserTO delete(@PathVariable final String username) {
+ public UserTO delete(final String username) {
LOG.debug("User delete called with {}", username);
UserTO result = binder.getUserTO(username);
@@ -556,103 +466,6 @@ public class UserController {
return doDelete(userId);
}
- @PreAuthorize("hasRole('USER_UPDATE')")
- @RequestMapping(method = RequestMethod.POST, value = "/execute/workflow/{taskId}")
- public UserTO executeWorkflow(@RequestBody final UserTO userTO, @PathVariable("taskId") final String taskId) {
- LOG.debug("About to execute {} on {}", taskId, userTO.getId());
-
- WorkflowResult<Long> updated = uwfAdapter.execute(userTO, taskId);
-
- List<PropagationTask> tasks = propagationManager.getUserUpdateTaskIds(
- new WorkflowResult<Map.Entry<Long, Boolean>>(new SimpleEntry<Long, Boolean>(updated.getResult(), null),
- updated.getPropByRes(), updated.getPerformedTasks()));
-
- taskExecutor.execute(tasks);
-
- notificationManager.createTasks(updated.getResult(), updated.getPerformedTasks());
-
- final UserTO savedTO = binder.getUserTO(updated.getResult());
-
- LOG.debug("About to return updated user\n{}", savedTO);
-
- auditManager.audit(Category.user, UserSubCategory.executeWorkflow, Result.success,
- "Successfully executed workflow action " + taskId + " on user: " + userTO.getUsername());
-
- return savedTO;
- }
-
- @PreAuthorize("hasRole('WORKFLOW_FORM_LIST')")
- @RequestMapping(method = RequestMethod.GET, value = "/workflow/form/list")
- @Transactional(rollbackFor = {Throwable.class})
- public List<WorkflowFormTO> getForms() {
- List<WorkflowFormTO> forms = uwfAdapter.getForms();
-
- auditManager.audit(Category.user, UserSubCategory.getForms, Result.success,
- "Successfully list workflow forms: " + forms.size());
-
- return forms;
- }
-
- @PreAuthorize("hasRole('WORKFLOW_FORM_READ') and hasRole('USER_READ')")
- @RequestMapping(method = RequestMethod.GET, value = "/workflow/form/{userId}")
- @Transactional(rollbackFor = {Throwable.class})
- public WorkflowFormTO getFormForUser(@PathVariable("userId") final Long userId) {
- SyncopeUser user = binder.getUserFromId(userId);
- WorkflowFormTO result = uwfAdapter.getForm(user.getWorkflowId());
-
- auditManager.audit(Category.user, UserSubCategory.getFormForUser, Result.success,
- "Successfully read workflow form for user: " + user.getUsername());
-
- return result;
- }
-
- @PreAuthorize("hasRole('WORKFLOW_FORM_CLAIM')")
- @RequestMapping(method = RequestMethod.GET, value = "/workflow/form/claim/{taskId}")
- @Transactional(rollbackFor = {Throwable.class})
- public WorkflowFormTO claimForm(@PathVariable("taskId") final String taskId) {
- WorkflowFormTO result = uwfAdapter.claimForm(taskId,
- SecurityContextHolder.getContext().getAuthentication().getName());
-
- auditManager.audit(Category.user, UserSubCategory.claimForm, Result.success,
- "Successfully claimed workflow form: " + taskId);
-
- return result;
- }
-
- @PreAuthorize("hasRole('WORKFLOW_FORM_SUBMIT')")
- @RequestMapping(method = RequestMethod.POST, value = "/workflow/form/submit")
- @Transactional(rollbackFor = {Throwable.class})
- public UserTO submitForm(@RequestBody final WorkflowFormTO form) {
- LOG.debug("About to process form {}", form);
-
- WorkflowResult<Map.Entry<Long, String>> updated = uwfAdapter.submitForm(form,
- SecurityContextHolder.getContext().getAuthentication().getName());
-
- // propByRes can be made empty by the workflow definition is no propagation should occur
- // (for example, with rejected users)
- if (updated.getPropByRes() != null && !updated.getPropByRes().isEmpty()) {
- List<PropagationTask> tasks = propagationManager.getUserUpdateTaskIds(
- new WorkflowResult<Map.Entry<Long, Boolean>>(
- new SimpleEntry<Long, Boolean>(updated.getResult().getKey(), Boolean.TRUE),
- updated.getPropByRes(),
- updated.getPerformedTasks()),
- updated.getResult().getValue(),
- null,
- null,
- null);
- taskExecutor.execute(tasks);
- }
-
- final UserTO savedTO = binder.getUserTO(updated.getResult().getKey());
-
- auditManager.audit(Category.user, UserSubCategory.submitForm, Result.success,
- "Successfully submitted workflow form for user: " + savedTO.getUsername());
-
- LOG.debug("About to return user after form processing\n{}", savedTO);
-
- return savedTO;
- }
-
protected UserTO setStatus(final SyncopeUser user, final String token,
final PropagationRequestTO propagationRequestTO, final boolean status, final String task) {
@@ -736,8 +549,7 @@ public class UserController {
+ "(hasRole('USER_UPDATE') and "
+ "(#bulkAction.operation == #bulkAction.operation.REACTIVATE or "
+ "#bulkAction.operation == #bulkAction.operation.SUSPEND))")
- @RequestMapping(method = RequestMethod.POST, value = "/bulk")
- public BulkActionRes bulkAction(@RequestBody final BulkAction bulkAction) {
+ public BulkActionRes bulkAction(final BulkAction bulkAction) {
LOG.debug("Bulk action '{}' called on '{}'", bulkAction.getOperation(), bulkAction.getTargets());
BulkActionRes res = new BulkActionRes();