List of usage examples for java.security Principal getName
public String getName();
From source file:alfio.controller.api.AdminApiController.java
@RequestMapping(value = "/events/{eventId}/categories/new", method = POST) public ValidationResult createCategory(@PathVariable("eventId") int eventId, @RequestBody TicketCategoryModification category, Errors errors, Principal principal) { return Validator.validateCategory(category, errors) .ifSuccess(() -> eventManager.insertCategory(eventId, category, principal.getName())); }
From source file:com.evilisn.DAO.CertMapper.java
@Override public Object mapRow(ResultSet resultSet, int i) throws SQLException { Cert crt = new Cert(); crt.setCertificate(resultSet.getString("certificate")); CertificateFactory fact = null; try {//from w ww . j av a 2 s.co m fact = CertificateFactory.getInstance("X.509"); } catch (CertificateException e) { e.printStackTrace(); } X509Certificate x509cert = null; InputStream stream = new ByteArrayInputStream(crt.getCertificate().getBytes(StandardCharsets.UTF_8)); try { x509cert = (X509Certificate) fact.generateCertificate(stream); crt.setClient_cert(x509cert); } catch (CertificateException e) { e.printStackTrace(); } crt.setResponder_uri(OCSP.getResponderURI(x509cert)); X509Certificate issuerCert; if (!cached_issuers.containsKey(getIssuerCertURL(x509cert))) { //download and set the issuers. try { issuerCert = getX509Certificate(httpGetBin(getIssuerCertURL(x509cert), true)); cached_issuers.put(getIssuerCertURL(x509cert), issuerCert); crt.setIssuer_cert(issuerCert); } catch (Exception e) { e.printStackTrace(); } } else { issuerCert = cached_issuers.get(getIssuerCertURL(x509cert)); crt.setIssuer_cert(issuerCert); } Principal principal = x509cert.getIssuerDN(); String issuerDn = principal.getName(); crt.setIssuer_dn(issuerDn); return crt; }
From source file:org.drugis.trialverse.config.controller.IndexController.java
@RequestMapping("/") public String index(Principal currentUser, Model model, HttpServletRequest request) { model.addAttribute("connectionsToProviders", getConnectionRepository().findAllConnections()); try {/*from ww w . j a v a 2s.c o m*/ if (currentUser == null) { return "redirect:/signin"; } else { Account account = accountRepository.findAccountByUsername(currentUser.getName()); model.addAttribute(account); model.addAttribute("userEmail", account.getUsername()); model.addAttribute("userNameHash", account.getuserNameHash()); } } catch (org.springframework.dao.EmptyResultDataAccessException e) { request.getSession().invalidate(); return "redirect:/signin"; } return "index"; }
From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpoints.java
private void checkClient(String client, Principal principal) { if (principal instanceof OAuth2Authentication) { OAuth2Authentication authentication = (OAuth2Authentication) principal; if (!authentication.isClientOnly() || !client.equals(principal.getName()) && !isAdmin(principal)) { throw new AccessDeniedException(String.format("Client '%s' cannot obtain tokens for client '%s'", principal.getName(), client)); }/*from w w w . j av a 2 s . c om*/ } }
From source file:pdl.web.controller.rest.RestMainController.java
@RequestMapping(value = "role", method = RequestMethod.GET) public @ResponseBody Map<String, Object> getRoles(HttpServletRequest req, Principal principal) { Map<String, Object> rtnJson = new HashMap<String, Object>(); rtnJson.put("hinder", req.isUserInRole("ROLE_ADMIN")); rtnJson.put("c_u", principal.getName()); return rtnJson; }
From source file:com.zanshang.controllers.web.SettingController.java
@RequestMapping(method = RequestMethod.GET) @Secured("ROLE_USER") public Object settings(HttpServletRequest request, Principal principal) { ObjectId uid = new ObjectId(principal.getName()); Setting setting = settingService.get(uid); List<Address> addressList = addressService.findByUid(uid); Person person = personService.get(uid); ModelAndView mav = new ModelAndView(); mav.addObject("email", setting.getEmail()); mav.addObject("displayName", setting.getDisplayName()); mav.addObject("avatar", setting.getAvatar()); mav.addObject("uid", setting.getUid()); mav.addObject("addresses", addressList); if (person != null) { mav.addObject("verified", authorService.isVerified(uid)); String weixinId = person.getWechatId(); String weiboId = person.getWeiboId(); mav.addObject("phone", person.getPhone()); mav.addObject("qq", person.getQq()); mav.addObject("legalName", person.getLegalName()); mav.addObject("identityCode", person.getIdentityCode()); mav.addObject("identityFront", person.getIdentityFront()); mav.addObject("identityBack", person.getIdentityBack()); if (weixinId != null) { WechatInformation wechatInformation = weixinService.get(weixinId); if (wechatInformation != null) { mav.addObject("wechat", true); mav.addObject("wechat_information", wechatInformation); } else { mav.addObject("wechat", false); mav.addObject("unbind_wechat_uri", request.getContextPath() + WechatController.UNBIND_PATH); }// w w w . j a va 2 s.co m } else { mav.addObject("wechat_appid", WECHAT_APPID); mav.addObject("wechat_redirect_uri", URLEncoder.encode( SERVER_CONTEXT + request.getContextPath() + WechatController.CALLBACK_REQUEST_PATH)); } if (weiboId != null) { WeiboInformation weiboInformation = weiboService.get(weiboId); if (weiboInformation != null) { mav.addObject("weibo", true); mav.addObject("weibo_information", weiboInformation); } else { mav.addObject("weibo", false); mav.addObject("unbind_weibo_uri", request.getContextPath() + WeiboController.UNBIND_PATH); } } else { mav.addObject("weibo_appid", WEIBO_APPID); mav.addObject("weibo_redirect_uri", URLEncoder .encode(SERVER_CONTEXT + request.getContextPath() + WeiboController.CALLBACK_REQUEST_PATH)); } mav.setViewName("7_1"); return mav; } else { mav.addObject("verified", publisherService.isVerified(uid)); Company company = companyService.get(uid); mav.addObject("contactPhone", company.getContactPhone()); mav.addObject("license", company.getLicense()); mav.addObject("companyName", company.getCompanyName()); mav.addObject("companyCode", company.getCompanyCode()); mav.setViewName("7_2"); return mav; } }
From source file:com.jd.survey.web.settings.QuestionColumnLabelController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String createPost(Question question, BindingResult bindingResult, @RequestParam(value = "_proceed", required = false) String proceed, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("create(): handles " + RequestMethod.POST.toString()); try {//w w w. j av a 2s .c o m String login = principal.getName(); User user = userService.user_findByLogin(login); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(surveySettingsService .question_findById(question.getId()).getPage().getSurveyDefinition().getId(), user) && !securityService .userBelongsToDepartment(surveySettingsService.question_findById(question.getId()) .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"; } if (proceed != null) { boolean isValid = true; for (int i = 0; i < question.getColumnLabelsList().size(); i++) { if (question.getColumnLabelsList().get(i).getLabel() != null && question.getColumnLabelsList().get(i).getLabel().trim().length() > 0) { if (question.getColumnLabelsList().get(i).getLabel().trim().length() == 0 || question.getColumnLabelsList().get(i).getLabel().trim().length() > 75) { bindingResult.rejectValue("columnLabelsList[" + i + "].label", "invalidEntry"); isValid = false; } } else { //User is trying to save an empty MC form if (i == 0) { bindingResult.rejectValue("columnLabelsList[" + i + "].label", "invalidEntry"); isValid = false; } } } if (!isValid) { return "settings/questionCols/update"; } else { question = surveySettingsService.question_updateColumnLabels(question); return "settings/questionCols/saved"; } } else { question = surveySettingsService.question_updateColumnLabels(question); return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment( question.getPage().getSurveyDefinition().getId().toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:org.cloudfoundry.identity.uaa.oauth.TokenAdminEndpoints.java
private void checkResourceOwner(String user, Principal principal) { if (principal instanceof OAuth2Authentication) { OAuth2Authentication authentication = (OAuth2Authentication) principal; if (!authentication.isClientOnly() && !user.equals(principal.getName())) { throw new AccessDeniedException( String.format("User '%s' cannot obtain tokens for user '%s'", principal.getName(), user)); }/* www . j a va 2s. c om*/ } else if (!user.equals(principal.getName())) { throw new AccessDeniedException( String.format("User '%s' cannot obtain tokens for user '%s'", principal.getName(), user)); } }
From source file:com.epam.ta.reportportal.ws.controller.impl.ProjectController.java
@Override @RequestMapping(value = "/{projectName}/unassign", method = PUT, consumes = { APPLICATION_JSON_VALUE }) @ResponseBody/* w ww .j av a 2 s . c o m*/ @ResponseStatus(OK) @PreAuthorize(PROJECT_LEAD) @ApiOperation("Un assign users") public OperationCompletionRS unassignProjectUsers(@PathVariable String projectName, @RequestBody @Validated UnassignUsersRQ unassignUsersRQ, Principal principal) { return updateProjectHandler.unassignUsers(EntityUtils.normalizeProjectName(projectName), principal.getName(), unassignUsersRQ); }