List of usage examples for java.security Principal getName
public String getName();
From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.message.GPSecureMessageResource.java
@PUT @Path(value = GPServiceRSPathConfig.MARK_ALL_MESSAGES_AS_READ_BY_RECIPIENT_PATH) @Override/*from w w w . java2 s . c o m*/ public Boolean markAllMessagesAsReadByRecipient(@Auth Principal principal, @PathParam(value = "recipientID") Long recipientID) throws Exception { logger.debug( "\n\n@@@@@@@@@@@@@@Executing secure" + " markAllMessagesAsReadByRecipient - Principal : {}\n\n", principal.getName()); return super.markAllMessagesAsReadByRecipient(recipientID); }
From source file:org.ng200.openolympus.controller.user.ChangePasswordController.java
@RequestMapping(method = RequestMethod.POST) public String changePassword(Model model, @Valid final PasswordChangeDto userDto, final BindingResult bindingResult, final Principal principal) { if (bindingResult.hasErrors()) { model.addAttribute("postUrl", "/user/changePassword"); model.addAttribute("hideOldPassword", false); return "user/changePassword"; }/*w w w. j a v a2 s . co m*/ final User user = this.userRepository.findByUsername(principal.getName()); if (!this.passwordEncoder.matches(userDto.getExistingPassword(), user.getPassword())) { bindingResult.rejectValue("existingPassword", "", "user.changePassword.form.errors.existingPasswordDoesntMatch"); } if (!userDto.getPassword().equals(userDto.getPasswordConfirmation())) { bindingResult.rejectValue("passwordConfirmation", "", "user.changePassword.form.errors.passwordConfirmationDoesntMatch"); } if (bindingResult.hasErrors()) { model.addAttribute("hideOldPassword", false); model.addAttribute("postUrl", "/user/changePassword"); return "user/changePassword"; } user.setPassword(this.passwordEncoder.encode(userDto.getPassword())); this.userRepository.save(user); return "redirect:/user"; }
From source file:org.fcrepo.auth.webac.WebACAuthorizingRealm.java
@Override protected AuthorizationInfo doGetAuthorizationInfo(final PrincipalCollection principals) { final SimpleAuthorizationInfo authzInfo = new SimpleAuthorizationInfo(); // if the user was assigned the "fedoraAdmin" container role, they get the // "fedoraAdmin" application role if (principals.byType(ContainerRolesPrincipal.class).contains(adminPrincipal)) { authzInfo.addRole(FEDORA_ADMIN_ROLE); } else {//from w w w . jav a 2 s . co m // otherwise, they are a normal user authzInfo.addRole(FEDORA_USER_ROLE); // for non-admins, we must check the ACL for the requested resource // convert the request URI to a JCR node final FedoraResource fedoraResource = getResourceOrParentFromPath(request.getPathInfo()); if (fedoraResource != null) { final Node node = ((FedoraResourceImpl) fedoraResource).getNode(); // check ACL for the request URI and get a mapping of agent => modes final Map<String, Collection<String>> roles = rolesProvider.getRoles(node, true); for (Object o : principals.asList()) { log.debug("User has principal with name: {}", ((Principal) o).getName()); } final Principal userPrincipal = principals.oneByType(BasicUserPrincipal.class); if (userPrincipal != null) { log.debug("Basic user principal username: {}", userPrincipal.getName()); final Collection<String> modesForUser = roles.get(userPrincipal.getName()); if (modesForUser != null) { // add WebACPermission instance for each mode in the Authorization final URI fullRequestURI = URI.create(request.getRequestURL().toString()); for (String mode : modesForUser) { final WebACPermission perm = new WebACPermission(URI.create(mode), fullRequestURI); authzInfo.addObjectPermission(perm); log.debug("Added permission {}", perm); } } } else { log.debug("No basic user principal found"); } } } return authzInfo; }
From source file:com.jd.survey.web.settings.VelocityTemplateController.java
@Secured({ "ROLE_ADMIN" }) @RequestMapping(value = "/{id}", method = RequestMethod.DELETE, produces = "text/html") public String delete(@PathVariable("id") Long id, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "size", required = false) Integer size, Principal principal, Model uiModel) { log.info("delete(): id=" + id); try {//from w w w . ja va2s . c om User user = userService.user_findByLogin(principal.getName()); if (!user.isAdmin()) { return "accessDenied"; } VelocityTemplate surveyDefinition = surveySettingsService.velocityTemplate_findById(id); surveySettingsService.velocityTemplate_remove(surveyDefinition); uiModel.asMap().clear(); uiModel.addAttribute("page", (page == null) ? "1" : page.toString()); uiModel.addAttribute("size", (size == null) ? "10" : size.toString()); return "redirect:/admin/templates"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:alfio.controller.api.admin.CheckInApiController.java
@RequestMapping(value = "/check-in/{eventId}/ticket/{ticketIdentifier}", method = POST) public TicketAndCheckInResult checkIn(@PathVariable("eventId") int eventId, @PathVariable("ticketIdentifier") String ticketIdentifier, @RequestBody TicketCode ticketCode, Principal principal) { return checkInManager.checkIn(eventId, ticketIdentifier, Optional.ofNullable(ticketCode).map(TicketCode::getCode), principal.getName()); }
From source file:demo.oauth.server.controllers.ApplicationController.java
@RequestMapping("/registerClient") public ModelAndView registerApp(@ModelAttribute("client") ClientApp clientApp) throws Exception { if (StringUtils.isEmpty(clientApp.getClientName())) { clientApp.setError("Client name field is required!"); return handleInternalRedirect(clientApp); }// w w w . j a v a2s . com MD5SequenceGenerator tokenGen = new MD5SequenceGenerator(); Principal principal = SecurityContextHolder.getContext().getAuthentication(); String consumerKey = clientApp.getConsumerKey(); if (StringUtils.isEmpty(consumerKey)) { consumerKey = tokenGen .generate((principal.getName() + clientApp.getClientName()).getBytes(StandardCharsets.UTF_8)); } String secretKey = tokenGen.generate(new SecureRandom().generateSeed(20)); Client clientInfo = new Client(consumerKey, secretKey, clientApp.getClientName(), null); clientInfo.setCallbackURI(clientApp.getCallbackURL()); clientInfo.setLoginName(principal.getName()); Client authNInfo = clientManager.registerNewClient(consumerKey, clientInfo); if (authNInfo != null) { clientApp.setError("Client already exists!"); return handleInternalRedirect(clientApp); } ModelAndView modelAndView = new ModelAndView("clientDetails"); modelAndView.getModel().put("clientInfo", clientInfo); return modelAndView; }
From source file:com.epam.ta.reportportal.ws.controller.impl.ProjectController.java
@Override @RequestMapping(value = "/{projectName}/assign", method = PUT, consumes = { APPLICATION_JSON_VALUE }) @ResponseBody//w w w .j a va 2s . c o m @ResponseStatus(OK) @PreAuthorize(PROJECT_LEAD) @ApiOperation("Assign users") public OperationCompletionRS assignProjectUsers(@PathVariable String projectName, @RequestBody @Validated AssignUsersRQ assignUsersRQ, Principal principal) { return updateProjectHandler.assignUsers(EntityUtils.normalizeProjectName(projectName), principal.getName(), assignUsersRQ); }
From source file:org.dawnsci.marketplace.controllers.ExtendedRestApiController.java
/** * Uploads a screenshot to the solution and updates the solution data with * the name of the file being uploaded. Returns a <b>403 Forbidden</b> if * the logged in user is not the owner of the solution. *///from www. j a va 2s. c o m @PreAuthorize("hasRole('UPLOAD')") @RequestMapping(value = "/upload-screenshot") public ResponseEntity<String> uploadScreenshot(Principal principal, @RequestParam("id") Long id, @RequestParam("file") MultipartFile file) throws Exception { // verify that we have the correct owner Account account = accountRepository.findOne(principal.getName()); if (!canEdit(principal, id)) { return new ResponseEntity<String>("Logged in user is not the owner of the solution", HttpStatus.FORBIDDEN); } fileService.saveSolutionFile(id, file); // get solution and update with new information Node node = marketplaceDAO.getSolution(id); node.setScreenshot(file.getOriginalFilename()); Object result = marketplaceDAO.saveOrUpdateSolution(node, account); if (result instanceof Node) { return new ResponseEntity<String>(MarketplaceSerializer.serialize((Node) result), HttpStatus.OK); } else { return new ResponseEntity<String>((String) result, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.dawnsci.marketplace.controllers.ExtendedRestApiController.java
/** * Uploads a image to the solution and updates the solution data with * the name of the file being uploaded. Returns a <b>403 Forbidden</b> if * the logged in user is not the owner of the solution. *///from w w w . j a va 2 s .c o m @PreAuthorize("hasRole('UPLOAD')") @RequestMapping(value = "/upload-image") public ResponseEntity<String> uploadImage(Principal principal, @RequestParam("id") Long id, @RequestParam("file") MultipartFile file) throws Exception { // verify that we have the correct owner Account account = accountRepository.findOne(principal.getName()); if (!canEdit(principal, id)) { return new ResponseEntity<String>("Logged in user is not the owner of the solution", HttpStatus.FORBIDDEN); } fileService.saveSolutionFile(id, file); // get solution and update with new information Node node = marketplaceDAO.getSolution(id); node.setImage(file.getOriginalFilename()); Object result = marketplaceDAO.saveOrUpdateSolution(node, account); if (result instanceof Node) { return new ResponseEntity<String>(MarketplaceSerializer.serialize((Node) result), HttpStatus.OK); } else { return new ResponseEntity<String>((String) result, HttpStatus.INTERNAL_SERVER_ERROR); } }
From source file:org.dawnsci.marketplace.controllers.ExtendedRestApiController.java
/** * Uploads a p2-repository to the solution and updates the solution data * Returns a <b>403 Forbidden</b> if the logged in user is not the owner of * the solution.// w ww. j a v a 2 s .c o m * * The URL to the update site will be overwritten with a new value pointing * to this server. */ @PreAuthorize("hasRole('UPLOAD')") @RequestMapping(value = "/upload-p2repo") public ResponseEntity<String> uploadRepository(Principal principal, @RequestParam("id") Long id, @RequestParam("file") MultipartFile file) throws Exception { // verify that we have the correct owner Account account = accountRepository.findOne(principal.getName()); Account a = accountRepository.findAccountBySolutionId(id); if (!account.getUsername().equals(a.getUsername())) { return new ResponseEntity<String>("Logged in user is not the owner of the solution", HttpStatus.FORBIDDEN); } fileService.uploadRepository(id, file); // get solution and update with new information Node node = marketplaceDAO.getSolution(id); node.setUpdateurl("/files/" + id + "/"); Object result = marketplaceDAO.saveOrUpdateSolution(node, account); if (result instanceof Node) { return new ResponseEntity<String>(MarketplaceSerializer.serialize((Node) result), HttpStatus.OK); } else { return new ResponseEntity<String>((String) result, HttpStatus.INTERNAL_SERVER_ERROR); } }