http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/GroupService.java ---------------------------------------------------------------------- diff --git a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/GroupService.java b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/GroupService.java index 001d71c..7d48b46 100644 --- a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/GroupService.java +++ b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/GroupService.java @@ -19,47 +19,21 @@ package org.apache.syncope.common.rest.api.service; import java.util.List; -import javax.validation.constraints.NotNull; -import javax.ws.rs.BeanParam; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.GET; -import javax.ws.rs.POST; import javax.ws.rs.Path; -import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.model.wadl.Description; import org.apache.cxf.jaxrs.model.wadl.Descriptions; import org.apache.cxf.jaxrs.model.wadl.DocTarget; import org.apache.syncope.common.lib.mod.GroupMod; -import org.apache.syncope.common.lib.to.BulkAction; -import org.apache.syncope.common.lib.to.BulkActionResult; -import org.apache.syncope.common.lib.to.PagedResult; import org.apache.syncope.common.lib.to.GroupTO; -import org.apache.syncope.common.lib.types.ResourceAssociationActionType; -import org.apache.syncope.common.lib.types.ResourceDeassociationActionType; -import org.apache.syncope.common.lib.wrap.ResourceKey; -import org.apache.syncope.common.rest.api.beans.AnyListQuery; -import org.apache.syncope.common.rest.api.beans.AnySearchQuery; /** * REST operations for groups. */ @Path("groups") -public interface GroupService extends JAXRSService { - - /** - * Reads the group matching the provided groupKey. - * - * @param groupKey key of group to be read - * @return group with matching id - */ - @GET - @Path("{groupKey}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - GroupTO read(@NotNull @PathParam("groupKey") Long groupKey); +public interface GroupService extends AnyService<GroupTO, GroupMod> { /** * This method is similar to {@link #read(Long)}, but uses different authentication handling to ensure that a user @@ -76,134 +50,4 @@ public interface GroupService extends JAXRSService { @Path("own") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) List<GroupTO> own(); - - /** - * Returns a paged list of existing groups matching the given query. - * - * @param listQuery query conditions - * @return paged list of existing groups matching the given query - */ - @GET - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - PagedResult<GroupTO> list(@BeanParam AnyListQuery listQuery); - - /** - * Returns a paged list of groups matching the given query. - * - * @param searchQuery query conditions - * @return paged list of groups matching the given query - */ - @GET - @Path("search") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - PagedResult<GroupTO> search(@BeanParam AnySearchQuery searchQuery); - - /** - * Creates a new group. - * - * @param groupTO group to be created - * @return <tt>Response</tt> object featuring <tt>Location</tt> header of created group as well as the group itself - * enriched with propagation status information - {@link GroupTO} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring <tt>Location</tt> header of created group as well as the " - + "group itself enriched with propagation status information - <tt>GroupTO</tt> as <tt>Entity</tt>") - }) - @POST - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response create(@NotNull GroupTO groupTO); - - /** - * Updates group matching the provided groupKey. - * - * @param groupKey key of group to be updated - * @param groupMod modification to be applied to group matching the provided groupKey - * @return <tt>Response</tt> object featuring the updated group enriched with propagation status information - * - {@link GroupTO} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring the updated group enriched with propagation status information - " - + "<tt>GroupTO</tt> as <tt>Entity</tt>") - }) - @POST - @Path("{groupKey}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response update(@NotNull @PathParam("groupKey") Long groupKey, @NotNull GroupMod groupMod); - - /** - * Deletes group matching provided groupKey. - * - * @param groupKey key of group to be deleted - * @return <tt>Response</tt> object featuring the deleted group enriched with propagation status information - * - {@link GroupTO} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring the deleted group enriched with propagation status information - " - + "<tt>GroupTO</tt> as <tt>Entity</tt>") - }) - @DELETE - @Path("{groupKey}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response delete(@NotNull @PathParam("groupKey") Long groupKey); - - /** - * Executes resource-related operations on given group. - * - * @param groupKey group id. - * @param type resource association action type - * @param resourceNames external resources to be used for propagation-related operations - * @return <tt>Response</tt> object featuring - * {@link BulkActionResult} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring <tt>BulkActionResult</tt> as <tt>Entity</tt>") - }) - @POST - @Path("{groupKey}/deassociate/{type}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response bulkDeassociation( - @NotNull @PathParam("groupKey") Long groupKey, - @NotNull @PathParam("type") ResourceDeassociationActionType type, - @NotNull List<ResourceKey> resourceNames); - - /** - * Executes resource-related operations on given group. - * - * @param groupKey group id. - * @param type resource association action type - * @param resourceNames external resources to be used for propagation-related operations - * @return <tt>Response</tt> object featuring {@link BulkActionResult} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring <tt>BulkActionResult</tt> as <tt>Entity</tt>") - }) - @POST - @Path("{groupKey}/associate/{type}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response bulkAssociation( - @NotNull @PathParam("groupKey") Long groupKey, - @NotNull @PathParam("type") ResourceAssociationActionType type, - @NotNull List<ResourceKey> resourceNames); - - /** - * Executes the provided bulk action. - * - * @param bulkAction list of group ids against which the bulk action will be performed. - * @return Bulk action result - */ - @POST - @Path("bulk") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - BulkActionResult bulk(@NotNull BulkAction bulkAction); }
http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserService.java ---------------------------------------------------------------------- diff --git a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserService.java b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserService.java index 4866f95..bf1e6b7 100644 --- a/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserService.java +++ b/common/rest-api/src/main/java/org/apache/syncope/common/rest/api/service/UserService.java @@ -18,13 +18,9 @@ */ package org.apache.syncope.common.rest.api.service; -import java.util.List; import javax.validation.constraints.NotNull; -import javax.ws.rs.BeanParam; import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.DefaultValue; -import javax.ws.rs.GET; import javax.ws.rs.OPTIONS; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -36,86 +32,45 @@ import javax.ws.rs.core.Response; import org.apache.cxf.jaxrs.model.wadl.Description; import org.apache.cxf.jaxrs.model.wadl.Descriptions; import org.apache.cxf.jaxrs.model.wadl.DocTarget; -import org.apache.syncope.common.lib.mod.ResourceAssociationMod; import org.apache.syncope.common.lib.mod.StatusMod; import org.apache.syncope.common.lib.mod.UserMod; -import org.apache.syncope.common.lib.to.BulkAction; -import org.apache.syncope.common.lib.to.BulkActionResult; -import org.apache.syncope.common.lib.to.PagedResult; import org.apache.syncope.common.lib.to.UserTO; -import org.apache.syncope.common.lib.types.ResourceAssociationActionType; -import org.apache.syncope.common.lib.types.ResourceDeassociationActionType; -import org.apache.syncope.common.lib.wrap.ResourceKey; -import org.apache.syncope.common.rest.api.beans.AnyListQuery; -import org.apache.syncope.common.rest.api.beans.AnySearchQuery; /** * REST operations for users. */ @Path("users") -public interface UserService extends JAXRSService { +public interface UserService extends AnyService<UserTO, UserMod> { /** * Gives the username for the provided user key. * - * @param userKey user key - * @return <tt>Response</tt> object featuring HTTP header with username matching the given userKey + * @param key user key + * @return <tt>Response</tt> object featuring HTTP header with username matching the given key */ @Descriptions({ @Description(target = DocTarget.RESPONSE, - value = "Featuring HTTP header with username matching the given userKey") + value = "Featuring HTTP header with username matching the given key") }) @OPTIONS - @Path("{userKey}/username") - Response getUsername(@NotNull @PathParam("userKey") Long userKey); + @Path("{key}/username") + Response getUsername(@NotNull @PathParam("key") Long key); /** * Gives the user key for the provided username. * * @param username username - * @return <tt>Response</tt> object featuring HTTP header with userKey matching the given username + * @return <tt>Response</tt> object featuring HTTP header with key matching the given username */ @Descriptions({ @Description(target = DocTarget.RESPONSE, - value = "Featuring HTTP header with userKey matching the given username") + value = "Featuring HTTP header with key matching the given username") }) @OPTIONS - @Path("{username}/userKey") + @Path("{username}/key") Response getUserKey(@NotNull @PathParam("username") String username); /** - * Reads the user matching the provided userKey. - * - * @param userKey id of user to be read - * @return User matching the provided userKey - */ - @GET - @Path("{userKey}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - UserTO read(@NotNull @PathParam("userKey") Long userKey); - - /** - * Returns a paged list of existing users matching the given query. - * - * @param listQuery query conditions - * @return paged list of existing users matching the given query - */ - @GET - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - PagedResult<UserTO> list(@BeanParam AnyListQuery listQuery); - - /** - * Returns a paged list of users matching the given query. - * - * @param searchQuery query conditions - * @return paged list of users matching the given query - */ - @GET - @Path("search") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - PagedResult<UserTO> search(@BeanParam AnySearchQuery searchQuery); - - /** * Creates a new user. * * @param userTO user to be created @@ -136,28 +91,9 @@ public interface UserService extends JAXRSService { @DefaultValue("true") @QueryParam("storePassword") boolean storePassword); /** - * Updates user matching the provided userKey. + * Performs a status update on user matching provided key. * - * @param userKey id of user to be updated - * @param userMod modification to be applied to user matching the provided userKey - * @return <tt>Response</tt> object featuring the updated user enriched with propagation status information - * - {@link UserTO} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring the updated user enriched with propagation status information - " - + "<tt>UserTO</tt> as <tt>Entity</tt>") - }) - @POST - @Path("{userKey}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response update(@NotNull @PathParam("userKey") Long userKey, @NotNull UserMod userMod); - - /** - * Performs a status update on user matching provided userKey. - * - * @param userKey id of user to be subjected to status update + * @param key id of user to be subjected to status update * @param statusMod status update details * @return <tt>Response</tt> object featuring the updated user enriched with propagation status information * - {@link UserTO} as <tt>Entity</tt> @@ -168,78 +104,8 @@ public interface UserService extends JAXRSService { + "<tt>UserTO</tt> as <tt>Entity</tt>") }) @POST - @Path("{userKey}/status") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response status(@NotNull @PathParam("userKey") Long userKey, @NotNull StatusMod statusMod); - - /** - * Deletes user matching provided userKey. - * - * @param userKey id of user to be deleted - * @return <tt>Response</tt> object featuring the deleted user enriched with propagation status information - * - {@link UserTO} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring the deleted user enriched with propagation status information - " - + "<tt>UserTO</tt> as <tt>Entity</tt>") - }) - @DELETE - @Path("{userKey}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response delete(@NotNull @PathParam("userKey") Long userKey); - - /** - * Executes resource-related operations on given user. - * - * @param userKey user key - * @param type resource de-association action type - * @param resourceNames external resources to be used for propagation-related operations - * @return <tt>Response</tt> object featuring {@link BulkActionResult} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, - value = "Featuring <tt>BulkActionResult</tt> as <tt>Entity</tt>") - }) - @POST - @Path("{userKey}/bulkDeassociation/{type}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response bulkDeassociation( - @NotNull @PathParam("userKey") Long userKey, - @NotNull @PathParam("type") ResourceDeassociationActionType type, - @NotNull List<ResourceKey> resourceNames); - - /** - * Executes resource-related operations on given user. - * - * @param userKey user key. - * @param type resource association action type - * @param associationMod external resources to be used for propagation-related operations - * @return <tt>Response</tt> object featuring {@link BulkActionResult} as <tt>Entity</tt> - */ - @Descriptions({ - @Description(target = DocTarget.RESPONSE, value = "Featuring <tt>BulkActionResult</tt> as <tt>Entity</tt>") - }) - @POST - @Path("{userKey}/bulkAssociation/{type}") - @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - Response bulkAssociation( - @NotNull @PathParam("userKey") Long userKey, - @NotNull @PathParam("type") ResourceAssociationActionType type, - @NotNull ResourceAssociationMod associationMod); - - /** - * Executes the provided bulk action. - * - * @param bulkAction list of user keys against which the bulk action will be performed. - * @return Bulk action result - */ - @POST - @Path("bulk") + @Path("{key}/status") @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) @Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON }) - BulkActionResult bulk(@NotNull BulkAction bulkAction); + Response status(@NotNull @PathParam("key") Long key, @NotNull StatusMod statusMod); } http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractAnyLogic.java ---------------------------------------------------------------------- diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractAnyLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractAnyLogic.java index 83e90da..d24b08e 100644 --- a/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractAnyLogic.java +++ b/core/logic/src/main/java/org/apache/syncope/core/logic/AbstractAnyLogic.java @@ -30,8 +30,8 @@ import org.apache.syncope.core.misc.RealmUtils; import org.apache.syncope.core.persistence.api.dao.search.OrderByClause; import org.apache.syncope.core.persistence.api.dao.search.SearchCond; -public abstract class AbstractAnyLogic<T extends AnyTO, V extends AnyMod> - extends AbstractResourceAssociator<T> { +public abstract class AbstractAnyLogic<TO extends AnyTO, MOD extends AnyMod> + extends AbstractResourceAssociator<TO> { private static class StartsWithPredicate implements Predicate<String> { @@ -67,17 +67,19 @@ public abstract class AbstractAnyLogic<T extends AnyTO, V extends AnyMod> return effective; } - public abstract T read(Long key); + public abstract TO read(Long key); public abstract int count(List<String> realms); - public abstract T update(V anyMod); + public abstract TO create(TO anyTO); - public abstract T delete(Long key); + public abstract TO update(MOD anyMod); - public abstract List<T> list(int page, int size, List<OrderByClause> orderBy, List<String> realms); + public abstract TO delete(Long key); - public abstract List<T> search( + public abstract List<TO> list(int page, int size, List<OrderByClause> orderBy, List<String> realms); + + public abstract List<TO> search( SearchCond searchCondition, int page, int size, List<OrderByClause> orderBy, List<String> realms); public abstract int searchCount(SearchCond searchCondition, List<String> realms); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/logic/src/main/java/org/apache/syncope/core/logic/AnyObjectLogic.java ---------------------------------------------------------------------- diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/AnyObjectLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/AnyObjectLogic.java index 4919097..257bf42 100644 --- a/core/logic/src/main/java/org/apache/syncope/core/logic/AnyObjectLogic.java +++ b/core/logic/src/main/java/org/apache/syncope/core/logic/AnyObjectLogic.java @@ -29,6 +29,7 @@ import javax.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.Transformer; import org.apache.commons.lang3.ArrayUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.SyncopeConstants; import org.apache.syncope.common.lib.mod.AnyObjectMod; @@ -107,9 +108,19 @@ public class AnyObjectLogic extends AbstractAnyLogic<AnyObjectTO, AnyObjectMod> public List<AnyObjectTO> list( final int page, final int size, final List<OrderByClause> orderBy, final List<String> realms) { - return CollectionUtils.collect(anyObjectDAO.findAll( - getEffectiveRealms(SyncopeConstants.FULL_ADMIN_REALMS, realms), - page, size, orderBy), + return list(null, page, size, orderBy, realms); + } + + @PreAuthorize("hasRole('" + Entitlement.ANY_OBJECT_LIST + "')") + @Transactional(readOnly = true) + public List<AnyObjectTO> list(final String type, + final int page, final int size, final List<OrderByClause> orderBy, final List<String> realms) { + + Set<String> effectiveRealms = getEffectiveRealms(SyncopeConstants.FULL_ADMIN_REALMS, realms); + + return CollectionUtils.collect(StringUtils.isBlank(type) + ? anyObjectDAO.findAll(effectiveRealms, page, size, orderBy) + : anyObjectDAO.findAll(type, effectiveRealms, page, size, orderBy), new Transformer<AnyObject, AnyObjectTO>() { @Override @@ -147,10 +158,10 @@ public class AnyObjectLogic extends AbstractAnyLogic<AnyObjectTO, AnyObjectMod> } @PreAuthorize("hasRole('" + Entitlement.ANY_OBJECT_CREATE + "')") + @Override public AnyObjectTO create(final AnyObjectTO anyObjectTO) { if (anyObjectTO.getRealm() == null) { - SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm); - throw sce; + throw SyncopeClientException.build(ClientExceptionType.InvalidRealm); } Set<String> effectiveRealms = getEffectiveRealms( AuthContextUtils.getAuthorizations().get(Entitlement.ANY_OBJECT_CREATE), @@ -163,6 +174,10 @@ public class AnyObjectLogic extends AbstractAnyLogic<AnyObjectTO, AnyObjectMod> AnyObjectTO actual = attrTransformer.transform(anyObjectTO); LOG.debug("Transformed: {}", actual); + if (anyObjectTO.getType() == null) { + throw SyncopeClientException.build(ClientExceptionType.InvalidAnyType); + } + /* * Actual operations: workflow, propagation */ @@ -181,7 +196,7 @@ public class AnyObjectLogic extends AbstractAnyLogic<AnyObjectTO, AnyObjectMod> } Set<String> effectiveRealms = getEffectiveRealms( AuthContextUtils.getAuthorizations().get(Entitlement.ANY_OBJECT_UPDATE), - Collections.singleton(anyObjectMod.getRealm())); + Collections.singleton(anyObject.getRealm().getFullPath())); if (effectiveRealms.isEmpty()) { throw new UnauthorizedException(AnyTypeKind.ANY_OBJECT, anyObject.getKey()); } http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java ---------------------------------------------------------------------- diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java index 93af622..b0cfa03 100644 --- a/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java +++ b/core/logic/src/main/java/org/apache/syncope/core/logic/AnyTypeLogic.java @@ -25,7 +25,9 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.Transformer; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.AnyTypeTO; +import org.apache.syncope.common.lib.types.ClientExceptionType; import org.apache.syncope.common.lib.types.Entitlement; import org.apache.syncope.core.persistence.api.dao.NotFoundException; import org.apache.syncope.core.persistence.api.dao.AnyTypeDAO; @@ -96,7 +98,13 @@ public class AnyTypeLogic extends AbstractTransactionalLogic<AnyTypeTO> { } AnyTypeTO deleted = binder.getAnyTypeTO(anyType); - anyTypeDAO.delete(key); + try { + anyTypeDAO.delete(key); + } catch (IllegalArgumentException e) { + SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidAnyType); + sce.getElements().add(e.getMessage()); + throw sce; + } return deleted; } http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/logic/src/main/java/org/apache/syncope/core/logic/GroupLogic.java ---------------------------------------------------------------------- diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/GroupLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/GroupLogic.java index d9216da..877a272 100644 --- a/core/logic/src/main/java/org/apache/syncope/core/logic/GroupLogic.java +++ b/core/logic/src/main/java/org/apache/syncope/core/logic/GroupLogic.java @@ -166,6 +166,7 @@ public class GroupLogic extends AbstractAnyLogic<GroupTO, GroupMod> { } @PreAuthorize("hasRole('" + Entitlement.GROUP_CREATE + "')") + @Override public GroupTO create(final GroupTO groupTO) { if (groupTO.getRealm() == null) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java ---------------------------------------------------------------------- diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java index 4ecab47..28e5cab 100644 --- a/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java +++ b/core/logic/src/main/java/org/apache/syncope/core/logic/UserLogic.java @@ -183,6 +183,12 @@ public class UserLogic extends AbstractAnyLogic<UserTO, UserMod> { } @PreAuthorize("hasRole('" + Entitlement.USER_CREATE + "')") + @Override + public UserTO create(final UserTO userTO) { + return create(userTO, true); + } + + @PreAuthorize("hasRole('" + Entitlement.USER_CREATE + "')") public UserTO create(final UserTO userTO, final boolean storePassword) { if (userTO.getRealm() == null) { SyncopeClientException sce = SyncopeClientException.build(ClientExceptionType.InvalidRealm); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java ---------------------------------------------------------------------- diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java index 807ea0f..6257d59 100644 --- a/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java +++ b/core/misc/src/main/java/org/apache/syncope/core/misc/ConnObjectUtils.java @@ -196,6 +196,7 @@ public class ConnObjectUtils { final SyncTask syncTask, final Provision provision, final AnyUtils anyUtils) { T anyTO = anyUtils.newAnyTO(); + anyTO.setType(provision.getAnyType().getKey()); // 1. fill with data from connector object anyTO.setRealm(syncTask.getDestinatioRealm().getFullPath()); @@ -206,6 +207,7 @@ public class ConnObjectUtils { switch (item.getIntMappingType()) { case UserKey: case GroupKey: + case AnyObjectKey: break; case Password: @@ -252,6 +254,7 @@ public class ConnObjectUtils { case UserPlainSchema: case GroupPlainSchema: + case AnyObjectPlainSchema: attrTO = new AttrTO(); attrTO.setSchema(item.getIntAttrName()); @@ -292,6 +295,7 @@ public class ConnObjectUtils { case UserDerivedSchema: case GroupDerivedSchema: + case AnyObjectDerivedSchema: attrTO = new AttrTO(); attrTO.setSchema(item.getIntAttrName()); anyTO.getDerAttrs().add(attrTO); @@ -299,6 +303,7 @@ public class ConnObjectUtils { case UserVirtualSchema: case GroupVirtualSchema: + case AnyObjectVirtualSchema: attrTO = new AttrTO(); attrTO.setSchema(item.getIntAttrName()); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java ---------------------------------------------------------------------- diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java b/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java index 140c5ad..e655809 100644 --- a/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java +++ b/core/misc/src/main/java/org/apache/syncope/core/misc/MappingUtils.java @@ -154,7 +154,7 @@ public final class MappingUtils { try { if (mapping.getIntMappingType() == IntMappingType.UserVirtualSchema || mapping.getIntMappingType() == IntMappingType.GroupVirtualSchema - || mapping.getIntMappingType() == IntMappingType.AnyVirtualSchema) { + || mapping.getIntMappingType() == IntMappingType.AnyObjectVirtualSchema) { LOG.debug("Expire entry cache {}-{}", any.getKey(), mapping.getIntAttrName()); virAttrCache.expire(any.getType().getKey(), any.getKey(), mapping.getIntAttrName()); @@ -270,7 +270,7 @@ public final class MappingUtils { switch (mapItem.getIntMappingType()) { case UserPlainSchema: case GroupPlainSchema: - case AnyPlainSchema: + case AnyObjectPlainSchema: final PlainSchemaDAO plainSchemaDAO = context.getBean(PlainSchemaDAO.class); schema = plainSchemaDAO.find(mapItem.getIntAttrName()); schemaType = schema == null ? AttrSchemaType.String : schema.getType(); @@ -278,7 +278,7 @@ public final class MappingUtils { case UserVirtualSchema: case GroupVirtualSchema: - case AnyVirtualSchema: + case AnyObjectVirtualSchema: VirSchemaDAO virSchemaDAO = context.getBean(VirSchemaDAO.class); VirSchema virSchema = virSchemaDAO.find(mapItem.getIntAttrName()); readOnlyVirSchema = (virSchema != null && virSchema.isReadonly()); @@ -442,7 +442,7 @@ public final class MappingUtils { switch (mappingItem.getIntMappingType()) { case UserPlainSchema: case GroupPlainSchema: - case AnyPlainSchema: + case AnyObjectPlainSchema: for (Any<?, ?, ?> any : anys) { PlainAttr<?> attr = any.getPlainAttr(mappingItem.getIntAttrName()); if (attr != null) { @@ -464,7 +464,7 @@ public final class MappingUtils { case UserVirtualSchema: case GroupVirtualSchema: - case AnyVirtualSchema: + case AnyObjectVirtualSchema: for (Any<?, ?, ?> any : anys) { AnyUtils anyUtils = anyUtilsFactory.getInstance(any); VirAttr<?> virAttr = any.getVirAttr(mappingItem.getIntAttrName()); @@ -501,7 +501,7 @@ public final class MappingUtils { case UserDerivedSchema: case GroupDerivedSchema: - case AnyDerivedSchema: + case AnyObjectDerivedSchema: for (Any<?, ?, ?> any : anys) { AnyUtils anyUtils = anyUtilsFactory.getInstance(any); DerAttr<?> derAttr = any.getDerAttr(mappingItem.getIntAttrName()); @@ -521,7 +521,7 @@ public final class MappingUtils { case UserKey: case GroupKey: - case AnyKey: + case AnyObjectKey: for (Any<?, ?, ?> any : anys) { AnyUtils anyUtils = anyUtilsFactory.getInstance(any); attrValue = anyUtils.newPlainAttrValue(); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/misc/src/main/java/org/apache/syncope/core/misc/search/SearchCondVisitor.java ---------------------------------------------------------------------- diff --git a/core/misc/src/main/java/org/apache/syncope/core/misc/search/SearchCondVisitor.java b/core/misc/src/main/java/org/apache/syncope/core/misc/search/SearchCondVisitor.java index a67cbf5..c7efa8a 100644 --- a/core/misc/src/main/java/org/apache/syncope/core/misc/search/SearchCondVisitor.java +++ b/core/misc/src/main/java/org/apache/syncope/core/misc/search/SearchCondVisitor.java @@ -37,6 +37,7 @@ import org.apache.syncope.core.persistence.api.dao.search.ResourceCond; import org.apache.syncope.core.persistence.api.dao.search.RoleCond; import org.apache.syncope.core.persistence.api.dao.search.SearchCond; import org.apache.syncope.core.persistence.api.dao.search.AnyCond; +import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond; /** * Converts CXF's <tt>SearchCondition</tt> into internal <tt>SearchCond</tt>. @@ -98,6 +99,12 @@ public class SearchCondVisitor extends AbstractSearchConditionVisitor<SearchBean leaf = SearchCond.getLeafCond(attributeCond); } else { switch (specialAttrName) { + case TYPE: + AnyTypeCond typeCond = new AnyTypeCond(); + typeCond.setAnyTypeName(value); + leaf = SearchCond.getLeafCond(typeCond); + break; + case GROUPS: MembershipCond groupCond = new MembershipCond(); groupCond.setGroupKey(Long.valueOf(value)); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java ---------------------------------------------------------------------- diff --git a/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java b/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java index 26068e9..caa9c54 100644 --- a/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java +++ b/core/misc/src/test/java/org/apache/syncope/core/misc/search/SearchCondConverterTest.java @@ -20,6 +20,7 @@ package org.apache.syncope.core.misc.search; import static org.junit.Assert.assertEquals; +import org.apache.syncope.common.lib.search.AnyObjectFiqlSearchConditionBuilder; import org.apache.syncope.common.lib.search.SpecialAttr; import org.apache.syncope.common.lib.search.UserFiqlSearchConditionBuilder; import org.apache.syncope.core.persistence.api.dao.search.AttributeCond; @@ -28,6 +29,7 @@ import org.apache.syncope.core.persistence.api.dao.search.ResourceCond; import org.apache.syncope.core.persistence.api.dao.search.RoleCond; import org.apache.syncope.core.persistence.api.dao.search.SearchCond; import org.apache.syncope.core.persistence.api.dao.search.AnyCond; +import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond; import org.junit.Test; public class SearchCondConverterTest { @@ -119,6 +121,18 @@ public class SearchCondConverterTest { } @Test + public void type() { + String fiqlExpression = new AnyObjectFiqlSearchConditionBuilder().type("PRINTER").query(); + assertEquals(SpecialAttr.TYPE + "==PRINTER", fiqlExpression); + + AnyTypeCond acond = new AnyTypeCond(); + acond.setAnyTypeName("PRINTER"); + SearchCond simpleCond = SearchCond.getLeafCond(acond); + + assertEquals(simpleCond, SearchCondConverter.convert(fiqlExpression)); + } + + @Test public void and() { String fiqlExpression = new UserFiqlSearchConditionBuilder(). is("fullname").equalTo("*o*").and("fullname").equalTo("*i*").query(); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java ---------------------------------------------------------------------- diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java index bd2f938..11d3c8e 100644 --- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java +++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/AnyObjectDAO.java @@ -20,6 +20,8 @@ package org.apache.syncope.core.persistence.api.dao; import java.util.Collection; import java.util.List; +import java.util.Set; +import org.apache.syncope.core.persistence.api.dao.search.OrderByClause; import org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship; import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject; import org.apache.syncope.core.persistence.api.entity.group.Group; @@ -28,7 +30,11 @@ import org.apache.syncope.core.persistence.api.entity.user.URelationship; public interface AnyObjectDAO extends AnyDAO<AnyObject> { - List<AnyObject> findByAnyType(String anyTypeName); + List<AnyObject> findAll(String anyTypeName, + Set<String> adminRealms, int page, int itemsPerPage); + + List<AnyObject> findAll(String anyTypeName, + Set<String> adminRealms, int page, int itemsPerPage, List<OrderByClause> orderBy); List<Group> findDynGroupMemberships(AnyObject anyObject); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AnyTypeCond.java ---------------------------------------------------------------------- diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AnyTypeCond.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AnyTypeCond.java new file mode 100644 index 0000000..a12a3e7 --- /dev/null +++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/AnyTypeCond.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.core.persistence.api.dao.search; + +public class AnyTypeCond extends AbstractSearchCond { + + private static final long serialVersionUID = 4298076973281246633L; + + private String anyTypeName; + + public String getAnyTypeName() { + return anyTypeName; + } + + public void setAnyTypeName(final String anyTypeName) { + this.anyTypeName = anyTypeName; + } + + @Override + public boolean isValid() { + return anyTypeName != null; + } + +} http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/SearchCond.java ---------------------------------------------------------------------- diff --git a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/SearchCond.java b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/SearchCond.java index d942591..82da594 100644 --- a/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/SearchCond.java +++ b/core/persistence-api/src/main/java/org/apache/syncope/core/persistence/api/dao/search/SearchCond.java @@ -35,6 +35,8 @@ public class SearchCond extends AbstractSearchCond { private Type type; + private AnyTypeCond anyTypeCond; + private AnyCond anyCond; private AttributeCond attributeCond; @@ -51,6 +53,15 @@ public class SearchCond extends AbstractSearchCond { private SearchCond rightNodeCond; + public static SearchCond getLeafCond(final AnyTypeCond anyTypeCond) { + SearchCond nodeCond = new SearchCond(); + + nodeCond.type = Type.LEAF; + nodeCond.anyTypeCond = anyTypeCond; + + return nodeCond; + } + public static SearchCond getLeafCond(final AttributeCond attributeCond) { SearchCond nodeCond = new SearchCond(); @@ -173,6 +184,14 @@ public class SearchCond extends AbstractSearchCond { } } + public AnyTypeCond getAnyTypeCond() { + return anyTypeCond; + } + + public void setAnyTypeCond(final AnyTypeCond anyTypeCond) { + this.anyTypeCond = anyTypeCond; + } + public AnyCond getAnyCond() { return anyCond; } @@ -256,9 +275,10 @@ public class SearchCond extends AbstractSearchCond { switch (type) { case LEAF: case NOT_LEAF: - isValid = (anyCond != null || attributeCond != null + isValid = (anyTypeCond != null || anyCond != null || attributeCond != null || relationshipCond != null || membershipCond != null || roleCond != null || resourceCond != null) + && (anyTypeCond == null || anyTypeCond.isValid()) && (anyCond == null || anyCond.isValid()) && (attributeCond == null || attributeCond.isValid()) && (membershipCond == null || membershipCond.isValid()) http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java index 298f5c4..968f990 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnyObjectDAO.java @@ -20,6 +20,7 @@ package org.apache.syncope.core.persistence.jpa.dao; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -33,6 +34,9 @@ import org.apache.syncope.core.misc.security.AuthContextUtils; import org.apache.syncope.core.misc.security.UnauthorizedException; import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; import org.apache.syncope.core.persistence.api.dao.GroupDAO; +import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond; +import org.apache.syncope.core.persistence.api.dao.search.OrderByClause; +import org.apache.syncope.core.persistence.api.dao.search.SearchCond; import org.apache.syncope.core.persistence.api.entity.AnyUtils; import org.apache.syncope.core.persistence.api.entity.anyobject.AMembership; import org.apache.syncope.core.persistence.api.entity.anyobject.ARelationship; @@ -43,7 +47,6 @@ import org.apache.syncope.core.persistence.api.entity.user.URelationship; import org.apache.syncope.core.persistence.jpa.entity.JPAAnyUtilsFactory; import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAADynGroupMembership; import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAARelationship; -import org.apache.syncope.core.persistence.jpa.entity.anyobject.JPAAnyObject; import org.apache.syncope.core.persistence.jpa.entity.user.JPAURelationship; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Repository; @@ -77,12 +80,21 @@ public class JPAAnyObjectDAO extends AbstractAnyDAO<AnyObject> implements AnyObj } @Override - public List<AnyObject> findByAnyType(final String anyTypeName) { - TypedQuery<AnyObject> query = entityManager.createQuery( - "SELECT e FROM " + JPAAnyObject.class.getSimpleName() + " e WHERE e.type.name=:name", AnyObject.class); - query.setParameter("name", anyTypeName); + public final List<AnyObject> findAll(final String anyTypeName, + final Set<String> adminRealms, final int page, final int itemsPerPage) { - return query.getResultList(); + return findAll(anyTypeName, adminRealms, page, itemsPerPage, Collections.<OrderByClause>emptyList()); + } + + @Override + public final List<AnyObject> findAll(final String anyTypeName, + final Set<String> adminRealms, final int page, final int itemsPerPage, final List<OrderByClause> orderBy) { + + AnyTypeCond anyTypeCond = new AnyTypeCond(); + anyTypeCond.setAnyTypeName(anyTypeName); + + return searchDAO.search(adminRealms, SearchCond.getLeafCond(anyTypeCond), page, itemsPerPage, orderBy, + getAnyUtils().getAnyTypeKind()); } @Override http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java index 6a14e58..b8ab75d 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAAnySearchDAO.java @@ -53,6 +53,7 @@ import org.apache.syncope.core.persistence.api.dao.search.ResourceCond; import org.apache.syncope.core.persistence.api.dao.search.RoleCond; import org.apache.syncope.core.persistence.api.dao.search.SearchCond; import org.apache.syncope.core.persistence.api.dao.search.AnyCond; +import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond; import org.apache.syncope.core.persistence.api.dao.search.RelationshipCond; import org.apache.syncope.core.persistence.api.entity.Any; import org.apache.syncope.core.persistence.api.entity.AnyUtils; @@ -420,6 +421,10 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?, ?, ?>, Long> implements case LEAF: case NOT_LEAF: + if (nodeCond.getAnyTypeCond() != null && AnyTypeKind.ANY_OBJECT == type) { + query.append(getQuery(nodeCond.getAnyTypeCond(), + nodeCond.getType() == SearchCond.Type.NOT_LEAF, parameters, svs)); + } if (nodeCond.getRelationshipCond() != null && (AnyTypeKind.USER == type || AnyTypeKind.ANY_OBJECT == type)) { @@ -470,6 +475,23 @@ public class JPAAnySearchDAO extends AbstractDAO<Any<?, ?, ?>, Long> implements return query; } + private String getQuery(final AnyTypeCond cond, final boolean not, final List<Object> parameters, + final SearchSupport svs) { + + StringBuilder query = new StringBuilder("SELECT DISTINCT any_id FROM "). + append(svs.field().name).append(" WHERE type_name"); + + if (not) { + query.append("<>"); + } else { + query.append('='); + } + + query.append('?').append(setParameter(parameters, cond.getAnyTypeName())); + + return query.toString(); + } + private String getQuery(final RelationshipCond cond, final boolean not, final List<Object> parameters, final SearchSupport svs) { http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java index 9d0f798..645c60c 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/JPAAnyUtils.java @@ -321,7 +321,7 @@ public class JPAAnyUtils implements AnyUtils { break; case ANY_OBJECT: - result = IntMappingType.AnyPlainSchema; + result = IntMappingType.AnyObjectPlainSchema; break; case USER: @@ -344,7 +344,7 @@ public class JPAAnyUtils implements AnyUtils { break; case ANY_OBJECT: - result = IntMappingType.AnyDerivedSchema; + result = IntMappingType.AnyObjectDerivedSchema; break; case USER: @@ -367,7 +367,7 @@ public class JPAAnyUtils implements AnyUtils { break; case ANY_OBJECT: - result = IntMappingType.AnyVirtualSchema; + result = IntMappingType.AnyObjectVirtualSchema; break; case USER: http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMapping.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMapping.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMapping.java index 227f0fd..2066f6f 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMapping.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMapping.java @@ -115,7 +115,7 @@ public class JPAMapping extends AbstractEntity<Long> implements Mapping { protected boolean addConnObjectKeyItem(final MappingItem connObjectKeyItem) { if (IntMappingType.UserVirtualSchema == connObjectKeyItem.getIntMappingType() || IntMappingType.GroupVirtualSchema == connObjectKeyItem.getIntMappingType() - || IntMappingType.AnyVirtualSchema == connObjectKeyItem.getIntMappingType() + || IntMappingType.AnyObjectVirtualSchema == connObjectKeyItem.getIntMappingType() || IntMappingType.Password == connObjectKeyItem.getIntMappingType()) { throw new IllegalArgumentException("Virtual attributes cannot be set as ConnObjectKey"); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMappingItem.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMappingItem.java b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMappingItem.java index 2aa587f..ae9a117 100644 --- a/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMappingItem.java +++ b/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/entity/resource/JPAMappingItem.java @@ -143,7 +143,7 @@ public class JPAMappingItem extends AbstractEntity<Long> implements MappingItem switch (getIntMappingType()) { case UserKey: case GroupKey: - case AnyKey: + case AnyObjectKey: name = "id"; break; http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyObjectTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyObjectTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyObjectTest.java index e3a4a74..e149969 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyObjectTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyObjectTest.java @@ -21,6 +21,7 @@ package org.apache.syncope.core.persistence.jpa.entity; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.List; import org.apache.syncope.common.lib.SyncopeConstants; @@ -48,6 +49,15 @@ public class AnyObjectTest extends AbstractTest { } @Test + public void findAllByType() { + List<AnyObject> list = anyObjectDAO.findAll("PRINTER", SyncopeConstants.FULL_ADMIN_REALMS, 1, 100); + assertFalse(list.isEmpty()); + + list = anyObjectDAO.findAll("UNEXISTING", SyncopeConstants.FULL_ADMIN_REALMS, 1, 100); + assertTrue(list.isEmpty()); + } + + @Test public void find() { AnyObject anyObject = anyObjectDAO.find(2L); assertNotNull(anyObject); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnySearchTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnySearchTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnySearchTest.java index fcc3982..018f632 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnySearchTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnySearchTest.java @@ -30,7 +30,6 @@ import java.util.List; import java.util.Set; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.Predicate; -import org.apache.cxf.ws.addressing.v200403.Relationship; import org.apache.syncope.common.lib.SyncopeConstants; import org.apache.syncope.common.lib.types.AnyTypeKind; import org.apache.syncope.core.persistence.api.dao.AnyObjectDAO; @@ -44,6 +43,7 @@ import org.apache.syncope.core.persistence.api.dao.search.ResourceCond; import org.apache.syncope.core.persistence.api.dao.search.RoleCond; import org.apache.syncope.core.persistence.api.dao.search.SearchCond; import org.apache.syncope.core.persistence.api.dao.search.AnyCond; +import org.apache.syncope.core.persistence.api.dao.search.AnyTypeCond; import org.apache.syncope.core.persistence.api.dao.search.RelationshipCond; import org.apache.syncope.core.persistence.api.entity.anyobject.AnyObject; import org.apache.syncope.core.persistence.api.entity.group.Group; @@ -72,7 +72,7 @@ public class AnySearchTest extends AbstractTest { public void anyObjectMatch() { AnyObject anyObject = anyObjectDAO.find(1L); assertNotNull(anyObject); - + RelationshipCond cond = new RelationshipCond(); cond.setAnyObjectKey(2L); assertTrue(searchDAO.matches(anyObject, SearchCond.getLeafCond(cond), AnyTypeKind.ANY_OBJECT)); @@ -385,6 +385,26 @@ public class AnySearchTest extends AbstractTest { } @Test + public void searchByType() { + AnyTypeCond tcond = new AnyTypeCond(); + tcond.setAnyTypeName("PRINTER"); + + SearchCond searchCondition = SearchCond.getLeafCond(tcond); + assertTrue(searchCondition.isValid()); + + List<AnyObject> printers = searchDAO.search( + SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.ANY_OBJECT); + assertNotNull(printers); + assertEquals(2, printers.size()); + + tcond.setAnyTypeName("UNEXISTING"); + printers = searchDAO.search( + SyncopeConstants.FULL_ADMIN_REALMS, searchCondition, AnyTypeKind.ANY_OBJECT); + assertNotNull(printers); + assertTrue(printers.isEmpty()); + } + + @Test public void userOrderBy() { AnyCond usernameLeafCond = new AnyCond(AnyCond.Type.EQ); usernameLeafCond.setSchema("username"); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyTypeTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyTypeTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyTypeTest.java index 2337a32..13937cc 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyTypeTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/AnyTypeTest.java @@ -57,10 +57,10 @@ public class AnyTypeTest extends AbstractTest { assertEquals(AnyTypeKind.GROUP.name(), groupType.getKey()); assertFalse(groupType.getClasses().isEmpty()); - AnyType otherType = anyTypeDAO.find("OTHER"); + AnyType otherType = anyTypeDAO.find("PRINTER"); assertNotNull(otherType); assertEquals(AnyTypeKind.ANY_OBJECT, otherType.getKind()); - assertEquals("OTHER", otherType.getKey()); + assertEquals("PRINTER", otherType.getKey()); } @Test @@ -100,11 +100,11 @@ public class AnyTypeTest extends AbstractTest { @Test public void delete() { - AnyType otherType = anyTypeDAO.find("OTHER"); + AnyType otherType = anyTypeDAO.find("PRINTER"); assertNotNull(otherType); anyTypeDAO.delete(otherType.getKey()); - assertNull(anyTypeDAO.find("OTHER")); + assertNull(anyTypeDAO.find("PRINTER")); } @Test(expected = IllegalArgumentException.class) http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java index 967a6be..7e86689 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/PlainSchemaTest.java @@ -47,7 +47,7 @@ public class PlainSchemaTest extends AbstractTest { @Test public void findAll() { List<PlainSchema> schemas = plainSchemaDAO.findAll(); - assertEquals(40, schemas.size()); + assertEquals(42, schemas.size()); } @Test http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ResourceTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ResourceTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ResourceTest.java index ee9a9f7..c058db7 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ResourceTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/ResourceTest.java @@ -82,7 +82,7 @@ public class ResourceTest extends AbstractTest { public void findAll() { List<ExternalResource> resources = resourceDAO.findAll(); assertNotNull(resources); - assertEquals(18, resources.size()); + assertEquals(19, resources.size()); } @Test @@ -294,7 +294,7 @@ public class ResourceTest extends AbstractTest { item = entityFactory.newEntity(MappingItem.class); item.setIntAttrName("mderiveddata"); item.setExtAttrName("mderiveddata"); - item.setIntMappingType(IntMappingType.AnyDerivedSchema); + item.setIntMappingType(IntMappingType.AnyObjectDerivedSchema); item.setPurpose(MappingPurpose.BOTH); mapping.add(item); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/TaskTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/TaskTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/TaskTest.java index 43d65d1..a4aed30 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/TaskTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/entity/TaskTest.java @@ -67,7 +67,7 @@ public class TaskTest extends AbstractTest { assertEquals(5, taskDAO.findAll(TaskType.PROPAGATION).size()); assertEquals(1, taskDAO.findAll(TaskType.NOTIFICATION).size()); assertEquals(1, taskDAO.findAll(TaskType.SCHEDULED).size()); - assertEquals(9, taskDAO.findAll(TaskType.SYNCHRONIZATION).size()); + assertEquals(10, taskDAO.findAll(TaskType.SYNCHRONIZATION).size()); assertEquals(11, taskDAO.findAll(TaskType.PUSH).size()); } http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java index b32e970..50b4c56 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/GroupTest.java @@ -158,7 +158,7 @@ public class GroupTest extends AbstractTest { User user = entityFactory.newEntity(User.class); user.setUsername("username"); user.setRealm(realmDAO.find("/even/two")); - user.add(anyTypeClassDAO.find("minimal other")); + user.add(anyTypeClassDAO.find("other")); UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); attr.setOwner(user); @@ -250,13 +250,13 @@ public class GroupTest extends AbstractTest { public void adynMembership() { // 0. create any object matching the condition below AnyObject anyObject = entityFactory.newEntity(AnyObject.class); - anyObject.setType(anyTypeDAO.find("OTHER")); + anyObject.setType(anyTypeDAO.find("PRINTER")); anyObject.setRealm(realmDAO.find("/even/two")); APlainAttr attr = entityFactory.newEntity(APlainAttr.class); attr.setOwner(anyObject); - attr.setSchema(plainSchemaDAO.find("cool")); - attr.add("true", anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT)); + attr.setSchema(plainSchemaDAO.find("model")); + attr.add("Canon MFC8030", anyUtilsFactory.getInstance(AnyTypeKind.ANY_OBJECT)); anyObject.add(attr); anyObject = anyObjectDAO.save(anyObject); @@ -269,7 +269,7 @@ public class GroupTest extends AbstractTest { group.setName("new"); ADynGroupMembership dynMembership = entityFactory.newEntity(ADynGroupMembership.class); - dynMembership.setFIQLCond("cool==true"); + dynMembership.setFIQLCond("model==Canon MFC8030"); dynMembership.setGroup(group); group.setADynMembership(dynMembership); @@ -288,7 +288,7 @@ public class GroupTest extends AbstractTest { // 3. verify that expected any objects have the created group dynamically assigned assertEquals(2, actual.getADynMembership().getMembers().size()); - assertEquals(new HashSet<>(Arrays.asList(2L, newAnyObjectKey)), + assertEquals(new HashSet<>(Arrays.asList(1L, newAnyObjectKey)), CollectionUtils.collect(actual.getADynMembership().getMembers(), new Transformer<AnyObject, Long>() { @Override @@ -297,7 +297,7 @@ public class GroupTest extends AbstractTest { } }, new HashSet<Long>())); - anyObject = anyObjectDAO.find(2L); + anyObject = anyObjectDAO.find(1L); assertNotNull(anyObject); Collection<Group> dynGroupMemberships = findDynGroupMemberships(anyObject); assertEquals(1, dynGroupMemberships.size()); @@ -310,7 +310,7 @@ public class GroupTest extends AbstractTest { actual = groupDAO.find(actual.getKey()); assertEquals(1, actual.getADynMembership().getMembers().size()); - assertEquals(2L, actual.getADynMembership().getMembers().get(0).getKey(), 0); + assertEquals(1L, actual.getADynMembership().getMembers().get(0).getKey(), 0); // 5. delete group and verify that dynamic membership was also removed Long dynMembershipKey = actual.getADynMembership().getKey(); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainSchemaTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainSchemaTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainSchemaTest.java index b92debb..7d363c2 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainSchemaTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/PlainSchemaTest.java @@ -79,7 +79,9 @@ public class PlainSchemaTest extends AbstractTest { // check for associated mappings Set<MappingItem> mapItems = new HashSet<>(); for (ExternalResource resource : resourceDAO.findAll()) { - if (resource.getProvision(anyTypeDAO.findUser()).getMapping() != null) { + if (resource.getProvision(anyTypeDAO.findUser()) != null + && resource.getProvision(anyTypeDAO.findUser()).getMapping() != null) { + for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) { if (schema.getKey().equals(mapItem.getIntAttrName())) { mapItems.add(mapItem); @@ -103,7 +105,9 @@ public class PlainSchemaTest extends AbstractTest { // check for mappings deletion mapItems = new HashSet<>(); for (ExternalResource resource : resourceDAO.findAll()) { - if (resource.getProvision(anyTypeDAO.findUser()).getMapping() != null) { + if (resource.getProvision(anyTypeDAO.findUser()) != null + && resource.getProvision(anyTypeDAO.findUser()).getMapping() != null) { + for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) { if ("fullname".equals(mapItem.getIntAttrName())) { mapItems.add(mapItem); @@ -128,7 +132,9 @@ public class PlainSchemaTest extends AbstractTest { // check for associated mappings Set<MappingItem> mappings = new HashSet<>(); for (ExternalResource resource : resourceDAO.findAll()) { - if (resource.getProvision(anyTypeDAO.findUser()).getMapping() != null) { + if (resource.getProvision(anyTypeDAO.findUser()) != null + && resource.getProvision(anyTypeDAO.findUser()).getMapping() != null) { + for (MappingItem mapItem : resource.getProvision(anyTypeDAO.findUser()).getMapping().getItems()) { if (schema.getKey().equals(mapItem.getIntAttrName())) { mappings.add(mapItem); http://git-wip-us.apache.org/repos/asf/syncope/blob/a45a46bb/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java ---------------------------------------------------------------------- diff --git a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java index 71fa878..5fdc803 100644 --- a/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java +++ b/core/persistence-jpa/src/test/java/org/apache/syncope/core/persistence/jpa/relationship/RoleTest.java @@ -88,7 +88,7 @@ public class RoleTest extends AbstractTest { User user = entityFactory.newEntity(User.class); user.setUsername("username"); user.setRealm(realmDAO.find("/even/two")); - user.add(anyTypeClassDAO.find("minimal other")); + user.add(anyTypeClassDAO.find("other")); UPlainAttr attr = entityFactory.newEntity(UPlainAttr.class); attr.setOwner(user);
