Add npm adduser endpoint
@@ -68,6 +68,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.security.core.Authentication;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@@ -78,6 +79,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
+
/**
* This Controller used to handle npm requests.
*
@@ -96,7 +98,6 @@ public class NpmArtifactController
private static final String FIELD_NAME_VERSION = "versions";
-
@Inject
@NpmObjectMapper
private ObjectMapper npmJacksonMapper;
@@ -394,6 +395,17 @@ public class NpmArtifactController
return ResponseEntity.ok("");
}
+ @PreAuthorize("hasAuthority('UI_LOGIN')")
+ @PutMapping(path = "{storageId}/{repositoryId}/-/user/org.couchdb.user:{username}",
+ consumes = MediaType.APPLICATION_JSON_VALUE,
+ produces = MediaType.APPLICATION_JSON_VALUE)
+ public ResponseEntity addUser(Authentication authentication)
+ {
+ return ResponseEntity
+ .status(HttpStatus.CREATED)
+ .body("{\"ok\":\"user '" + authentication.getName() + "' created\"}");
+ }
+
private void storeNpmPackage(Repository repository,
NpmArtifactCoordinates coordinates,
PackageVersion packageDef,
