You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ma...@apache.org on 2021/01/04 14:22:53 UTC

[archiva] branch master updated (cae70e8 -> 510d21a)

This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git.


    from cae70e8  Fixing copyright
     new ee45f7b  Upgrading dependency check and suppress jquery upload
     new 23f3df0  Adding check-user script
     new 510d21a  Adding REST v2 implementations

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../services/v2/SecurityConfigurationService.java  | 136 ++++++++++-
 .../v2/DefaultSecurityConfigurationService.java    | 248 +++++++++++++++++++++
 .../apache/archiva/rest/services/v2/ErrorKeys.java |   6 +-
 archiva-modules/archiva-web/archiva-webapp/pom.xml |   2 +-
 .../resources/META-INF/owasp/cve-suppressions.xml  |   9 +
 .../resources/{generate-users.sh => check-user.sh} |  22 +-
 6 files changed, 403 insertions(+), 20 deletions(-)
 copy archiva-modules/archiva-web/archiva-webapp/src/test/resources/{generate-users.sh => check-user.sh} (69%)
 mode change 100644 => 100755


[archiva] 03/03: Adding REST v2 implementations

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit 510d21aa0975599105ccbe2bceea1ff94db0d325
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Mon Jan 4 15:22:36 2021 +0100

    Adding REST v2 implementations
---
 .../services/v2/SecurityConfigurationService.java  | 136 ++++++++++-
 .../v2/DefaultSecurityConfigurationService.java    | 248 +++++++++++++++++++++
 .../apache/archiva/rest/services/v2/ErrorKeys.java |   6 +-
 3 files changed, 384 insertions(+), 6 deletions(-)

diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
index 5292c0e..1a22c0d 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-api/src/main/java/org/apache/archiva/rest/api/services/v2/SecurityConfigurationService.java
@@ -18,8 +18,11 @@ package org.apache.archiva.rest.api.services.v2;/*
 
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.Parameters;
+import io.swagger.v3.oas.annotations.enums.ParameterIn;
 import io.swagger.v3.oas.annotations.media.Content;
 import io.swagger.v3.oas.annotations.media.Schema;
+import io.swagger.v3.oas.annotations.parameters.RequestBody;
 import io.swagger.v3.oas.annotations.responses.ApiResponse;
 import io.swagger.v3.oas.annotations.security.SecurityRequirement;
 import io.swagger.v3.oas.annotations.tags.Tag;
@@ -32,12 +35,16 @@ import org.apache.archiva.rest.api.model.v2.LdapConfiguration;
 import org.apache.archiva.rest.api.model.v2.SecurityConfiguration;
 import org.apache.archiva.security.common.ArchivaRoleConstants;
 
+import javax.ws.rs.Consumes;
 import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
+import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
 import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
 import java.util.List;
 
 import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@@ -58,7 +65,7 @@ public interface SecurityConfigurationService
 {
     @Path("config")
     @GET
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({ APPLICATION_JSON })
     @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     @Operation( summary = "Returns the security configuration that is currently active.",
         security = {
@@ -77,6 +84,28 @@ public interface SecurityConfigurationService
     SecurityConfiguration getConfiguration()
         throws ArchivaRestServiceException;
 
+    @Path("config")
+    @PUT
+    @Consumes({ APPLICATION_JSON })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    @Operation( summary = "Updates the security configuration.",
+        security = {
+            @SecurityRequirement(
+                name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
+            )
+        },
+        responses = {
+            @ApiResponse( responseCode = "200",
+                description = "If the configuration was updated"
+            ),
+            @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the configuration",
+                content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) )
+        }
+    )
+    Response updateConfiguration( SecurityConfiguration newConfiguration)
+        throws ArchivaRestServiceException;
+
+
     @Path( "config/properties" )
     @GET
     @Produces( { APPLICATION_JSON } )
@@ -109,9 +138,64 @@ public interface SecurityConfigurationService
                                                            @QueryParam( "orderBy") @DefaultValue( "key" ) List<String> orderBy,
                                                            @QueryParam("order") @DefaultValue( "asc" ) String order ) throws ArchivaRestServiceException;
 
+    @Path("config/properties/{propertyName}")
+    @GET
+    @Produces({ APPLICATION_JSON })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    @Operation( summary = "Returns a single configuration property value.",
+        security = {
+            @SecurityRequirement(
+                name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
+            )
+        },
+        parameters = {
+            @Parameter(in = ParameterIn.PATH, name="propertyName", description = "The name of the property to update")
+        },
+        responses = {
+            @ApiResponse( responseCode = "200",
+                description = "If the configuration could be retrieved"
+            ),
+            @ApiResponse( responseCode = "404", description = "The given property name does not exist",
+                content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) ),
+            @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
+                content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) )
+        }
+    )
+    PropertyEntry getConfigurationProperty( @PathParam ( "propertyName" )  String propertyName)
+        throws ArchivaRestServiceException;
+
+
+    @Path("config/properties/{propertyName}")
+    @PUT
+    @Consumes({ APPLICATION_JSON})
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    @Operation( summary = "Updates a single property value of the security configuration.",
+        security = {
+            @SecurityRequirement(
+                name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
+            )
+        },
+        requestBody = @RequestBody(required = true, description = "The property value"),
+        parameters = {
+            @Parameter(in = ParameterIn.PATH, name="propertyName", description = "The name of the property to update")
+        },
+        responses = {
+            @ApiResponse( responseCode = "200",
+                description = "If the property value was updated."
+            ),
+            @ApiResponse( responseCode = "404", description = "The given property name does not exist",
+                content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) ),
+            @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to gather the information",
+                content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) )
+        }
+    )
+    Response updateConfigurationProperty( @PathParam ( "propertyName" )  String propertyName, PropertyEntry propertyValue)
+        throws ArchivaRestServiceException;
+
+
     @Path("config/ldap")
     @GET
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({ APPLICATION_JSON })
     @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     @Operation( summary = "Returns the LDAP configuration that is currently active.",
         security = {
@@ -129,10 +213,30 @@ public interface SecurityConfigurationService
     )
     LdapConfiguration getLdapConfiguration( ) throws ArchivaRestServiceException;
 
+    @Path("config/ldap")
+    @PUT
+    @Consumes({ APPLICATION_JSON })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    @Operation( summary = "Updates the LDAP configuration that is currently active.",
+        security = {
+            @SecurityRequirement(
+                name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
+            )
+        },
+        requestBody = @RequestBody(required = true, description = "The LDAP configuration"),
+        responses = {
+            @ApiResponse( responseCode = "200",
+                description = "If the configuration was updated"
+            ),
+            @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the information",
+                content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) )
+        }
+    )
+    Response updateLdapConfiguration( LdapConfiguration configuration ) throws ArchivaRestServiceException;
 
     @Path("config/cache")
     @GET
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({ APPLICATION_JSON })
     @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     @Operation( summary = "Returns the cache configuration that is currently active.",
         security = {
@@ -150,9 +254,31 @@ public interface SecurityConfigurationService
     )
     CacheConfiguration getCacheConfiguration( ) throws ArchivaRestServiceException;
 
+    @Path("config/cache")
+    @PUT
+    @Consumes({ APPLICATION_JSON })
+    @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
+    @Operation( summary = "Updates the LDAP configuration that is currently active.",
+        security = {
+            @SecurityRequirement(
+                name = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION
+            )
+        },
+        requestBody = @RequestBody(required = true, description = "The LDAP configuration"),
+        responses = {
+            @ApiResponse( responseCode = "200",
+                description = "If the configuration was updated"
+            ),
+            @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the information",
+                content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) )
+        }
+    )
+    Response updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException;
+
+
     @Path("user_managers")
     @GET
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({ APPLICATION_JSON })
     @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     @Operation( summary = "Returns the available user manager implementations.",
         security = {
@@ -173,7 +299,7 @@ public interface SecurityConfigurationService
 
     @Path("rbac_managers")
     @GET
-    @Produces({ MediaType.APPLICATION_JSON })
+    @Produces({ APPLICATION_JSON })
     @RedbackAuthorization(permissions = ArchivaRoleConstants.OPERATION_MANAGE_CONFIGURATION)
     @Operation( summary = "Returns the available RBAC manager implementations.",
         security = {
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java
index b9b504c..be76f31 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/DefaultSecurityConfigurationService.java
@@ -19,11 +19,18 @@ package org.apache.archiva.rest.services.v2;/*
 import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.RedbackRuntimeConfiguration;
 import org.apache.archiva.admin.model.runtime.RedbackRuntimeConfigurationAdmin;
+import org.apache.archiva.components.cache.Cache;
 import org.apache.archiva.components.rest.model.PagedResult;
 import org.apache.archiva.components.rest.model.PropertyEntry;
 import org.apache.archiva.components.rest.util.PagingHelper;
 import org.apache.archiva.components.rest.util.QueryHelper;
+import org.apache.archiva.redback.authentication.Authenticator;
+import org.apache.archiva.redback.common.ldap.connection.LdapConnectionFactory;
+import org.apache.archiva.redback.common.ldap.user.LdapUserMapper;
+import org.apache.archiva.redback.policy.CookieSettings;
+import org.apache.archiva.redback.policy.PasswordRule;
 import org.apache.archiva.redback.rbac.RBACManager;
+import org.apache.archiva.redback.role.RoleManager;
 import org.apache.archiva.redback.users.UserManager;
 import org.apache.archiva.rest.api.model.UserManagerImplementationInformation;
 import org.apache.archiva.rest.api.model.v2.BeanInformation;
@@ -33,6 +40,8 @@ import org.apache.archiva.rest.api.model.v2.SecurityConfiguration;
 import org.apache.archiva.rest.api.services.v2.ArchivaRestServiceException;
 import org.apache.archiva.rest.api.services.v2.ErrorMessage;
 import org.apache.archiva.rest.api.services.v2.SecurityConfigurationService;
+import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.collections4.ListUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -41,8 +50,11 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
+import javax.inject.Named;
 import javax.management.Query;
+import javax.ws.rs.core.Response;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
@@ -81,6 +93,29 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
     @Inject
     private ApplicationContext applicationContext;
 
+    @Inject
+    @Named(value = "userManager#default")
+    private UserManager userManager;
+
+    @Inject
+    @Named(value = "rbacManager#default")
+    private RBACManager rbacManager;
+
+    @Inject
+    private RoleManager roleManager;
+
+    @Inject
+    @Named(value = "ldapConnectionFactory#configurable")
+    private LdapConnectionFactory ldapConnectionFactory;
+
+    @Inject
+    private LdapUserMapper ldapUserMapper;
+
+    @Inject
+    @Named(value = "cache#users")
+    private Cache usersCache;
+
+
     @PostConstruct
     void init() {
         bundle = ResourceBundle.getBundle( "org.apache.archiva.rest.RestBundle" );
@@ -103,6 +138,135 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
             throw new ArchivaRestServiceException( ErrorMessage.of( REPOSITORY_ADMIN_ERROR ) );
         }
     }
+    private void updateConfig(SecurityConfiguration newConfig, RedbackRuntimeConfiguration rbConfig) {
+        rbConfig.setUserManagerImpls( newConfig.getActiveUserManagers() );
+        rbConfig.setRbacManagerImpls( newConfig.getActiveRbacManagers() );
+        rbConfig.setUseUsersCache( newConfig.isUserCacheEnabled() );
+        Map<String, String> props = rbConfig.getConfigurationProperties( );
+        for ( Map.Entry<String,String> newProp : newConfig.getProperties().entrySet() ) {
+            props.put( newProp.getKey( ), newProp.getValue( ) );
+        }
+    }
+
+    private void updateConfig(LdapConfiguration newConfig, RedbackRuntimeConfiguration rbConfig) {
+        org.apache.archiva.admin.model.beans.LdapConfiguration ldapConfig = rbConfig.getLdapConfiguration( );
+        ldapConfig.setBaseDn( newConfig.getBaseDn( ) );
+        ldapConfig.setAuthenticationMethod( newConfig.getAuthenticationMethod() );
+        ldapConfig.setBindAuthenticatorEnabled( newConfig.isBindAuthenticatorEnabled( ) );
+        ldapConfig.setBindDn( newConfig.getBindDn() );
+        ldapConfig.setSsl( newConfig.isSslEnabled( ) );
+        ldapConfig.setBaseGroupsDn( newConfig.getGroupsBaseDn() );
+        ldapConfig.setHostName( newConfig.getHostName() );
+        ldapConfig.setPort( newConfig.getPort() );
+        ldapConfig.setPassword( newConfig.getBindPassword() );
+        ldapConfig.setUseRoleNameAsGroup( newConfig.isUseRoleNameAsGroup() );
+        ldapConfig.setWritable( newConfig.isWritable( ) );
+
+        Map<String, String> props = ldapConfig.getExtraProperties( );
+        for ( Map.Entry<String,String> newProp : newConfig.getProperties().entrySet() ) {
+            props.put( newProp.getKey( ), newProp.getValue( ) );
+        }
+    }
+
+    private void updateConfig(CacheConfiguration newConfig, RedbackRuntimeConfiguration rbConfig) {
+        org.apache.archiva.admin.model.beans.CacheConfiguration cacheConfig = rbConfig.getUsersCacheConfiguration( );
+        cacheConfig.setMaxElementsInMemory( newConfig.getMaxEntriesInMemory());
+        cacheConfig.setMaxElementsOnDisk( newConfig.getMaxEntriesOnDisk() );
+        cacheConfig.setTimeToLiveSeconds( newConfig.getTimeToLiveSeconds() );
+        cacheConfig.setTimeToIdleSeconds( newConfig.getTimeToIdleSeconds() );
+    }
+
+    @Override
+    public Response updateConfiguration( SecurityConfiguration newConfiguration ) throws ArchivaRestServiceException
+    {
+        try
+        {
+            RedbackRuntimeConfiguration conf = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration( );
+            boolean userManagerChanged = !CollectionUtils.isEqualCollection( newConfiguration.getActiveUserManagers( ), conf.getUserManagerImpls() );
+            boolean rbacManagerChanged = !CollectionUtils.isEqualCollection( newConfiguration.getActiveRbacManagers( ), conf.getRbacManagerImpls( ) );
+
+            boolean ldapConfigured = false;
+            for (String um : newConfiguration.getActiveUserManagers()) {
+                if (um.contains("ldap")) {
+                    ldapConfigured=true;
+                }
+            }
+            if (!ldapConfigured) {
+                for (String rbm : newConfiguration.getActiveRbacManagers()) {
+                    if (rbm.contains("ldap")) {
+                        ldapConfigured = true;
+                    }
+                }
+            }
+
+            updateConfig( newConfiguration, conf);
+            redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( conf );
+
+            if ( userManagerChanged )
+            {
+                log.info( "user managerImpls changed to {} so reload it",
+                    newConfiguration.getActiveUserManagers() );
+                userManager.initialize();
+            }
+
+            if ( rbacManagerChanged )
+            {
+                log.info( "rbac manager changed to {} so reload it",
+                    newConfiguration.getActiveRbacManagers() );
+                rbacManager.initialize();
+                roleManager.initialize();
+            }
+
+            if (ldapConfigured) {
+                try {
+                    ldapConnectionFactory.initialize();
+                } catch (Exception e) {
+                    log.error( "Could not initialize LDAP connection factory: {}", e.getMessage( ) );
+                    throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.LDAP_CF_INIT_FAILED, e.getMessage() ) );
+                }
+            }
+            Collection<PasswordRule> passwordRules = applicationContext.getBeansOfType( PasswordRule.class ).values();
+
+            for ( PasswordRule passwordRule : passwordRules )
+            {
+                passwordRule.initialize();
+            }
+
+            Collection<CookieSettings> cookieSettingsList =
+                applicationContext.getBeansOfType( CookieSettings.class ).values();
+
+            for ( CookieSettings cookieSettings : cookieSettingsList )
+            {
+                cookieSettings.initialize();
+            }
+
+            Collection<Authenticator> authenticators =
+                applicationContext.getBeansOfType( Authenticator.class ).values();
+
+            for ( Authenticator authenticator : authenticators )
+            {
+                try {
+                    log.debug("Initializing authenticatior "+authenticator.getId());
+                    authenticator.initialize();
+                } catch (Exception e) {
+                    log.error("Initialization of authenticator failed "+authenticator.getId(),e);
+                }
+            }
+
+            if (ldapConfigured) {
+                try {
+                    ldapUserMapper.initialize();
+                } catch (Exception e) {
+                    throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.LDAP_USER_MAPPER_INIT_FAILED, e.getMessage( ) ) );
+                }
+            }
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( ErrorMessage.of( REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
+        }
+        return Response.ok( ).build();
+    }
 
     @Override
     public PagedResult<PropertyEntry> getConfigurationProperties( String searchTerm, Integer offset, Integer limit, List<String> orderBy, String order ) throws ArchivaRestServiceException
@@ -134,6 +298,48 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
     }
 
     @Override
+    public PropertyEntry getConfigurationProperty( String propertyName ) throws ArchivaRestServiceException
+    {
+        try
+        {
+            RedbackRuntimeConfiguration conf = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration( );
+            if (conf.getConfigurationProperties().containsKey( propertyName )) {
+                String value = conf.getConfigurationProperties( ).get( propertyName );
+                return new PropertyEntry( propertyName, value );
+            } else {
+                throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.PROPERTY_NOT_FOUND ), 404 );
+            }
+
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( ErrorMessage.of( REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
+        }
+
+    }
+
+    @Override
+    public Response updateConfigurationProperty( String propertyName, PropertyEntry propertyValue ) throws ArchivaRestServiceException
+    {
+        try
+        {
+            RedbackRuntimeConfiguration conf = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration( );
+            if (conf.getConfigurationProperties().containsKey( propertyName )) {
+                conf.getConfigurationProperties( ).put( propertyName, propertyValue.getValue( ) );
+                redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( conf );
+                return Response.ok( ).build( );
+            } else {
+                throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.PROPERTY_NOT_FOUND ), 404 );
+            }
+
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( ErrorMessage.of( REPOSITORY_ADMIN_ERROR, e.getMessage( ) ) );
+        }
+    }
+
+    @Override
     public LdapConfiguration getLdapConfiguration( ) throws ArchivaRestServiceException
     {
         try
@@ -153,6 +359,29 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
     }
 
     @Override
+    public Response updateLdapConfiguration( LdapConfiguration configuration ) throws ArchivaRestServiceException
+    {
+        try
+        {
+            RedbackRuntimeConfiguration redbackRuntimeConfiguration =
+                redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration( );
+
+            log.debug( "getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration );
+
+            updateConfig( configuration, redbackRuntimeConfiguration );
+
+            redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
+
+            return Response.ok( ).build( );
+
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( ErrorMessage.of( REPOSITORY_ADMIN_ERROR ) );
+        }
+    }
+
+    @Override
     public CacheConfiguration getCacheConfiguration( ) throws ArchivaRestServiceException
     {
         try
@@ -172,6 +401,25 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio
     }
 
     @Override
+    public Response updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException
+    {
+        try
+        {
+            RedbackRuntimeConfiguration redbackRuntimeConfiguration =
+                redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration( );
+
+            log.debug( "getRedbackRuntimeConfiguration -> {}", redbackRuntimeConfiguration );
+            updateConfig( cacheConfiguration, redbackRuntimeConfiguration );
+            redbackRuntimeConfigurationAdmin.updateRedbackRuntimeConfiguration( redbackRuntimeConfiguration );
+            return Response.ok( ).build( );
+        }
+        catch ( RepositoryAdminException e )
+        {
+            throw new ArchivaRestServiceException( ErrorMessage.of( REPOSITORY_ADMIN_ERROR ) );
+        }
+    }
+
+    @Override
     public List<BeanInformation> getAvailableUserManagers( ) throws ArchivaRestServiceException
     {
         Map<String, UserManager> beans = applicationContext.getBeansOfType( UserManager.class );
diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java
index 85e9c5c..fae6bc2 100644
--- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java
+++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/v2/ErrorKeys.java
@@ -21,6 +21,10 @@ package org.apache.archiva.rest.services.v2;/*
  */
 public interface ErrorKeys
 {
-    public static final String REPOSITORY_ADMIN_ERROR = "a.repositoryadmin.error";
+    String REPOSITORY_ADMIN_ERROR = "archiva.repositoryadmin.error";
+    String LDAP_CF_INIT_FAILED = "archiva.ldap.cf.init.failed";
+    String LDAP_USER_MAPPER_INIT_FAILED = "archiva.ldap.usermapper.init.failed";
+
+    String PROPERTY_NOT_FOUND = "archiva.property.not.found";
 
 }


