Java Code Examples for org.springframework.security.access.annotation.Secured

The following examples show how to use org.springframework.security.access.annotation.Secured. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: flair-engine   Source File: UserResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * PUT  /users : Updates an existing User.
 *
 * @param managedUserVM the user to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated user,
 * or with status 400 (Bad Request) if the login or email is already in use,
 * or with status 500 (Internal Server Error) if the user couldn't be updated
 */
@PutMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<UserDTO> updateUser(@Valid @RequestBody ManagedUserVM managedUserVM) {
    log.debug("REST request to update User : {}", managedUserVM);
    Optional<User> existingUser = userRepository.findOneByEmail(managedUserVM.getEmail());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserVM.getId()))) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "emailexists", "Email already in use")).body(null);
    }
    existingUser = userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserVM.getId()))) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "userexists", "Login already in use")).body(null);
    }
    Optional<UserDTO> updatedUser = userService.updateUser(managedUserVM);

    return ResponseUtil.wrapOrNotFound(updatedUser,
        HeaderUtil.createAlert("A user is updated with identifier " + managedUserVM.getLogin(), managedUserVM.getLogin()));
}
 
Example 2
Source Project: cubeai   Source File: UserResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * POST  /users  : Creates a new user.
 * <p>
 * Creates a new user if the login and email are not already used, and sends an
 * mail with an activation link.
 * The user needs to be activated on creation.
 *
 * @param userDTO the user to create
 * @return the ResponseEntity with status 201 (Created) and with body the new user, or with status 400 (Bad Request) if the login or email is already in use
 * @throws URISyntaxException if the Location URI syntax is incorrect
 * @throws BadRequestAlertException 400 (Bad Request) if the login or email is already in use
 */
@PostMapping("/users")
@Timed
@Secured({AuthoritiesConstants.ADMIN})
public ResponseEntity<User> createUser(@Valid @RequestBody UserDTO userDTO) throws URISyntaxException {
    log.debug("REST request to save User : {}", userDTO);

    if (userDTO.getId() != null) {
        throw new BadRequestAlertException("A new user cannot already have an ID", "userManagement", "idexists");
        // Lowercase the user login before comparing with database
    } else if (userRepository.findOneByLogin(userDTO.getLogin().toLowerCase()).isPresent()) {
        throw new LoginAlreadyUsedException();
    } else if (userRepository.findOneByEmailIgnoreCase(userDTO.getEmail()).isPresent()) {
        throw new EmailAlreadyUsedException();
    } else {
        User newUser = userService.createUser(userDTO);
        // mailService.sendCreationEmail(newUser);  // huolongshe: 创建用户不发邮件通知
        return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin()))
            .headers(HeaderUtil.createAlert( "A user is created with identifier " + newUser.getLogin(), newUser.getLogin()))
            .body(newUser);
    }
}
 
Example 3
Source Project: cubeai   Source File: UserResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * PUT /users : Updates an existing User.
 *
 * @param userDTO the user to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated user
 * @throws EmailAlreadyUsedException 400 (Bad Request) if the email is already in use
 * @throws LoginAlreadyUsedException 400 (Bad Request) if the login is already in use
 */
@PutMapping("/users")
@Timed
@Secured({AuthoritiesConstants.ADMIN})
public ResponseEntity<UserDTO> updateUser(@Valid @RequestBody UserDTO userDTO) {
    log.debug("REST request to update User : {}", userDTO);
    Optional<User> existingUser = userRepository.findOneByEmailIgnoreCase(userDTO.getEmail());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) {
        throw new EmailAlreadyUsedException();
    }
    existingUser = userRepository.findOneByLogin(userDTO.getLogin().toLowerCase());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) {
        throw new LoginAlreadyUsedException();
    }
    Optional<UserDTO> updatedUser = userService.updateUser(userDTO);

    return ResponseUtil.wrapOrNotFound(updatedUser,
        HeaderUtil.createAlert("A user is updated with identifier " + userDTO.getLogin(), userDTO.getLogin()));
}
 
