diff options
Diffstat (limited to 'archiva-modules/archiva-web/archiva-rest')
4 files changed, 200 insertions, 2 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 e70f465af..6c9c83631 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 @@ -98,6 +98,8 @@ public interface SecurityConfigurationService @ApiResponse( responseCode = "200", description = "If the configuration was updated" ), + @ApiResponse( responseCode = "422", description = "Invalid content data", + content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) ), @ApiResponse( responseCode = "403", description = "Authenticated user is not permitted to update the configuration", content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) ) } @@ -182,6 +184,8 @@ public interface SecurityConfigurationService @ApiResponse( responseCode = "200", description = "If the property value was updated." ), + @ApiResponse( responseCode = "400", description = "The body data is not valid", + content = @Content(mediaType = APPLICATION_JSON, schema = @Schema(implementation = ArchivaRestServiceException.class )) ), @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", 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 be76f3164..d1b4fe187 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 @@ -179,6 +179,9 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio @Override public Response updateConfiguration( SecurityConfiguration newConfiguration ) throws ArchivaRestServiceException { + if (newConfiguration==null) { + throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.MISSING_DATA ), 400 ); + } try { RedbackRuntimeConfiguration conf = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration( ); @@ -321,6 +324,9 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio @Override public Response updateConfigurationProperty( String propertyName, PropertyEntry propertyValue ) throws ArchivaRestServiceException { + if (propertyValue==null) { + throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.MISSING_DATA ), 400 ); + } try { RedbackRuntimeConfiguration conf = redbackRuntimeConfigurationAdmin.getRedbackRuntimeConfiguration( ); @@ -403,6 +409,9 @@ public class DefaultSecurityConfigurationService implements SecurityConfiguratio @Override public Response updateCacheConfiguration( CacheConfiguration cacheConfiguration ) throws ArchivaRestServiceException { + if (cacheConfiguration==null) { + throw new ArchivaRestServiceException( ErrorMessage.of( ErrorKeys.MISSING_DATA ), 400 ); + } try { RedbackRuntimeConfiguration redbackRuntimeConfiguration = 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 fae6bc221..455617e09 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 @@ -27,4 +27,6 @@ public interface ErrorKeys String PROPERTY_NOT_FOUND = "archiva.property.not.found"; + String MISSING_DATA = "archiva.missing.data"; + } diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeSecurityConfigurationServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeSecurityConfigurationServiceTest.java index 610743f5b..02d0dc986 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeSecurityConfigurationServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/v2/NativeSecurityConfigurationServiceTest.java @@ -22,6 +22,8 @@ import io.restassured.response.Response; import org.apache.archiva.components.rest.model.PagedResult; import org.apache.archiva.components.rest.model.PropertyEntry; import org.apache.archiva.rest.api.model.v2.BeanInformation; +import org.apache.archiva.rest.api.model.v2.CacheConfiguration; +import org.apache.archiva.rest.api.model.v2.LdapConfiguration; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.DisplayName; @@ -34,7 +36,10 @@ import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; +import java.util.Arrays; +import java.util.HashMap; import java.util.List; +import java.util.Map; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; @@ -125,6 +130,54 @@ public class NativeSecurityConfigurationServiceTest extends AbstractNativeRestSe assertEquals( 13, response.getBody( ).jsonPath( ).getMap( "properties" ).size( ) ); } + + @Test + void testUpdateLdapConfiguration() { + String token = getAdminToken( ); + try + { + Map<String, Object> jsonMap = new HashMap<>( ); + jsonMap.put( "host_name", "localhost" ); + jsonMap.put( "port", 389 ); + jsonMap.put( "ssl_enabled", false ); + jsonMap.put( "writable", true ); + jsonMap.put( "base_dn", "dc=apache,dc=org" ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonMap ) + .put( "config/ldap" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + + response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "config/ldap" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + LdapConfiguration config = response.getBody( ).jsonPath( ).getObject( "", LdapConfiguration.class ); + assertEquals( "localhost", config.getHostName( ) ); + assertEquals( 389, config.getPort( ) ); + assertFalse( config.isSslEnabled( ) ); + assertTrue( config.isWritable( ) ); + assertEquals( "dc=apache,dc=org", config.getBaseDn( ) ); + } finally + { + Map<String, Object> jsonMap = new HashMap<>( ); + jsonMap.put( "host_name", "" ); + jsonMap.put( "port", -1 ); + jsonMap.put( "ssl_enabled", false ); + jsonMap.put( "base_dn", "" ); + jsonMap.put( "writable", false ); + given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonMap ) + .put( "config/ldap" ) + .then( ).statusCode( 200 ); + + } + } + + @Test void testGetCacheConfiguration() { String token = getAdminToken( ); @@ -136,12 +189,57 @@ public class NativeSecurityConfigurationServiceTest extends AbstractNativeRestSe } @Test + void testUpdateCacheConfiguration() { + String token = getAdminToken( ); + + try + { + Map<String, Object> jsonMap = new HashMap<>( ); + jsonMap.put( "time_to_idle_seconds", 1600 ); + jsonMap.put( "time_to_live_seconds", 12000 ); + jsonMap.put( "max_entries_in_memory", 500 ); + jsonMap.put( "max_entries_on_disk", 400 ); + + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonMap ) + .put( "config/cache" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "config/cache" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + CacheConfiguration config = response.getBody( ).jsonPath( ).getObject( "", CacheConfiguration.class ); + assertEquals( 1600, config.getTimeToIdleSeconds( ) ); + assertEquals( 12000, config.getTimeToLiveSeconds( ) ); + assertEquals( 500, config.getMaxEntriesInMemory( ) ); + assertEquals( 400, config.getMaxEntriesOnDisk( ) ); + } finally + { + Map<String, Object> jsonMap = new HashMap<>( ); + jsonMap.put( "time_to_idle_seconds", 1800 ); + jsonMap.put( "time_to_live_seconds", 14400 ); + jsonMap.put( "max_entries_in_memory", 1000 ); + jsonMap.put( "max_entries_on_disk", 0 ); + + given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonMap ) + .put( "config/cache" ) + .then( ).statusCode( 200 ); + + } + } + + + @Test void testGetUserManagers() { String token = getAdminToken( ); Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) .when( ) .get( "user_managers" ) - .prettyPeek() .then( ).statusCode( 200 ).extract( ).response( ); assertNotNull( response ); List<BeanInformation> usrList = response.getBody( ).jsonPath( ).getList( "", BeanInformation.class ); @@ -156,7 +254,6 @@ public class NativeSecurityConfigurationServiceTest extends AbstractNativeRestSe Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) .when( ) .get( "rbac_managers" ) - .prettyPeek() .then( ).statusCode( 200 ).extract( ).response( ); assertNotNull( response ); List<BeanInformation> rbacList = response.getBody( ).jsonPath( ).getList( "", BeanInformation.class ); @@ -165,4 +262,90 @@ public class NativeSecurityConfigurationServiceTest extends AbstractNativeRestSe assertTrue( rbacList.stream( ).anyMatch( bi -> "LDAP RBAC Manager".equals( bi.getDisplayName( ) ) ) ); } + @Test + void testUpdateConfiguration() { + String token = getAdminToken( ); + try + { + Map<String, Object> jsonAsMap = new HashMap<>( ); + jsonAsMap.put( "active_user_managers", Arrays.asList( "jpa", "ldap" ) ); + jsonAsMap.put( "active_rbac_managers", Arrays.asList( "jpa" ) ); + jsonAsMap.put( "user_cache_enabled", false ); + jsonAsMap.put( "ldap_active", false ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonAsMap ) + .put( "config" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + + response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "config" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + assertEquals( 2, response.getBody( ).jsonPath( ).getList( "active_user_managers" ).size( ) ); + } finally + { + Map<String, Object> jsonAsMap = new HashMap<>( ); + jsonAsMap.put( "active_user_managers", Arrays.asList( "jpa" ) ); + jsonAsMap.put( "active_rbac_managers", Arrays.asList( "jpa" ) ); + jsonAsMap.put( "user_cache_enabled", true ); + jsonAsMap.put( "ldap_active", false ); + given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonAsMap ) + .put( "config" ) + .then( ).statusCode( 200 ); + + } + + } + + @Test + void testGetConfigProperty() { + String token = getAdminToken( ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "config/properties/rest.csrffilter.absentorigin.deny" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + assertEquals( "true", response.getBody( ).jsonPath( ).getString( "value" ) ); + } + + @Test + void testUpdateConfigProperty() { + String token = getAdminToken( ); + + try + { + Map<String, String> jsonMap = new HashMap<>( ); + jsonMap.put( "value", "false" ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonMap ) + .put( "config/properties/rest.csrffilter.absentorigin.deny" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + + + response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .get( "config/properties/rest.csrffilter.absentorigin.deny" ) + .then( ).statusCode( 200 ).extract( ).response( ); + assertNotNull( response ); + assertEquals( "false", response.getBody( ).jsonPath( ).getString( "value" ) ); + } finally + { + Map<String, String> jsonMap = new HashMap<>( ); + jsonMap.put( "value", "true" ); + Response response = given( ).spec( getRequestSpec( token ) ).contentType( JSON ) + .when( ) + .body( jsonMap ) + .put( "config/properties/rest.csrffilter.absentorigin.deny" ) + .then( ).statusCode( 200 ).extract( ).response( ); + } + } + + } |