@ExtendWith({ RepositoryManagementTestExecutionListener.class, ArtifactManagementTestExecutionListener.class }) @Test public void addUserTest(@NpmRepository(repositoryId = REPOSITORY_RELEASES) Repository repository) { String url = getContextBaseUrl() + "/storages/{storageId}/{repositoryId}/" + NpmLayoutProvider.NPM_USER_PATH + "{username}"; String basicAuth = "Basic YWRtaW46cGFzc3dvcmQ="; final String storageId = repository.getStorage().getId(); final String repositoryId = repository.getId(); NpmUser strongboxUser1 = new NpmUser("admin", "password"); NpmUser strongboxUser2 = new NpmUser("deployer", "password"); NpmUser nonStrongboxUser = new NpmUser("notARealUser", "notARealPassword"); mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE) .body(strongboxUser1) .when() .put(url, storageId, repositoryId, strongboxUser1.getName()) .peek() .then() .statusCode(HttpStatus.CREATED.value()); mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE) .body(strongboxUser2) .when() .put(url, storageId, repositoryId, strongboxUser2.getName()) .peek() .then() .statusCode(HttpStatus.CREATED.value()); mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE) .body(strongboxUser1) .when() .put(url, storageId, repositoryId, nonStrongboxUser.getName()) .peek() .then() .statusCode(HttpStatus.UNAUTHORIZED.value()); mockMvc.header(HttpHeaders.AUTHORIZATION, basicAuth) .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(nonStrongboxUser) .when() .put(url, storageId, repositoryId, nonStrongboxUser.getName()) .then() .statusCode(HttpStatus.UNAUTHORIZED.value()); mockMvc.header(HttpHeaders.AUTHORIZATION, basicAuth) .header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE) .contentType(MediaType.APPLICATION_JSON_VALUE) .body(strongboxUser1) .when() .put(url, storageId, repositoryId, strongboxUser1.getName()) .then() .statusCode(HttpStatus.CREATED.value()); mockMvc.contentType(MediaType.APPLICATION_JSON_VALUE) .body(nonStrongboxUser) .when() .put(url, storageId, repositoryId, nonStrongboxUser.getName()) .peek() .then() .statusCode(HttpStatus.UNAUTHORIZED.value()); }
@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) { if (authentication == null || !authentication.isAuthenticated()) { throw new InsufficientAuthenticationException("unauthorized"); } if (!(authentication instanceof UsernamePasswordAuthenticationToken)) { return toResponseEntityError("Unsupported authentication class " + authentication.getClass().getName()); } Object principal = authentication.getPrincipal(); if (!(principal instanceof SpringSecurityUser)) { return toResponseEntityError( "Unsupported authentication principal " + Optional.ofNullable(principal).orElse(null)); } return ResponseEntity .status(HttpStatus.CREATED) .body("{\"ok\":\"user '" + authentication.getName() + "' created\"}"); }
NpmArtifactController extends BaseArtifactController { @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) { if (authentication == null || !authentication.isAuthenticated()) { throw new InsufficientAuthenticationException("unauthorized"); } if (!(authentication instanceof UsernamePasswordAuthenticationToken)) { return toResponseEntityError("Unsupported authentication class " + authentication.getClass().getName()); } Object principal = authentication.getPrincipal(); if (!(principal instanceof SpringSecurityUser)) { return toResponseEntityError( "Unsupported authentication principal " + Optional.ofNullable(principal).orElse(null)); } return ResponseEntity .status(HttpStatus.CREATED) .body("{\"ok\":\"user '" + authentication.getName() + "' created\"}"); } }
NpmArtifactController extends BaseArtifactController { @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) { if (authentication == null || !authentication.isAuthenticated()) { throw new InsufficientAuthenticationException("unauthorized"); } if (!(authentication instanceof UsernamePasswordAuthenticationToken)) { return toResponseEntityError("Unsupported authentication class " + authentication.getClass().getName()); } Object principal = authentication.getPrincipal(); if (!(principal instanceof SpringSecurityUser)) { return toResponseEntityError( "Unsupported authentication principal " + Optional.ofNullable(principal).orElse(null)); } return ResponseEntity .status(HttpStatus.CREATED) .body("{\"ok\":\"user '" + authentication.getName() + "' created\"}"); }  }
NpmArtifactController extends BaseArtifactController { @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) { if (authentication == null || !authentication.isAuthenticated()) { throw new InsufficientAuthenticationException("unauthorized"); } if (!(authentication instanceof UsernamePasswordAuthenticationToken)) { return toResponseEntityError("Unsupported authentication class " + authentication.getClass().getName()); } Object principal = authentication.getPrincipal(); if (!(principal instanceof SpringSecurityUser)) { return toResponseEntityError( "Unsupported authentication principal " + Optional.ofNullable(principal).orElse(null)); } return ResponseEntity .status(HttpStatus.CREATED) .body("{\"ok\":\"user '" + authentication.getName() + "' created\"}"); }  @GetMapping(path = "{storageId}/{repositoryId}/-/v1/search") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void search(@RepositoryMapping Repository repository,
                       @RequestParam(name = "text") String text,
                       @RequestParam(name = "size", defaultValue = "20") Integer size,
                       HttpServletResponse response); @GetMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName:[^-].+}/{packageVersion}") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void viewPackageWithScope(@RepositoryMapping Repository repository,
                                     @PathVariable(name = "packageScope") String packageScope,
                                     @PathVariable(name = "packageName") String packageName,
                                     @PathVariable(name = "packageVersion") String packageVersion,
                                     HttpServletResponse response); @GetMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void viewPackageFeedWithScope(@RepositoryMapping Repository repository,
                                         @PathVariable(name = "packageScope") String packageScope,
                                         @PathVariable(name = "packageName") String packageName,
                                         HttpServletResponse response); @GetMapping(path = "{storageId}/{repositoryId}/{packageName}") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void viewPackageFeed(@RepositoryMapping Repository repository,
                                @PathVariable(name = "packageName") String packageName,
                                HttpServletResponse response); @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}/-/{packageNameWithVersion}.{packageExtension}", method = { RequestMethod.GET, RequestMethod.HEAD }) void downloadPackageWithScope(@RepositoryMapping Repository repository,
                                         @PathVariable(name = "packageScope") String packageScope,
                                         @PathVariable(name = "packageName") String packageName,
                                         @PathVariable(name = "packageNameWithVersion") String packageNameWithVersion,
                                         @PathVariable(name = "packageExtension") String packageExtension,
                                         @RequestHeader HttpHeaders httpHeaders,
                                         HttpServletRequest request,
                                         HttpServletResponse response); @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "{storageId}/{repositoryId}/{packageName}/-/{packageNameWithVersion}.{packageExtension}", method = { RequestMethod.GET, RequestMethod.HEAD }) void downloadPackage(@RepositoryMapping Repository repository,
                                @PathVariable(name = "packageName") String packageName,
                                @PathVariable(name = "packageNameWithVersion") String packageNameWithVersion,
                                @PathVariable(name = "packageExtension") String packageExtension,
                                @RequestHeader HttpHeaders httpHeaders,
                                HttpServletRequest request,
                                HttpServletResponse response); @PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')") @PutMapping(path = "{storageId}/{repositoryId}/{name:.+}", consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity publish(@RepositoryMapping Repository repository,
                                  @PathVariable(name = "name") String name,
                                  HttpServletRequest request); @PreAuthorize("hasAuthority('UI_LOGIN')") @PutMapping(path = "{storageId}/{repositoryId}/-/user/org.couchdb.user:{username}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity addUser(Authentication authentication); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishPackageWithScope(@RepositoryMapping Repository repository,
                                                    @PathVariable(name = "packageScope") String packageScope,
                                                    @PathVariable(name = "packageName") String packageName,
                                                    @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{r1}/{r2}/{r3}/{packageScope}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersionWithScope(@RepositoryMapping Repository repository,
                                                    @PathVariable(name = "packageScope") String packageScope,
                                                    @PathVariable(name = "packageName") String packageName,
                                                    @PathVariable(name = "tarball") String tarball,
                                                    @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersionWithScopeV5(@RepositoryMapping Repository repository,
                                                      @PathVariable(name = "packageScope") String packageScope,
                                                      @PathVariable(name = "packageName") String packageName,
                                                      @PathVariable(name = "tarball") String tarball,
                                                      @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageName}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishPackage(@RepositoryMapping Repository repository,
                                           @PathVariable(name = "packageName") String packageName,
                                           @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{r1}/{r2}/{r3}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersion(@RepositoryMapping Repository repository,
                                           @PathVariable(name = "packageName") String packageName,
                                           @PathVariable(name = "tarball") String tarball,
                                           @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersionV5(@RepositoryMapping Repository repository,
                                             @PathVariable(name = "packageName") String packageName,
                                             @PathVariable(name = "tarball") String tarball,
                                             @PathVariable(name = "rev") String rev); }
NpmArtifactController extends BaseArtifactController { @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) { if (authentication == null || !authentication.isAuthenticated()) { throw new InsufficientAuthenticationException("unauthorized"); } if (!(authentication instanceof UsernamePasswordAuthenticationToken)) { return toResponseEntityError("Unsupported authentication class " + authentication.getClass().getName()); } Object principal = authentication.getPrincipal(); if (!(principal instanceof SpringSecurityUser)) { return toResponseEntityError( "Unsupported authentication principal " + Optional.ofNullable(principal).orElse(null)); } return ResponseEntity .status(HttpStatus.CREATED) .body("{\"ok\":\"user '" + authentication.getName() + "' created\"}"); }  @GetMapping(path = "{storageId}/{repositoryId}/-/v1/search") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void search(@RepositoryMapping Repository repository,
                       @RequestParam(name = "text") String text,
                       @RequestParam(name = "size", defaultValue = "20") Integer size,
                       HttpServletResponse response); @GetMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName:[^-].+}/{packageVersion}") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void viewPackageWithScope(@RepositoryMapping Repository repository,
                                     @PathVariable(name = "packageScope") String packageScope,
                                     @PathVariable(name = "packageName") String packageName,
                                     @PathVariable(name = "packageVersion") String packageVersion,
                                     HttpServletResponse response); @GetMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void viewPackageFeedWithScope(@RepositoryMapping Repository repository,
                                         @PathVariable(name = "packageScope") String packageScope,
                                         @PathVariable(name = "packageName") String packageName,
                                         HttpServletResponse response); @GetMapping(path = "{storageId}/{repositoryId}/{packageName}") @PreAuthorize("hasAuthority('ARTIFACTS_VIEW')") void viewPackageFeed(@RepositoryMapping Repository repository,
                                @PathVariable(name = "packageName") String packageName,
                                HttpServletResponse response); @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}/-/{packageNameWithVersion}.{packageExtension}", method = { RequestMethod.GET, RequestMethod.HEAD }) void downloadPackageWithScope(@RepositoryMapping Repository repository,
                                         @PathVariable(name = "packageScope") String packageScope,
                                         @PathVariable(name = "packageName") String packageName,
                                         @PathVariable(name = "packageNameWithVersion") String packageNameWithVersion,
                                         @PathVariable(name = "packageExtension") String packageExtension,
                                         @RequestHeader HttpHeaders httpHeaders,
                                         HttpServletRequest request,
                                         HttpServletResponse response); @PreAuthorize("hasAuthority('ARTIFACTS_RESOLVE')") @RequestMapping(path = "{storageId}/{repositoryId}/{packageName}/-/{packageNameWithVersion}.{packageExtension}", method = { RequestMethod.GET, RequestMethod.HEAD }) void downloadPackage(@RepositoryMapping Repository repository,
                                @PathVariable(name = "packageName") String packageName,
                                @PathVariable(name = "packageNameWithVersion") String packageNameWithVersion,
                                @PathVariable(name = "packageExtension") String packageExtension,
                                @RequestHeader HttpHeaders httpHeaders,
                                HttpServletRequest request,
                                HttpServletResponse response); @PreAuthorize("hasAuthority('ARTIFACTS_DEPLOY')") @PutMapping(path = "{storageId}/{repositoryId}/{name:.+}", consumes = MediaType.APPLICATION_JSON_VALUE) ResponseEntity publish(@RepositoryMapping Repository repository,
                                  @PathVariable(name = "name") String name,
                                  HttpServletRequest request); @PreAuthorize("hasAuthority('UI_LOGIN')") @PutMapping(path = "{storageId}/{repositoryId}/-/user/org.couchdb.user:{username}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE) ResponseEntity addUser(Authentication authentication); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishPackageWithScope(@RepositoryMapping Repository repository,
                                                    @PathVariable(name = "packageScope") String packageScope,
                                                    @PathVariable(name = "packageName") String packageName,
                                                    @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{r1}/{r2}/{r3}/{packageScope}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersionWithScope(@RepositoryMapping Repository repository,
                                                    @PathVariable(name = "packageScope") String packageScope,
                                                    @PathVariable(name = "packageName") String packageName,
                                                    @PathVariable(name = "tarball") String tarball,
                                                    @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageScope}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersionWithScopeV5(@RepositoryMapping Repository repository,
                                                      @PathVariable(name = "packageScope") String packageScope,
                                                      @PathVariable(name = "packageName") String packageName,
                                                      @PathVariable(name = "tarball") String tarball,
                                                      @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageName}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishPackage(@RepositoryMapping Repository repository,
                                           @PathVariable(name = "packageName") String packageName,
                                           @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{r1}/{r2}/{r3}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersion(@RepositoryMapping Repository repository,
                                           @PathVariable(name = "packageName") String packageName,
                                           @PathVariable(name = "tarball") String tarball,
                                           @PathVariable(name = "rev") String rev); @DeleteMapping(path = "{storageId}/{repositoryId}/{packageName}/-/{tarball}/-rev/{rev}") @PreAuthorize("hasAuthority('ARTIFACTS_DELETE')") ResponseEntity unpublishVersionV5(@RepositoryMapping Repository repository,
                                             @PathVariable(name = "packageName") String packageName,
                                             @PathVariable(name = "tarball") String tarball,
                                             @PathVariable(name = "rev") String rev);  }