Example 4
Source Project: cubeai   Source File: DeploymentResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * PUT  /deployments/subjects : 更新deployment对象中的subject和displayOrder等诸字段
 * @param jsonObject the JSONObject with subjects to be updated
 * @return the ResponseEntity with status 200 (OK) and with body the updated deployment or status 400 (Bad Request)
 */
@PutMapping("/deployments/subjects")
@Timed
@Secured({"ROLE_OPERATOR"})  // subject字段只能由能力开放平台管理员更新
public ResponseEntity<Deployment> updateDeploymentSubjects(@Valid @RequestBody JSONObject jsonObject) {
    log.debug("REST request to update Deployment subjects: {}", jsonObject);

    Deployment deployment = deploymentRepository.findOne(jsonObject.getLong("id"));
    deployment.setSubject1(jsonObject.getString("subject1"));
    deployment.setSubject2(jsonObject.getString("subject2"));
    deployment.setSubject3(jsonObject.getString("subject3"));
    deployment.setDisplayOrder(jsonObject.getLong("displayOrder"));

    deployment.setModifiedDate(Instant.now());
    Deployment result = deploymentRepository.save(deployment);

    return ResponseEntity.ok().body(result);
}
 
Example 5
Source Project: jhipster-online   Source File: JdlResource.java    License: Apache License 2.0 6 votes vote down vote up
@PostMapping("/apply-jdl/{gitProvider}/{organizationName}/{projectName}/{jdlId}")
@Secured(AuthoritiesConstants.USER)
public ResponseEntity applyJdl(@PathVariable String gitProvider, @PathVariable String organizationName,
                               @PathVariable String projectName,
                               @PathVariable String jdlId) {
    boolean isGitHub = gitProvider.toLowerCase().equals("github");
    log.info("Applying JDL `{}` on " + (isGitHub ? "GitHub" : "GitLab") + " project {}/{}", jdlId,
        organizationName, projectName);
    User user = userService.getUser();

    Optional<JdlMetadata> jdlMetadata = this.jdlMetadataService.findOne(jdlId);
    String applyJdlId = this.jdlService.kebabCaseJdlName(jdlMetadata.get()) + "-" +
        System.nanoTime();
    this.logsService.addLog(applyJdlId, "JDL Model is going to be applied to " + organizationName + "/" +
        projectName);

    try {
        this.jdlService.applyJdl(user, organizationName, projectName, jdlMetadata.get(),
            applyJdlId, GitProvider.getGitProviderByValue(gitProvider).orElseThrow(null));
    } catch (Exception e) {
        log.error("Error generating application", e);
        this.logsService.addLog(jdlId, "An error has occurred: " + e.getMessage());
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return new ResponseEntity<>(applyJdlId, HttpStatus.CREATED);
}
 
Example 6
/**
 * GET  /routes : get the active routes.
 *
 * @return the ResponseEntity with status 200 (OK) and with body the list of routes
 */
@GetMapping("/routes")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<List<RouteVM>> activeRoutes() {
    List<Route> routes = routeLocator.getRoutes();
    List<RouteVM> routeVMs = new ArrayList<>();
    routes.forEach(route -> {
        RouteVM routeVM = new RouteVM();
        routeVM.setPath(route.getFullPath());
        routeVM.setServiceId(route.getId());
        routeVM.setServiceInstances(discoveryClient.getInstances(route.getLocation()));
        routeVMs.add(routeVM);
    });
    return new ResponseEntity<>(routeVMs, HttpStatus.OK);
}
 
Example 7
Source Project: TeamDojo   Source File: UserResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * PUT /users : Updates an existing User.
 *
 * @param userDTO the user to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated user
 * @throws EmailAlreadyUsedException 400 (Bad Request) if the email is already in use
 * @throws LoginAlreadyUsedException 400 (Bad Request) if the login is already in use
 */
@PutMapping("/users")
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<UserDTO> updateUser(@Valid @RequestBody UserDTO userDTO) {
    log.debug("REST request to update User : {}", userDTO);
    Optional<User> existingUser = userRepository.findOneByEmailIgnoreCase(userDTO.getEmail());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) {
        throw new EmailAlreadyUsedException();
    }
    existingUser = userRepository.findOneByLogin(userDTO.getLogin().toLowerCase());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) {
        throw new LoginAlreadyUsedException();
    }
    Optional<UserDTO> updatedUser = userService.updateUser(userDTO);

    return ResponseUtil.wrapOrNotFound(updatedUser,
        HeaderUtil.createAlert("userManagement.updated", userDTO.getLogin()));
}
 
