List of usage examples for java.security Principal getName
public String getName();
From source file:com.jd.survey.web.settings.QuestionRowLabelController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", params = "form", produces = "text/html") public String updateForm(@PathVariable("id") Long questionId, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { try {/* w ww. j av a2s . com*/ String login = principal.getName(); User user = userService.user_findByLogin(login); Question question = surveySettingsService.question_findById(questionId); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(question.getPage().getSurveyDefinition().getId(), user) && !securityService.userBelongsToDepartment( question.getPage().getSurveyDefinition().getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } SortedSet<QuestionRowLabel> RowLabels = question.getRowLabels(); log.info("initial set size" + RowLabels.size()); for (int i = 1; i <= EMPTY_OPTIONS_COUNT; i++) { log.info("adding to set" + i); RowLabels.add(new QuestionRowLabel(question, (short) (question.getRowLabels().size() + i))); } question.setRowLabels(RowLabels); uiModel.addAttribute("question", question); return "settings/questionRows/update"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.ushahidi.swiftriver.core.api.controller.FormsController.java
/** * Handler for deleting a form field./*w ww . ja va 2s . c om*/ * * @param body * @return */ @RequestMapping(value = "/{formId}/fields/{fieldId}", method = RequestMethod.DELETE) @ResponseBody public void deleteField(Principal principal, @PathVariable Long formId, @PathVariable Long fieldId) { formService.deleteField(formId, fieldId, principal.getName()); }
From source file:alfio.controller.api.admin.AdminWaitingQueueApiController.java
@RequestMapping(value = "/load", method = RequestMethod.GET) public List<WaitingQueueSubscription> loadAllSubscriptions(@PathVariable("eventName") String eventName, Principal principal, HttpServletResponse response) { Optional<List<WaitingQueueSubscription>> count = optionally( () -> eventManager.getSingleEvent(eventName, principal.getName())) .map(e -> waitingQueueManager.loadAllSubscriptionsForEvent(e.getId())); if (count.isPresent()) { return count.get(); }/* w ww. j av a 2s . c o m*/ response.setStatus(HttpServletResponse.SC_NOT_FOUND); return Collections.emptyList(); }
From source file:eu.eidas.auth.engine.SAMLEngineUtils.java
/** * * @param keystore/*w w w .j a v a 2 s .c om*/ * @param serialNumber * @param issuer * @return a certificate/alias pair from the keystore, having the given issuer and serialNumber * @throws KeyStoreException * @throws SAMLEngineException */ public static CertificateAliasPair getCertificatePair(KeyStore keystore, String serialNumber, String issuer) throws KeyStoreException, SAMLEngineException { String alias = null; String aliasCert; X509Certificate certificate; boolean find = false; LOG.debug("cherche dans " + keystore.toString() + " numSerie=" + serialNumber + " issuer=" + issuer); for (final Enumeration<String> e = keystore.aliases(); e.hasMoreElements() && !find;) { aliasCert = e.nextElement(); certificate = (X509Certificate) keystore.getCertificate(aliasCert); final String serialNum = certificate.getSerialNumber().toString(16); Principal p = certificate.getIssuerDN(); String name = p.getName(); X500Name issuerDN = new X500Name(name); X500Name issuerDNConf = new X500Name(issuer); if (serialNum.equalsIgnoreCase(serialNumber) && X500PrincipalUtil.principalEquals(issuerDN, issuerDNConf)) { alias = aliasCert; find = true; } else { LOG.debug("pas pareil numSerie=" + serialNum + " ou issuer=" + name); } } if (!find) { throw new SAMLEngineException( "Certificate " + issuer + "/" + serialNumber + " cannot be found in keystore "); } certificate = (X509Certificate) keystore.getCertificate(alias); return new CertificateAliasPair(certificate, alias); }
From source file:com.pw.ism.controllers.AccountController.java
@RequestMapping(value = "/pass", params = "form", method = RequestMethod.POST) public ModelAndView changePass(User user, BindingResult bindingResult, Principal principal, RedirectAttributes redirectAttributes) { if (bindingResult.hasErrors()) { return new ModelAndView("account", "formErrors", bindingResult.getAllErrors()); }//w ww.j av a 2s . com User currentUser = userRepo.findBySsoId(principal.getName()); currentUser.setPassword(passEncoder.encode(user.getPassword())); userRepo.save(currentUser); redirectAttributes.addFlashAttribute("globalMessage", "Password changed"); return new ModelAndView("redirect:/account"); }
From source file:alfio.controller.api.admin.ExtensionApiController.java
private void ensureAdmin(Principal principal) { Validate.isTrue(userManager.isAdmin(userManager.findUserByUsername(principal.getName()))); }
From source file:pdl.web.controller.rest.RestMainController.java
/** * deletes a file// ww w . java 2s . c o m * @param fileId unique file identifier (rowKey of FileDetail table) * @return string message in json format * @format curl <ip address>:<port>/pdl/r/file/delete/?fileId=<fileId> -u <user id>:<pass> */ @RequestMapping(value = "file/delete", method = RequestMethod.POST) public @ResponseBody Map<String, String> fileDelete(@RequestParam("id") String fileId, Principal principal) { Map<String, String> rtnJson = handler.deleteFile(fileId, principal.getName()); return rtnJson; }
From source file:com.epam.ta.reportportal.ws.controller.impl.TestItemController.java
@Override @PutMapping("/{testItemId}") @ResponseBody//from w w w .jav a2s . c o m @ResponseStatus(OK) @ApiOperation("Finish test item") public OperationCompletionRS finishTestItem(@PathVariable String projectName, @PathVariable String testItemId, @RequestBody @Validated FinishTestItemRQ finishExecutionRQ, Principal principal) { return finishTestItemHandler.finishTestItem(testItemId, finishExecutionRQ, principal.getName()); }
From source file:com.pw.ism.controllers.AccountController.java
@RequestMapping(value = "/details", params = "form", method = RequestMethod.POST) public ModelAndView changeDetails(User user, BindingResult bindingResult, Principal principal, RedirectAttributes redirectAttributes) { if (bindingResult.hasErrors()) { return new ModelAndView("account", "formErrors", bindingResult.getAllErrors()); }/*from ww w . j av a2 s .c o m*/ User currentUser = userRepo.findBySsoId(principal.getName()); currentUser.setEmail(user.getEmail()); currentUser.setFirstName(user.getFirstName()); currentUser.setLastName(user.getLastName()); userRepo.save(currentUser); redirectAttributes.addFlashAttribute("globalMessage", "Details changed"); return new ModelAndView("redirect:/account"); }
From source file:org.geosdi.geoplatform.experimental.dropwizard.resources.secure.viewport.GPSecureViewportResource.java
@PUT @Path(value = GPServiceRSPathConfig.REPLACE_VIEWPORT_LIST_PATH) @Override/*from w w w . j av a 2 s .c o m*/ public void replaceViewportList(@Auth Principal principal, ManageViewportRequest request) throws Exception { logger.debug("\n\n@@@@@@@@@@@@@@Executing secure " + "replaceViewportList - Principal : {}\n\n", principal.getName()); super.replaceViewportList(request); }