[archiva] 01/03: Upgrading dependency check and suppress jquery upload

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit ee45f7b29f63292c88f891a15569c9c51ac0f9cb
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Mon Jan 4 15:20:36 2021 +0100

    Upgrading dependency check and suppress jquery upload
---
 archiva-modules/archiva-web/archiva-webapp/pom.xml               | 2 +-
 .../src/main/resources/META-INF/owasp/cve-suppressions.xml       | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/archiva-modules/archiva-web/archiva-webapp/pom.xml b/archiva-modules/archiva-web/archiva-webapp/pom.xml
index 1a73bb4..6e869f7 100644
--- a/archiva-modules/archiva-web/archiva-webapp/pom.xml
+++ b/archiva-modules/archiva-web/archiva-webapp/pom.xml
@@ -935,7 +935,7 @@
       <plugin>
         <groupId>org.owasp</groupId>
         <artifactId>dependency-check-maven</artifactId>
-        <version>5.3.2</version>
+        <version>6.0.4</version>
         <configuration>
           <skipProvidedScope>true</skipProvidedScope>
           <failBuildOnCVSS>8</failBuildOnCVSS>
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/owasp/cve-suppressions.xml b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/owasp/cve-suppressions.xml
index 420e6a5..2a3f08f 100644
--- a/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/owasp/cve-suppressions.xml
+++ b/archiva-modules/archiva-web/archiva-webapp/src/main/resources/META-INF/owasp/cve-suppressions.xml
@@ -64,4 +64,13 @@
     <vulnerabilityName>CVE-2019-20444</vulnerabilityName>
   </suppress>
 