Example 8
/**
 * Create tenant.
 *
 * @param orgId                     the org id
 * @param tenantCreateUpdateRequest the tenant create update request
 * @return the identity response
 */
@Secured(ROLE_SUPERADMIN)
public IdentityResponse createTenant(String orgId, TenantCreateUpdateRequest tenantCreateUpdateRequest) {

    Optional<Org> orgOptional = orgRepository.findById(orgId);

    if (!orgOptional.isPresent()) {
        throw new ResourceNotFoundException("Org not found.");
    }

    if (tenantRepository.isTenantExist(orgId, tenantCreateUpdateRequest.getName())) {
        throw new ValidationException("Tenant '" + tenantCreateUpdateRequest.getName() + "' is already exist.");
    }

    String uuid = uuidUtil.getUuid();
    Tenant tenant = new Tenant();
    tenant.setId(uuid);
    tenant.setTenant(tenantCreateUpdateRequest.getName());
    tenant.setOrg(orgOptional.get());
    tenantRepository.saveAndFlush(tenant);
    return new IdentityResponse(uuid);
}
 
Example 9
/**
 * Create User by super user.
 *
 * @param orgId             the org id
 * @param tenantId          the tenant id
 * @param userCreateRequest the user create request
 * @return the user's id
 */
@Secured(ROLE_SUPERADMIN)
public IdentityResponse create(String orgId, String tenantId, UserCreateRequest userCreateRequest) {

    Optional<Org> orgOptional = orgRepository.findById(orgId);
    if (!orgOptional.isPresent()) {
        throw new ValidationException("Org not found.");
    }

    Optional<Tenant> tenantOptional = tenantRepository.findById(tenantId);
    if (!tenantOptional.isPresent()) {
        throw new ValidationException("Tenant not found.");
    }

    return getIdentityResponse(userCreateRequest, orgOptional.get(), tenantOptional.get());
}
 
Example 10
Source Project: e-commerce-microservice   Source File: GatewayResource.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * GET  /routes : get the active routes.
 *
 * @return the ResponseEntity with status 200 (OK) and with body the list of routes
 */
@GetMapping("/routes")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<List<RouteVM>> activeRoutes() {
    List<Route> routes = routeLocator.getRoutes();
    List<RouteVM> routeVMs = new ArrayList<>();
    routes.forEach(route -> {
        RouteVM routeVM = new RouteVM();
        routeVM.setPath(route.getFullPath());
        routeVM.setServiceId(route.getId());
        routeVM.setServiceInstances(discoveryClient.getInstances(route.getLocation()));
        routeVMs.add(routeVM);
    });
    return new ResponseEntity<>(routeVMs, HttpStatus.OK);
}
 
Example 11
/**
 * POST  /users  : Creates a new user.
 * <p>
 * Creates a new user if the login and email are not already used, and sends an
 * mail with an activation link.
 * The user needs to be activated on creation.
 *
 * @param userDTO the user to create
 * @return the ResponseEntity with status 201 (Created) and with body the new user, or with status 400 (Bad Request) if the login or email is already in use
 * @throws URISyntaxException if the Location URI syntax is incorrect
 * @throws BadRequestAlertException 400 (Bad Request) if the login or email is already in use
 */
@PostMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<User> createUser(@Valid @RequestBody UserDTO userDTO) throws URISyntaxException {
    log.debug("REST request to save User : {}", userDTO);

    if (userDTO.getId() != null) {
        throw new BadRequestAlertException("A new user cannot already have an ID", "userManagement", "idexists");
        // Lowercase the user login before comparing with database
    } else if (userRepository.findOneByLogin(userDTO.getLogin().toLowerCase()).isPresent()) {
        throw new LoginAlreadyUsedException();
    } else if (userRepository.findOneByEmailIgnoreCase(userDTO.getEmail()).isPresent()) {
        throw new EmailAlreadyUsedException();
    } else {
        User newUser = userService.createUser(userDTO);
        mailService.sendCreationEmail(newUser);
        return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin()))
            .headers(HeaderUtil.createAlert( "userManagement.created", newUser.getLogin()))
            .body(newUser);
    }
}
 
Example 12
/**
 * PUT /users : Updates an existing User.
 *
 * @param userDTO the user to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated user
 * @throws EmailAlreadyUsedException 400 (Bad Request) if the email is already in use
 * @throws LoginAlreadyUsedException 400 (Bad Request) if the login is already in use
 */
@PutMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<UserDTO> updateUser(@Valid @RequestBody UserDTO userDTO) {
    log.debug("REST request to update User : {}", userDTO);
    Optional<User> existingUser = userRepository.findOneByEmailIgnoreCase(userDTO.getEmail());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) {
        throw new EmailAlreadyUsedException();
    }
    existingUser = userRepository.findOneByLogin(userDTO.getLogin().toLowerCase());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(userDTO.getId()))) {
        throw new LoginAlreadyUsedException();
    }
    Optional<UserDTO> updatedUser = userService.updateUser(userDTO);

    return ResponseUtil.wrapOrNotFound(updatedUser,
        HeaderUtil.createAlert("userManagement.updated", userDTO.getLogin()));
}
 
Example 13
/**
 * PUT  /users : Updates an existing User.
 *
 * @param managedUserVM the user to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated user,
 * or with status 400 (Bad Request) if the login or email is already in use,
 * or with status 500 (Internal Server Error) if the user couldn't be updated
 */
@PutMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<UserDTO> updateUser(@Valid @RequestBody ManagedUserVM managedUserVM) {
    log.debug("REST request to update User : {}", managedUserVM);
    Optional<User> existingUser = userRepository.findOneByEmail(managedUserVM.getEmail());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserVM.getId()))) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "emailexists", "Email already in use")).body(null);
    }
    existingUser = userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase());
    if (existingUser.isPresent() && (!existingUser.get().getId().equals(managedUserVM.getId()))) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "userexists", "Login already in use")).body(null);
    }
    Optional<UserDTO> updatedUser = userService.updateUser(managedUserVM);

    return ResponseUtil.wrapOrNotFound(updatedUser,
        HeaderUtil.createAlert("userManagement.updated", managedUserVM.getLogin()));
}
 
Example 14
Source Project: java-master   Source File: UserController.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 创建用户
 */
@Secured("ROLE_ADMIN")
@PostMapping("/createUser")
@AopLock(lockKeySpEL = "#reqVo.username", errorMsg = "用户名已被占用,请重新输入")
public Result<SysUser> createUser(@Validated @RequestBody CreateUserReqVo reqVo) {
    return new Result<>(userService.createUser(reqVo));
}
 
Example 15
Source Project: jhipster-online   Source File: YoRCResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET  /yo-rcs : get all the yoRCS.
 *
 * @return the ResponseEntity with status 200 (OK) and the list of yoRCS in body
 */
@GetMapping("/yo-rcs")
@Secured(AuthoritiesConstants.ADMIN)
public List<YoRC> getAllYoRCS() {
    log.debug("REST request to get all YoRCS");
    return yoRCService.findAll();
}
 
Example 16
Source Project: flair-engine   Source File: UserResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return a string list of the all of the roles
 */
