org.springframework.security.access.annotation.Secured Java Examples
The following examples show how to use
org.springframework.security.access.annotation.Secured.
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 File: UserResource.java From Full-Stack-Development-with-JHipster with MIT License | 7 votes |
/** * 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 #2
Source File: GatewayResource.java From okta-jhipster-microservices-oauth-example with Apache License 2.0 | 6 votes |
/** * 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 #3
Source File: UserResource.java From flair-engine with Apache License 2.0 | 6 votes |
/** * 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 #4
Source File: UserResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * 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 #5
Source File: UserResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * 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 #6
Source File: UserResource.java From jhipster-microservices-example with Apache License 2.0 | 6 votes |
/** * 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 #7
Source File: UserResource.java From Full-Stack-Development-with-JHipster with MIT License | 6 votes |
/** * 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 #8
Source File: GatewayResource.java From e-commerce-microservice with Apache License 2.0 | 6 votes |
/** * 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 #9
Source File: UserService.java From production-ready-microservices-starter with MIT License | 6 votes |
/** * 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 File: TenantService.java From production-ready-microservices-starter with MIT License | 6 votes |
/** * 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 #11
Source File: DeploymentResource.java From cubeai with Apache License 2.0 | 6 votes |
/** * 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 #12
Source File: JdlResource.java From jhipster-online with Apache License 2.0 | 6 votes |
@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 #13
Source File: UserResource.java From TeamDojo with Apache License 2.0 | 6 votes |
/** * 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 #14
Source File: JdlResource.java From jhipster-online with Apache License 2.0 | 5 votes |
/** * Update a JDL file. */ @PutMapping("/jdl/{jdlId}") @Secured(AuthoritiesConstants.USER) public @ResponseBody ResponseEntity updateJdlFile(@PathVariable String jdlId, @RequestBody JdlVM vm) { Optional<JdlMetadata> jdlMetadata = jdlMetadataService.findOne(jdlId); try { jdlMetadataService.updateJdlContent(jdlMetadata.get(), vm.getContent()); } catch (Exception e) { log.info("Could not update the JDL file", e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>(HttpStatus.OK); }
Example #15
Source File: GrpcServerService.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Override @Secured("ROLE_TEST") public void sayHello(final HelloRequest req, final StreamObserver<HelloReply> responseObserver) { final HelloReply reply = HelloReply.newBuilder().setMessage("Hello ==> " + req.getName()).build(); responseObserver.onNext(reply); responseObserver.onCompleted(); }
Example #16
Source File: EntityStatsResource.java From jhipster-online with Apache License 2.0 | 5 votes |
/** * PUT /entity-stats : Updates an existing entityStats. * * @param entityStats the entityStats to update * @return the ResponseEntity with status 200 (OK) and with body the updated entityStats, * or with status 400 (Bad Request) if the entityStats is not valid, * or with status 500 (Internal Server Error) if the entityStats couldn't be updated * @throws URISyntaxException if the Location URI syntax is incorrect */ @PutMapping("/entity-stats") @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<EntityStats> updateEntityStats(@RequestBody EntityStats entityStats) { log.debug("REST request to update EntityStats : {}", entityStats); if (entityStats.getId() == null) { throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); } EntityStats result = entityStatsService.save(entityStats); return ResponseEntity.ok() .headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, entityStats.getId().toString())) .body(result); }
Example #17
Source File: TenantService.java From production-ready-microservices-starter with MIT License | 5 votes |
/** * Gets tenants page. * * @param orgId the org id * @param pageable the pageable * @return the tenants */ @Secured(ROLE_SUPERADMIN) @Transactional(readOnly = true) public TenantsResponse getTenants(String orgId, Pageable pageable) { Page<Tenant> tenantPage = tenantRepository.findAllByOrgId(orgId, pageable); long totalElements = tenantPage.getTotalElements(); int totalPage = tenantPage.getTotalPages(); int size = tenantPage.getSize(); int page = tenantPage.getNumber(); List<TenantResponse> tenantResponseList = new ArrayList<>(); for (Tenant tenant : tenantPage.getContent()) { tenantResponseList.add(TenantResponse.builder() .id(tenant.getId()) .name(tenant.getTenant()) .orgId(tenant.getOrg().getId()) .build()); } return TenantsResponse.builder() .items(tenantResponseList) .page(page) .size(size) .totalPages(totalPage) .totalElements(totalElements) .build(); }
Example #18
Source File: UserResource.java From Full-Stack-Development-with-JHipster with MIT License | 5 votes |
/** * 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( "userManagement.deleted", login)).build(); }
Example #19
Source File: JdlResource.java From jhipster-online with Apache License 2.0 | 5 votes |
/** * Create a new JDL files and gives back its key. */ @PostMapping("/jdl") @Secured(AuthoritiesConstants.USER) public @ResponseBody ResponseEntity createJdlFile(@RequestBody JdlVM vm) throws URISyntaxException { JdlMetadata jdlMetadata = new JdlMetadata(); if (vm.getName() == null || vm.getName().equals("")) { jdlMetadata.setName("New JDL Model"); } else { jdlMetadata.setName(vm.getName()); } jdlMetadataService.create(jdlMetadata, vm.getContent()); return ResponseEntity.created(new URI("/api/jdl/" + jdlMetadata.getId())) .body(jdlMetadata); }
Example #20
Source File: UserResource.java From jhipster-microservices-example with Apache License 2.0 | 5 votes |
/** * @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 File: OrgService.java From production-ready-microservices-starter with MIT License | 5 votes |
/** * Create Org. * * @param orgCreateUpdateRequest the org create update request * @return the uuid */ @Secured(ROLE_SUPERADMIN) public IdentityResponse createOrg(OrgCreateUpdateRequest orgCreateUpdateRequest) { if (orgRepository.existsByOrg(orgCreateUpdateRequest.getName())) { throw new ValidationException("Org '" + orgCreateUpdateRequest.getName() + "' is already exist."); } String uuid = uuidUtil.getUuid(); Org org = new Org(); org.setId(uuid); org.setOrg(orgCreateUpdateRequest.getName()); orgRepository.saveAndFlush(org); return new IdentityResponse(uuid); }
Example #22
Source File: OrgService.java From production-ready-microservices-starter with MIT License | 5 votes |
/** * Gets org. * * @param orgId the orgId * @return the org */ @Secured(ROLE_SUPERADMIN) @Transactional(readOnly = true) public OrgResponse getOrg(String orgId) { Org org = getOrgOrThrowNotFoundException(orgId); return OrgResponse.builder().id(org.getId()).name(org.getOrg()).build(); }
Example #23
Source File: UserController.java From java-master with Apache License 2.0 | 5 votes |
/** * 创建用户 */ @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 #24
Source File: SubGenEventResource.java From jhipster-online with Apache License 2.0 | 5 votes |
/** * PUT /sub-gen-events : Updates an existing subGenEvent. * * @param subGenEvent the subGenEvent to update * @return the ResponseEntity with status 200 (OK) and with body the updated subGenEvent, * or with status 400 (Bad Request) if the subGenEvent is not valid, * or with status 500 (Internal Server Error) if the subGenEvent couldn't be updated * @throws URISyntaxException if the Location URI syntax is incorrect */ @PutMapping("/sub-gen-events") @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<SubGenEvent> updateSubGenEvent(@RequestBody SubGenEvent subGenEvent) { log.debug("REST request to update SubGenEvent : {}", subGenEvent); if (subGenEvent.getId() == null) { throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); } SubGenEvent result = subGenEventService.save(subGenEvent); return ResponseEntity.ok() .headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, subGenEvent.getId().toString())) .body(result); }
Example #25
Source File: UserResource.java From jhipster-microservices-example with Apache License 2.0 | 5 votes |
/** * 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( "userManagement.deleted", login)).build(); }
Example #26
Source File: GrpcServerService.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Override @Secured("ROLE_GREET") public void sayHello(final HelloRequest req, final StreamObserver<HelloReply> responseObserver) { final HelloReply reply = HelloReply.newBuilder().setMessage("Hello ==> " + req.getName()).build(); responseObserver.onNext(reply); responseObserver.onCompleted(); }
Example #27
Source File: YoRCResource.java From jhipster-online with Apache License 2.0 | 5 votes |
/** * DELETE /yo-rcs/:id : delete the "id" yoRC. * * @param id the id of the yoRC to delete * @return the ResponseEntity with status 200 (OK) */ @DeleteMapping("/yo-rcs/{id}") @Secured(AuthoritiesConstants.ADMIN) public ResponseEntity<Void> deleteYoRC(@PathVariable Long id) { log.debug("REST request to delete YoRC : {}", id); yoRCService.delete(id); return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, false, ENTITY_NAME, id.toString())).build(); }
Example #28
Source File: TestServiceImpl.java From grpc-spring-boot-starter with MIT License | 5 votes |
@Override @Secured("ROLE_CLIENT1") public StreamObserver<SomeType> secureDrain(final StreamObserver<Empty> responseObserver) { final Authentication authentication = assertAuthenticated("secureDrain"); assertSameAuthenticatedGrcContextCancellation("secureDrain-cancellation", authentication); return new StreamObserver<SomeType>() { @Override public void onNext(final SomeType input) { assertSameAuthenticated("secureDrain-onNext", authentication); assertEquals("1.2.3", input.getVersion()); } @Override public void onError(final Throwable t) { assertSameAuthenticated("secureDrain-onError", authentication); responseObserver.onError(t); } @Override public void onCompleted() { assertSameAuthenticated("secureDrain-onCompleted", authentication); responseObserver.onNext(Empty.getDefaultInstance()); responseObserver.onCompleted(); } }; }
Example #29
Source File: UserResource.java From Full-Stack-Development-with-JHipster with MIT License | 5 votes |
/** * @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 #30
Source File: CiCdResource.java From jhipster-online with Apache License 2.0 | 5 votes |
@PostMapping("/ci-cd/{gitProvider}/{organizationName}/{projectName}/{ciCdTool}") @Secured(AuthoritiesConstants.USER) public ResponseEntity configureCiCd(@PathVariable String gitProvider, @PathVariable String organizationName, @PathVariable String projectName, @PathVariable String ciCdTool) { boolean isGitHub = gitProvider.toLowerCase().equals("github"); log.info("Configuring CI: {} on " + (isGitHub ? "GitHub" : "GitLab") + " {}/{}", ciCdTool, organizationName, projectName); User user = userService.getUser(); String ciCdId = "ci-" + System.nanoTime(); Optional<CiCdTool> integrationTool = CiCdTool.getByName(ciCdTool); if (!integrationTool.isPresent()) { this.logsService.addLog(ciCdId, "Continuous Integration with `" + ciCdTool + "` is not supported."); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } this.logsService.addLog(ciCdId, "Continuous Integration with " + StringUtils.capitalize(ciCdTool) + " is going to be applied to " + organizationName + "/" + projectName); try { this.ciCdService.configureCiCd(user, organizationName, projectName, integrationTool.get(), ciCdId, GitProvider.getGitProviderByValue(gitProvider).orElseThrow(null)); } catch (Exception e) { log.error("Error generating application", e); this.logsService.addLog(ciCdId, "An error has occurred: " + e.getMessage()); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } return new ResponseEntity<>(ciCdId, HttpStatus.CREATED); }