List of usage examples for java.security Principal getName
public String getName();
From source file:eu.scidipes.toolkits.pawebapp.web.UserController.java
@RequestMapping(value = "/changepassword", method = RequestMethod.POST) public String saveChangePassword(@ModelAttribute final PasswordChange passwordChange, final BindingResult result, final SessionStatus status, final RedirectAttributes redirectAttrs, final Principal principal) { final User user = userRepo.findOne(principal.getName()); new PasswordChangeValidator(user, passwordEncoder).validate(passwordChange, result); if (result.hasErrors()) { return "/users/changepassword"; }//from w ww . ja va 2s . co m final String encodedNewPassword = passwordEncoder.encode(passwordChange.getNewPassword()); if (user != null) { user.setPassword(encodedNewPassword); userRepo.save(user); LOG.debug("Changed password for user: {}", user.getUsername()); } else { return "redirect:/logout"; } status.setComplete(); redirectAttrs.addFlashAttribute("msgKey", "users.changepassword.success"); return "redirect:/user/"; }
From source file:com.lixiaocong.rest.ArticleController.java
@RequestMapping(method = RequestMethod.GET) public Map<String, Object> get(@RequestParam(required = false, defaultValue = "1") int page, @RequestParam(required = false, defaultValue = "10") int size, Principal principal) { User user = userService.getByUsername(principal.getName()); if (user.isAdmin()) return ResponseMsgFactory.createSuccessResponse("articles", articleService.get(page - 1, size)); else//from w w w. j a v a 2 s. co m return ResponseMsgFactory.createSuccessResponse("articles", articleService.getByUser(page - 1, size, user.getId())); }
From source file:mx.gob.cfe.documentos.web.InicioController.java
@RequestMapping public String inicio(Model model, Principal principal, HttpServletRequest request) { log.info("Mostrando pagina de inicio"); String name = principal.getName(); log.debug("Usuario con rpe{} logeado", name); Usuario usuario = usuarioDao.obtinePorUsername(name); if (usuario.isAdministrador()) { log.debug("Admin en sessin"); }//from w ww . java2 s. c o m request.getSession().setAttribute("usuarioLogeado", usuario); model.addAttribute("mensaje", "Hola desde InicioController"); return "inicio/index"; }
From source file:com.springsource.oauthservice.IdentityController.java
@RequestMapping(value = "/me", method = RequestMethod.GET) public @ResponseBody Map<String, String> getIdentity(Principal principal) { HashMap<String, String> identityMap = new HashMap<String, String>(); identityMap.put("id", principal.getName()); return identityMap; }
From source file:io.github.proxyprint.kitchen.controllers.notifications.NotificationsController.java
@Transactional @ApiOperation(value = "Returns list of notifications.", notes = "This method retrieves to consumer his list of notifications.") @Secured({ "ROLE_USER" }) @RequestMapping(value = "/consumer/notifications", method = RequestMethod.GET) public List<Notification> getConsumerNotifications(Principal principal) { Consumer consumer = this.consumers.findByUsername(principal.getName()); return consumer.getNotifications(); }
From source file:FacultyAdvisement.ImagineBean.java
@PostConstruct public void init() { FacesContext fc = FacesContext.getCurrentInstance(); Principal p = fc.getExternalContext().getUserPrincipal(); username = p.getName(); try {/*w w w. j a v a2s. com*/ student = StudentRepository.read(ds, username); currentCourses = CurrentCourseRepository.readCurrentCourses(ds, student.getId()); } catch (SQLException ex) { Logger.getLogger(AppointmentBean.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:alfio.controller.api.admin.SpecialPriceApiController.java
@RequestMapping(value = "/events/{eventName}/categories/{categoryId}/sent-codes", method = RequestMethod.GET) public List<SpecialPrice> loadSentCodes(@PathVariable("eventName") String eventName, @PathVariable("categoryId") int categoryId, Principal principal) { return specialPriceManager.loadSentCodes(eventName, categoryId, principal.getName()); }
From source file:org.mitreid.multiparty.service.InMemoryResourceService.java
@Override public void shareResourceForUser(SharedResourceSet srs, Principal p) { sharedResourceSets.put(p.getName(), srs); }
From source file:org.ng200.openolympus.controller.solution.SolutionDownloadController.java
@PreAuthorize(SecurityExpressionConstants.IS_ADMIN + SecurityExpressionConstants.OR + '(' + SecurityExpressionConstants.IS_USER + SecurityExpressionConstants.AND + SecurityExpressionConstants.USER_IS_OWNER + SecurityExpressionConstants.AND + "@oolsec.isSolutionInCurrentContest(#solution)" + ')') @RequestMapping(method = RequestMethod.GET) public @ResponseBody ResponseEntity<FileSystemResource> solutionDownload(final HttpServletRequest request, final Model model, @RequestParam(value = "id") final Solution solution, final Principal principal) { if (principal == null || (!solution.getUser().getUsername().equals(principal.getName()) && !request.isUserInRole(Role.SUPERUSER))) { throw new InsufficientAuthenticationException( "You attempted to download a solution that doesn't belong to you!"); }//from w ww . j a va2 s. c om Assertions.resourceExists(solution); final HttpHeaders headers = new HttpHeaders(); headers.setContentDispositionFormData("attachment", this.storageService.getSolutionFile(solution).getFileName().toString()); return new ResponseEntity<FileSystemResource>( new FileSystemResource(this.storageService.getSolutionFile(solution).toFile()), headers, HttpStatus.OK); }
From source file:org.easit.core.controllers.home.HomeController.java
@RequestMapping("/newsPlugin") public @ResponseBody Map<String, Object> getNews(@RequestParam String provider, HttpServletResponse response, EasitAccount acc, Model model, Principal currentUser) { EasitAccount res = accountRepository.findAccountByUsername(currentUser.getName()); Map<String, Object> map = new HashMap<String, Object>(); // response.setContentType("text/event-stream"); if (pluginManager.isLoaded("news")) { map.put("newsLoaded", true); pluginManager.getPlugin("news").execute(res, connectionRepositoryProvider, operationsRepository, map, provider);/* w ww .j a v a 2 s . c om*/ } return map; }