List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:com.rambird.miles.repository.jdbc.JdbcMileRepositoryImpl.java
@Override public void save(MyMile mile) throws DataAccessException { BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(mile); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); mile.setUserName(auth.getName()); //get logged in username if (mile.isNew()) { Number newKey = this.insertMile.executeAndReturnKey(parameterSource); mile.setMileId(newKey.intValue()); } else {// w w w .j ava 2 s . c om this.namedParameterJdbcTemplate.update( "UPDATE mymiles SET catg=:catg, milestone=:milestone, user_name=:userName WHERE mileid=:mileId", parameterSource); } }
From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaAuthenticationManager.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); String password = (String) authentication.getCredentials(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED); headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); MultiValueMap<String, Object> parameters = new LinkedMultiValueMap<String, Object>(); parameters.set("username", username); parameters.set("password", password); @SuppressWarnings("rawtypes") ResponseEntity<Map> response = restTemplate.exchange(loginUrl, HttpMethod.POST, new HttpEntity<MultiValueMap<String, Object>>(parameters, headers), Map.class); if (response.getStatusCode() == HttpStatus.OK) { String userFromUaa = (String) response.getBody().get("username"); if (userFromUaa.equals(userFromUaa)) { logger.info("Successful authentication request for " + authentication.getName()); return new UsernamePasswordAuthenticationToken(username, null, UaaAuthority.USER_AUTHORITIES); }/* w w w . j av a 2s.com*/ } else if (response.getStatusCode() == HttpStatus.UNAUTHORIZED) { logger.info("Failed authentication request"); throw new BadCredentialsException("Authentication failed"); } else if (response.getStatusCode() == HttpStatus.INTERNAL_SERVER_ERROR) { logger.info("Internal error from UAA. Please Check the UAA logs."); } else { logger.error("Unexpected status code " + response.getStatusCode() + " from the UAA." + " Is a compatible version running?"); } throw new RuntimeException("Could not authenticate with remote server"); }
From source file:de.blizzy.documentr.web.project.ProjectController.java
@RequestMapping(value = "/delete/{name:" + DocumentrConstants.PROJECT_NAME_PATTERN + "}", method = RequestMethod.GET) @PreAuthorize("hasApplicationPermission(EDIT_PROJECT)") public String deleteProject(@PathVariable String name, Authentication authentication) throws IOException { User user = userStore.getUser(authentication.getName()); globalRepositoryManager.deleteProject(name, user); return "redirect:/projects"; //$NON-NLS-1$ }
From source file:gateway.auth.PiazzaBasicAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { try {//from www . j a v a 2 s . c om AuthenticationResponse response = userDetails.getAuthenticationDecision(authentication.getName()); if (response.getAuthenticated()) { return new UsernamePasswordAuthenticationToken(response.getUsername(), null, new ArrayList<>()); } } catch (Exception exception) { String error = String.format("Error retrieving UUID: %s.", exception.getMessage()); logger.log(error, PiazzaLogger.ERROR); LOGGER.error(error, exception); } return null; }
From source file:controller.PackagesCustomer.java
@RequestMapping(method = RequestMethod.GET) public ModelAndView packagesCustomer(Authentication authen) { ModelAndView model = new ModelAndView(); model.setViewName("packagesCustomer"); Customer cus = cusModel.find(authen.getName(), "username", false).get(0); int orderID = orderModel.getOrderIDByCustomer(cus.getCustomerId()); Order od = orderModel.getByID(orderID); Set<OderDetail> listDetail = od.getOderDetails(); model.addObject("listOrderDetail", listDetail); model.addObject("title", "My packages"); return model; }
From source file:org.statefulj.webapp.services.impl.UserSessionServiceImpl.java
@Override public User findLoggedInUser() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username return userRepo.findByEmail(name); }
From source file:com.alehuo.wepas2016projekti.controller.SearchController.java
/** * Haun ksittely/*from w ww.j a va2s . c om*/ * * @param a Autentikointi * @param m Malli * @param searchTerm Hakutermi * @return */ @RequestMapping(method = RequestMethod.POST) public String doSearch(Authentication a, Model m, @RequestParam String searchTerm) { LOG.log(Level.INFO, "Kayttaja ''{0}'' haki hakusanalla ''{1}''.", new Object[] { a.getName(), searchTerm }); m.addAttribute("user", userService.getUserByUsername(a.getName())); if (!searchTerm.trim().isEmpty()) { //Lista kyttjtileist m.addAttribute("userlist", userService.getUsersByUsernameLike(searchTerm)); } return "search"; }
From source file:com.epam.ta.reportportal.auth.permissions.AssignedToProjectPermission.java
/** * Check whether user assigned to project<br> * Or user is ADMIN who is GOD of ReportPortal *//*from w ww .ja v a2s . co m*/ @Override public boolean isAllowed(Authentication authentication, Object projectName) { return authentication.isAuthenticated() && projectRepository.get().isAssignedToProject((String) projectName, authentication.getName()); }
From source file:org.nuclos.client.remote.http.SecuredBasicAuthHttpInvokerRequestExecutor.java
@Override protected HttpPost createHttpPost(HttpInvokerClientConfiguration config) throws IOException { HttpPost postMethod = super.createHttpPost(config); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if ((auth != null) && (auth.getName() != null)) { String base64 = auth.getName() + ":" + LangUtils.defaultIfNull(auth.getCredentials(), ""); postMethod.setHeader("Authorization", "Basic " + new String(Base64.encodeBase64(base64.getBytes()))); }/* w w w .ja v a 2 s .c om*/ return postMethod; }
From source file:com.mascova.caliga.controller.UserController.java
@RequestMapping(value = "/profile", method = RequestMethod.GET) public String profile(Model model) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); User user = userService.findById(auth.getName()); UserForm userForm = new UserForm(); userForm.bindToForm(user);//from ww w . j a va2 s . c o m model.addAttribute("userForm", userForm); return "user/user-profile"; }