當前位置: 首頁>>代碼示例>>Java>>正文


Java Secured類代碼示例

本文整理匯總了Java中org.springframework.security.access.annotation.Secured的典型用法代碼示例。如果您正苦於以下問題:Java Secured類的具體用法?Java Secured怎麽用?Java Secured使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Secured類屬於org.springframework.security.access.annotation包,在下文中一共展示了Secured類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
@Secured(ADMIN)
@RequestMapping(value = "/user/{id}/update", method = RequestMethod.PUT)
public ResponseEntity<?> updateUser(@PathVariable("id") long id, @RequestBody UserUpdateDTO updateDTO) {
    Optional<ValidationErrors> errors = validators.validate(updateDTO);
    if (errors.isPresent()) {
        log.warn("User update data has field errors.");
        return new ResponseEntity<>(errors.get().getErrors(), HttpStatus.BAD_REQUEST);
    }
    UserDTO updatedUser = userService.updateUser(id, updateDTO);
    if (updatedUser == null) {
        log.error("No user found with given id({})",id);
        return new ResponseEntity<>("User not found with given id.", HttpStatus.INTERNAL_SERVER_ERROR);
    } else {
        log.debug("User({}) successfully updated by admin.",id);
        return new ResponseEntity<>(updatedUser, HttpStatus.OK);
    }
}
 
開發者ID:RFTDevGroup,項目名稱:RFTBackend,代碼行數:18,代碼來源:UserController.java

示例2: getByDates

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * GET  /audits : get a page of AuditEvents between the fromDate and toDate.
 *
 * @param fromDate the start of the time period of AuditEvents to get
 * @param toDate the end of the time period of AuditEvents to get
 * @param pageable the pagination information
 * @return the ResponseEntity with status 200 (OK) and the list of AuditEvents in body
 * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
 */

@GetMapping(params = {"fromDate", "toDate"})
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<List<AuditEvent>> getByDates(
    @RequestParam(value = "fromDate") LocalDate fromDate,
    @RequestParam(value = "toDate") LocalDate toDate,
    @ApiParam Pageable pageable) throws URISyntaxException {

    Page<AuditEvent> page = auditEventService.findByDates(fromDate.atTime(0, 0), toDate.atTime(23, 59), pageable);
    HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/management/audits");
    return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:22,代碼來源:AuditResource.java

示例3: createUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * 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 user 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
 */
@PostMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity createUser(@Valid @RequestBody UserDTO user) throws URISyntaxException {
    if (user.getId() != null) {
        return ResponseEntity.badRequest()
            .headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new user cannot already have an ID"))
            .body(null);
    }
    user.getLogins().forEach(userLogin ->
        userLoginRepository.findOneByLoginIgnoreCase(userLogin.getLogin())
            .ifPresent(s -> {
                throw new BusinessException(Constants.LOGIN_IS_USED_ERROR_TEXT);
            })
    );
    User newUser = userService.createUser(user);
    produceEvent(new UserDTO(newUser), Constants.CREATE_PROFILE_EVENT_TYPE);
    mailService.sendCreationEmail(newUser, TenantUtil.getApplicationUrl(),
        TenantContext.getCurrent().getTenant(), MDCUtil.getRid());
    return ResponseEntity.created(new URI("/api/users/" + newUser.getUserKey()))
        .headers(HeaderUtil.createAlert("userManagement.created", newUser.getUserKey()))
        .body(new UserDTO(newUser));
}
 
開發者ID:xm-online,項目名稱:xm-uaa,代碼行數:34,代碼來源:UserResource.java

示例4: adminPortalPublishOneUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
@PostMapping(value = "/admin/portal", params = "action=Complete")
@Secured("ROLE_ADMIN")
@ResponseStatus(value = HttpStatus.ACCEPTED)
public String adminPortalPublishOneUser(@ModelAttribute final AdminWindow request, final Map<String, Object> model) {
    try {
        boolean result = adminService.completeAccount(request.getSelectedID());
        if (result) {
            model.put("successOneUser", true);
        } else {
            model.put("publishError", true);
        }
    } catch (Exception e) {
        e.printStackTrace();
        model.put("publishError", true);
    }
    model.put("adminWindow", adminService.generateAdminWindow());
    return "adminPortal";
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:19,代碼來源:AdminResource.java

示例5: createUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * POST  /users -> Create a new user.
 */
@RequestMapping(value = "/users",
    method = RequestMethod.POST,
    produces = MediaType.APPLICATION_JSON_VALUE)
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<User> createUser(@RequestBody User user) throws URISyntaxException {
    log.debug("REST request to save User : {}", user);
    if (user.getId() != null) {
        return ResponseEntity.badRequest().header("Failure", "A new user cannot already have an ID").body(null);
    }
    User result = userRepository.save(user);
    return ResponseEntity.created(new URI("/api/users/" + result.getId()))
            .headers(HeaderUtil.createEntityCreationAlert("user", result.getId().toString()))
            .body(result);
}
 
開發者ID:GastonMauroDiaz,項目名稱:buenojo,代碼行數:19,代碼來源:UserResource.java

示例6: createUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * 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.
 * </p>
 *
 * @param managedUserVM 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
 */
@PostMapping("/users")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity createUser(@RequestBody ManagedUserVM managedUserVM) throws URISyntaxException {
    log.debug("REST request to save User : {}", managedUserVM);

    //Lowercase the user login before comparing with database
    if (userRepository.findOneByLogin(managedUserVM.getLogin().toLowerCase()).isPresent()) {
        return ResponseEntity.badRequest()
            .headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "userexists", "Login already in use"))
            .body(null);
    } else if (userRepository.findOneByEmail(managedUserVM.getEmail()).isPresent()) {
        return ResponseEntity.badRequest()
            .headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "emailexists", "Email already in use"))
            .body(null);
    } else {
        User newUser = userService.createUser(managedUserVM);
        mailService.sendCreationEmail(newUser);
        return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin()))
            .headers(HeaderUtil.createAlert( "userManagement.created", newUser.getLogin()))
            .body(newUser);
    }
}
 
