From 3d0d471254c585b5ecccf6f27075ff11b4e5c620 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 29 Apr 2013 12:21:03 +0000 Subject: [PATCH] use a bulk update mode with passing a list of update git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1476986 13f79535-47bb-0310-9956-ffa450edef68 --- .../api/services/LdapGroupMappingService.java | 37 ++++++++++--------- .../DefaultLdapGroupMappingService.java | 12 ++++-- 2 files changed, 27 insertions(+), 22 deletions(-) diff --git a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java index 2d312773..df3531b9 100644 --- a/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java +++ b/redback-integrations/redback-rest/redback-rest-api/src/main/java/org/apache/archiva/redback/rest/api/services/LdapGroupMappingService.java @@ -21,6 +21,7 @@ package org.apache.archiva.redback.rest.api.services; import org.apache.archiva.redback.authorization.RedbackAuthorization; import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants; import org.apache.archiva.redback.rest.api.model.LdapGroupMapping; +import org.apache.archiva.redback.rest.api.model.LdapGroupMappingUpdateRequest; import org.apache.archiva.redback.rest.api.model.StringList; import javax.ws.rs.Consumes; @@ -39,44 +40,44 @@ import java.util.List; * @author Olivier Lamy * @since 2.1 */ -@Path( "/ldapGroupMappingService/" ) +@Path("/ldapGroupMappingService/") public interface LdapGroupMappingService { - @Path( "ldapGroups" ) + @Path("ldapGroups") @GET - @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION ) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION) StringList getLdapGroups() throws RedbackServiceException; @GET - @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION ) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION) List getLdapGroupMappings() throws RedbackServiceException; @PUT - @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION ) + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION) Boolean addLdapGroupMapping( LdapGroupMapping ldapGroupMapping ) throws RedbackServiceException; @DELETE - @Path( "{group}" ) - @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION ) - Boolean removeLdapGroupMapping( @PathParam( "group" ) String group ) + @Path("{group}") + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION) + Boolean removeLdapGroupMapping( @PathParam("group") String group ) throws RedbackServiceException; @POST - @Consumes( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @Produces( { MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML } ) - @RedbackAuthorization( permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION ) - Boolean updateLdapGroupMapping( LdapGroupMapping ldapGroupMapping ) + @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML }) + @RedbackAuthorization(permissions = RedbackRoleConstants.CONFIGURATION_EDIT_OPERATION) + Boolean updateLdapGroupMapping( LdapGroupMappingUpdateRequest ldapGroupMappingUpdateRequest ) throws RedbackServiceException; } diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java index af5d8c0a..0632fe1e 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLdapGroupMappingService.java @@ -25,6 +25,7 @@ import org.apache.archiva.redback.common.ldap.connection.LdapException; import org.apache.archiva.redback.common.ldap.role.LdapRoleMapper; import org.apache.archiva.redback.common.ldap.role.LdapRoleMapperConfiguration; import org.apache.archiva.redback.rest.api.model.LdapGroupMapping; +import org.apache.archiva.redback.rest.api.model.LdapGroupMappingUpdateRequest; import org.apache.archiva.redback.rest.api.model.StringList; import org.apache.archiva.redback.rest.api.services.LdapGroupMappingService; import org.apache.archiva.redback.rest.api.services.RedbackServiceException; @@ -56,7 +57,7 @@ public class DefaultLdapGroupMappingService private LdapRoleMapper ldapRoleMapper; @Inject - @Named( value = "ldapRoleMapperConfiguration#default" ) + @Named(value = "ldapRoleMapperConfiguration#default") private LdapRoleMapperConfiguration ldapRoleMapperConfiguration; @Inject @@ -146,13 +147,16 @@ public class DefaultLdapGroupMappingService return Boolean.TRUE; } - public Boolean updateLdapGroupMapping( LdapGroupMapping ldapGroupMapping ) + public Boolean updateLdapGroupMapping( LdapGroupMappingUpdateRequest ldapGroupMappingUpdateRequest ) throws RedbackServiceException { try { - ldapRoleMapperConfiguration.updateLdapMapping( ldapGroupMapping.getGroup(), - new ArrayList( ldapGroupMapping.getRoleNames() ) ); + for ( LdapGroupMapping ldapGroupMapping : ldapGroupMappingUpdateRequest.getLdapGroupMapping() ) + { + ldapRoleMapperConfiguration.updateLdapMapping( ldapGroupMapping.getGroup(), + new ArrayList( ldapGroupMapping.getRoleNames() ) ); + } } catch ( MappingException e ) {