@GetMapping("/users/authorities")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public List<String> getAuthorities() {
    return userService.getAuthorities();
}
 
Example 17
Source Project: flair-engine   Source File: UserResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * DELETE /users/:login : delete the "login" User.
 *
 * @param login the login of the user to delete
 * @return the ResponseEntity with status 200 (OK)
 */
@DeleteMapping("/users/{login:" + Constants.LOGIN_REGEX + "}")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<Void> deleteUser(@PathVariable String login) {
    log.debug("REST request to delete User: {}", login);
    userService.deleteUser(login);
    return ResponseEntity.ok().headers(HeaderUtil.createAlert( "A user is deleted with identifier " + login, login)).build();
}
 
Example 18
/**
 * {@code GET  /routes} : get the active routes.
 *
 * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the list of routes.
 */
@GetMapping("/routes")
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<List<RouteVM>> activeRoutes() {
    List<Route> routes = routeLocator.getRoutes();
    List<RouteVM> routeVMs = new ArrayList<>();
    routes.forEach(route -> {
        RouteVM routeVM = new RouteVM();
        routeVM.setPath(route.getFullPath());
        routeVM.setServiceId(route.getId());
        routeVM.setServiceInstances(discoveryClient.getInstances(route.getLocation()));
        routeVMs.add(routeVM);
    });
    return ResponseEntity.ok(routeVMs);
}
 
Example 19
Source Project: cubeai   Source File: UserResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET /users : get all users.
 *
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and with body all users
 */
@GetMapping("/users")
@Timed
@Secured({AuthoritiesConstants.ADMIN})
public ResponseEntity<List<UserDTO>> getAllUsers(Pageable pageable) {
    final Page<UserDTO> page = userService.getAllManagedUsers(pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/users");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 20
Source Project: cubeai   Source File: UserResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return a string list of the all of the roles
 */
@GetMapping("/users/authorities")
@Timed
@Secured({AuthoritiesConstants.ADMIN})
public List<String> getAuthorities() {
    return userService.getAuthorities();
}
 
Example 21
Source Project: jhipster-online   Source File: EntityStatsResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET  /entity-stats : get all the entityStats.
 *
 * @return the ResponseEntity with status 200 (OK) and the list of entityStats in body
 */
@GetMapping("/entity-stats")
@Secured(AuthoritiesConstants.ADMIN)
public List<EntityStats> getAllEntityStats() {
    log.debug("REST request to get all EntityStats");
    return entityStatsService.findAll();
}
 
Example 22
Source Project: cubeai   Source File: UserResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return delete a authority
 */
@DeleteMapping("/users/authorities/{authority}")
@Timed
@Secured({AuthoritiesConstants.ADMIN})
public ResponseEntity<Void>  deleteAuthority(@PathVariable String authority) {
    if (userService.deleteAuthority(authority)) {
        return ResponseEntity.ok().build();
    } else {
        return ResponseEntity.badRequest().build();
    }
}
 
Example 23
Source Project: cubeai   Source File: UserResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * DELETE /users/:login : delete the "login" User.
 *
 * @param login the login of the user to delete
 * @return the ResponseEntity with status 200 (OK)
 */
@DeleteMapping("/users/{login:" + Constants.LOGIN_REGEX + "}")
@Timed
@Secured({AuthoritiesConstants.ADMIN})
public ResponseEntity<Void> deleteUser(@PathVariable String login) {
    log.debug("REST request to delete User: {}", login);
    userService.deleteUser(login);
    return ResponseEntity.ok().headers(HeaderUtil.createAlert( "A user is deleted with identifier " + login, login)).build();
}
 
Example 24
Source Project: jhipster-online   Source File: JdlResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Delete a JDL file.
 */
@DeleteMapping("/jdl/{jdlId}")
@Secured(AuthoritiesConstants.USER)
public @ResponseBody
ResponseEntity deleteJdlFile(@PathVariable String jdlId) {
    try {
        this.jdlMetadataService.delete(jdlId);
    } catch (Exception e) {
        log.info("Could not delete the JDL file", e);
        return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
    }
    return new ResponseEntity<>(HttpStatus.OK);
}
 
Example 25
Source Project: cubeai   Source File: ArticleResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * PUT  /articles : Updates an existing article.
 * @param article the article to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated article
 */
@PutMapping("/articles")
@Timed
@Secured({"ROLE_CONTENT"})
public ResponseEntity<Article> updateArticle(@Valid @RequestBody Article article) {
    log.debug("REST request to update Article : {}", article);

    article.setModifiedDate(Instant.now());
    Article result = articleRepository.save(article);
    return ResponseEntity.ok()
        .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, article.getId().toString()))
        .body(result);
}
 