開發者ID:ElectronicArmory,項目名稱:Armory,代碼行數:36,代碼來源:UserResource.java

示例7: updateUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * 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(@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", "E-mail 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()));
}
 
開發者ID:ElectronicArmory,項目名稱:Armory,代碼行數:27,代碼來源:UserResource.java

示例8: updateTask

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * PUT  /tasks : Updates an existing task.
 *
 * @param taskDTO the taskDTO to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated taskDTO,
 * or with status 400 (Bad Request) if the taskDTO is not valid,
 * or with status 500 (Internal Server Error) if the taskDTO couldnt be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/tasks")
@Timed
@Secured(AuthoritiesConstants.MANAGER)
public ResponseEntity<TaskDTO> updateTask(@Valid @RequestBody TaskDTO taskDTO) throws URISyntaxException {
    log.debug("REST request to update Task : {}", taskDTO);
    if (taskDTO.getId() == null) {
        return createTask(taskDTO);
    }
    try {
        TaskDTO result = taskService.save(taskDTO);
        return ResponseEntity.ok()
            .headers(HeaderUtil.createEntityUpdateAlert("task", taskDTO.getId()))
            .body(result);
    } catch (TaskException e) {
        log.warn("Could not update task: {}", taskDTO, e);
        return ResponseEntity.badRequest()
            .headers(HeaderUtil.createErrorAlert("Scheduler could not update this task")).body(null);
    }
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:29,代碼來源:TaskResource.java

示例9: updateUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * 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()));
}
 
開發者ID:deepu105,項目名稱:spring-io,代碼行數:27,代碼來源:UserResource.java