+
+  <suppress>
+    <notes><![CDATA[
+   file name: jquery-file-upload-9.10.1.jar is part of deprecated Web UI.
+   ]]></notes>
+    <packageUrl regex="true">^pkg:maven/org\.webjars/jquery\-file\-upload@.*$</packageUrl>
+    <cpe>cpe:/a:jquery_file_upload_project:jquery_file_upload</cpe>
+  </suppress>
+
 </suppressions>


[archiva] 02/03: Adding check-user script

Posted by ma...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

martin_s pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/archiva.git

commit 23f3df0ca96feb63a0bf6c3e17ed65acef20b461
Author: Martin Stockhammer <ma...@apache.org>
AuthorDate: Mon Jan 4 15:22:27 2021 +0100

    Adding check-user script
---
 .../src/test/resources/check-user.sh               | 43 ++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/check-user.sh b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/check-user.sh
new file mode 100755
index 0000000..b1b8de1
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/check-user.sh
@@ -0,0 +1,43 @@
+#!/bin/bash
+# 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.
+#
+
+# Just a simple script that checks, if a user exists by using the REST Api
+
+BASE_URL="http://localhost:8080/archiva"
+USER_NAME="admin"
+PASSWD="admin456"
+
+CHECK_USER=$1
+
+
+#Authenticate
+TOKEN=$(curl -s -X POST "${BASE_URL}/api/v2/redback/auth/authenticate" -H  "accept: application/json" -H  "Content-Type: application/json" \
+ -d "{\"grant_type\":\"authorization_code\",\"client_id\":\"test-bash\",\"client_secret\":\"string\",\"code\":\"string\",\"scope\":\"string\",\"state\":\"string\",\"user_id\":\"${USER_NAME}\",\
+ \"password\":\"${PASSWD}\",\"redirect_uri\":\"string\"}"|sed -n -e '/access_token/s/.*"access_token":"\([^"]\+\)".*/\1/gp')
+if [ "${TOKEN}" == "" ]; then
+    echo "Authentication failed!"
+    exit 1
+fi
+
+echo curl -I -w ' - %{http_code}' "${BASE_URL}/api/v2/redback/users/${CHECK_USER}" -H  "accept: application/json" \
+   -H  "Authorization: Bearer ${TOKEN}" \
+   -H  "Content-Type: application/json"
+
+curl -I -w ' - %{http_code}' "${BASE_URL}/api/v2/redback/users/${CHECK_USER}" -H  "accept: application/json" \
+   -H  "Authorization: Bearer ${TOKEN}" \
+   -H  "Content-Type: application/json"