Example 26
Source Project: cubeai   Source File: ArticleResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET  /articles/:id : get the "id" article.
 * @param id the id of the article to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the article, or with status 404 (Not Found)
 */
@GetMapping("/articles/{id}")
@Timed
@Secured({"ROLE_CONTENT"})
public ResponseEntity<Article> getArticle(@PathVariable Long id) {
    log.debug("REST request to get Article : {}", id);
    Article article = articleRepository.findOne(id);
    return ResponseUtil.wrapOrNotFound(Optional.ofNullable(article));
}
 
Example 27
Source Project: jhipster-online   Source File: StatisticsResource.java    License: Apache License 2.0 5 votes vote down vote up
@DeleteMapping("/data")
@Secured(AuthoritiesConstants.ADMIN)
public void deleteStatisticsData() {
    User user = userService.getUser();

    log.info("Deleting statistics data of {}", user.getLogin());
    statisticsService.deleteStatistics(user);
}
 
Example 28
Source Project: cubeai   Source File: AttachmentResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * POST  /attachments : Create a new attachment.
 *
 * @param attachment the attachment to create
 * @return the ResponseEntity with status 201 (Created) and with body the new attachment, or with status 401 Unauthorized
 */
@PostMapping("/attachments")
@Timed
@Secured({"ROLE_CONTENT"})
public ResponseEntity<Attachment> createAttachment(HttpServletRequest httpServletRequest,
                                                   @Valid @RequestBody Attachment attachment) {
    log.debug("REST request to save Attachment : {}", attachment);
    String userLogin = JwtUtil.getUserLogin(httpServletRequest);
    attachment.setAuthorLogin(userLogin);
    attachment.setCreatedDate(Instant.now());
    attachment.setModifiedDate(Instant.now());
    Attachment result = attachmentRepository.save(attachment);
    return ResponseEntity.status(201).body(result);
}
 
Example 29
Source Project: cubeai   Source File: AttachmentResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET  /attachments : get all the attachments.
 *
 * @return the ResponseEntity with status 200 (OK) and the list of attachments in body
 */
@GetMapping("/attachments")
@Timed
@Secured({"ROLE_CONTENT"})
public ResponseEntity<List<Attachment>> getAllAttachments(Pageable pageable) {
    log.debug("REST request to get all Attachments");

    Page<Attachment> page = attachmentRepository.findAll(pageable);

    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/api/attachments");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
Example 30
Source Project: cubeai   Source File: AttachmentResource.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * GET  /attachments/:id : get the "id" attachment.
 *
 * @param id the id of the attachment to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the attachment, or with status 404 (Not Found)
 */
@GetMapping("/attachments/{id}")
@Timed
@Secured({"ROLE_CONTENT"})
public ResponseEntity<Attachment> getAttachment(@PathVariable Long id) {
    log.debug("REST request to get Attachment : {}", id);
    Attachment attachment = attachmentRepository.findOne(id);

    if (attachment != null) {
        this.nexusArtifactClient.deleteArtifact(attachment.getUrl());
    }

    return ResponseUtil.wrapOrNotFound(Optional.ofNullable(attachment));
}