示例10: performAction

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
@PostMapping("/bots/{id}/{action}")
@Timed
@Secured(AuthoritiesConstants.ADMIN)
public ResponseEntity<Void> performAction(@PathVariable String id, @PathVariable String action) {
    log.debug("REST request to perform action {} on Bot : {}", action, id);
    switch (action) {
        case "login":
            return loginBot(id);
        case "logout":
            return logoutBot(id);
        case "reset":
            return resetBot(id);
        default:
            return ResponseEntity.badRequest()
                .headers(HeaderUtil.createAlert("Invalid action: " + action, action))
                .body(null);
    }
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:19,代碼來源:BotResource.java

示例11: adminPortalPublishAllUsers

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
@PostMapping(value = "/admin/portal", params = "action=Complete All")
@ResponseStatus(value = HttpStatus.ACCEPTED)
@Secured("ROLE_ADMIN")
public String adminPortalPublishAllUsers(final Map<String, Object> model) {
    try {
        String result = adminService.completeAllAccounts();
        if (result.equals("allSuccess")) {
            model.put(result, true);
        } else if (result.equals("partialSuccess")) {
            model.put(result, true);
        } else { //zeroSuccess
            model.put(result, true);
        }
    } catch (Exception e) {
        e.printStackTrace();
        model.put("publishError", true);
    }
    model.put("adminWindow", adminService.generateAdminWindow());
    return "adminPortal";
}
 
開發者ID:blmalone,項目名稱:Blockchain-Academic-Verification-Service,代碼行數:21,代碼來源:AdminResource.java

示例12: createUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * 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 managedUserVM 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 ManagedUserVM managedUserVM) throws URISyntaxException {
    log.debug("REST request to save User : {}", managedUserVM);

    if (managedUserVM.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(managedUserVM.getLogin().toLowerCase()).isPresent()) {
        throw new LoginAlreadyUsedException();
    } else if (userRepository.findOneByEmailIgnoreCase(managedUserVM.getEmail()).isPresent()) {
        throw new EmailAlreadyUsedException();
    } else {
        User newUser = userService.createUser(managedUserVM);
        mailService.sendCreationEmail(newUser);
        return ResponseEntity.created(new URI("/api/users/" + newUser.getLogin()))
            .headers(HeaderUtil.createAlert( "userManagement.created", newUser.getLogin()))
            .body(newUser);
    }
}
 
開發者ID:asanzdiego,項目名稱:codemotion-2017-taller-de-jhipster,代碼行數:34,代碼來源:UserResource.java

示例13: makeBid

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
@Secured(USER)
@RequestMapping(value = "/transport/{id}/bid", method = RequestMethod.POST)
public ResponseEntity<?> makeBid(@PathVariable("id") long transportId, @RequestBody PlaceBidDTO bidDTO, Principal principal) {
    log.debug("{} trying to make a bid on transport({})",principal.getName(), transportId);
    try {
        auctionService.makeBid(transportId, bidDTO.getAmount(), principal.getName());
        return new ResponseEntity<>("Bid placed.", HttpStatus.OK);
    } catch (AuctionError auerr) {
        log.error("Error happened during bidding: {}",auerr.getMessage());
        return new ResponseEntity<>(auerr.getMessage(), HttpStatus.BAD_REQUEST);
    }
}
 
開發者ID:RFTDevGroup,項目名稱:RFTBackend,代碼行數:13,代碼來源:AuctionController.java

示例14: updateUser

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * 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()));
}
 
開發者ID:pascalgrimaud,項目名稱:qualitoast,代碼行數:27,代碼來源:UserResource.java

示例15: updateFlow

import org.springframework.security.access.annotation.Secured; //導入依賴的package包/類
/**
 * PUT  /flows : Updates an existing flow.
 *
 * @param flowDTO the flowDTO to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated flowDTO,
 * or with status 400 (Bad Request) if the flowDTO is not valid,
 * or with status 500 (Internal Server Error) if the flowDTO couldnt be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/flows")
@Timed
@Secured(AuthoritiesConstants.MANAGER)
public ResponseEntity<FlowDTO> updateFlow(@Valid @RequestBody FlowDTO flowDTO) throws URISyntaxException {
    log.debug("REST request to update Flow : {}", flowDTO);
    if (flowDTO.getId() == null) {
        return createFlow(flowDTO);
    }
    try {
        FlowDTO result = flowService.save(flowDTO);
        return ResponseEntity.ok()
            .headers(HeaderUtil.createEntityUpdateAlert("flow", flowDTO.getId()))
            .body(result);
    } catch (TaskException e) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert("flow",
            "badarg", "An event flow must have a valid event type as message"))
            .body(null);
    }
}
 
開發者ID:quanticc,項目名稱:sentry,代碼行數:29,代碼來源:FlowResource.java


注:本文中的org.springframework.security.access.annotation.Secured類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。