List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:nc.noumea.mairie.appock.services.impl.AuthHelperImpl.java
@Override public String getCurrentUserIdentifiant() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null ? authentication.getName() : AppUser.IDENTIFIANT_TEST; }
From source file:nl.surfnet.mujina.spring.security.CustomAuthenticationProvider.java
@SuppressWarnings("serial") @Override//www. j a v a 2 s . c o m public Authentication authenticate(final Authentication authentication) throws AuthenticationException { final String name = authentication.getName(); final String password = authentication.getCredentials().toString(); /* * First check if we know this user. Fallback user if Method.ALL otherwise * an Exception */ Authentication authenticationForUser = getAuthenticationForUser(name, password); if (idpConfiguration.getAuthentication() == AuthenticationMethod.Method.ALL) { return authenticationForUser != null ? authenticationForUser : new SimpleAuthentication(name, password, Arrays.asList((GrantedAuthority) new GrantedAuthorityImpl("ROLE_USER"), (GrantedAuthority) new GrantedAuthorityImpl("ROLE_ADMIN"))); } else { if (authenticationForUser == null) { throw new AuthenticationException("Can not log in") { }; } return authenticationForUser; } }
From source file:BSxSB.Controllers.LoginController.java
@RequestMapping(value = "/index", method = RequestMethod.GET) public String login(Model model, @RequestParam(value = "error", required = false) String error, @RequestParam(value = "logout", required = false) String logout) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); Students currentStudent = StudentDAO.getStudent(name); if (currentStudent != null) { model.addAttribute("student", currentStudent); return "student"; }/*from w w w .j a va 2s . com*/ Admins currentAdmin = AdminDAO.getAdmin(name); if (currentAdmin != null) { SchoolDAO schoolDAO = new SchoolDAO(); ScheduleBlockDAO scheduleBlockDAO = new ScheduleBlockDAO(); List<Schools> schools = schoolDAO.allSchools(); for (Schools school : schools) { List<Scheduleblocks> scheduleBlocks = scheduleBlockDAO .getSchoolsScheduleBlocks(school.getSchoolid()); String SB2Strings = ""; for (Scheduleblocks sb : scheduleBlocks) { SB2Strings += sb.toString(); } school.setScheduleblocks(SB2Strings); } model.addAttribute("school", schools); return "admin"; } List<Schools> schools = SchoolDAO.allSchools(); if (schools != null) { model.addAttribute("school", schools); } return "index"; }
From source file:com.sasav.blackjack.controller.GameController.java
@RequestMapping(value = "/hit", method = RequestMethod.GET) public ModelAndView hit() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String login = auth.getName(); gameCore.hit(login);/*from w w w.j ava 2s.com*/ return new ModelAndView("redirect:game"); }
From source file:com.sasav.blackjack.controller.GameController.java
@RequestMapping(value = "/stand", method = RequestMethod.GET) public ModelAndView stand() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String login = auth.getName(); gameCore.stand(login);/*from ww w. ja v a2 s . com*/ return new ModelAndView("redirect:game"); }
From source file:com.github.djabry.platform.service.security.DefaultAuthenticationProvider.java
/** * Performs authentication with the same contract as {@link * org.springframework.security.authentication.AuthenticationManager#authenticate(org.springframework.security.core.Authentication)}. * * @param authentication the authentication request object. * @return a fully authenticated object including credentials. May return <code>null</code> if the * <code>AuthenticationProvider</code> is unable to support authentication of the passed * <code>Authentication</code> object. In such a case, the next <code>AuthenticationProvider</code> that * supports the presented <code>Authentication</code> class will be tried. * @throws org.springframework.security.core.AuthenticationException if authentication fails. */// w w w . j a v a2 s .com @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); String password = authentication.getCredentials().toString(); UserDetails details = userDetailsService.loadUserByUsername(username); SecurityToken<DBUser> token = springAuthenticationService.login(username, password); if (token != null) { return new UsernamePasswordAuthenticationToken(username, password, details.getAuthorities()); } throw new BadCredentialsException("Incorrect credentials"); }
From source file:com.t2tierp.controller.LoginController.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String nomeUsuario = authentication.getName(); String senha = authentication.getCredentials().toString(); try {//from w ww . ja v a 2 s. com InitialContext initialContext = new InitialContext(); dao = (UsuarioDAO) initialContext.lookup("java:comp/ejb/usuarioDAO"); Md5PasswordEncoder enc = new Md5PasswordEncoder(); senha = enc.encodePassword(nomeUsuario + senha, null); Usuario usuario = dao.getUsuario(nomeUsuario, senha); if (usuario != null) { List<PapelFuncao> funcoes = dao.getPapelFuncao(usuario); List<GrantedAuthority> grantedAuths = new ArrayList<>(); for (PapelFuncao p : funcoes) { grantedAuths.add(new SimpleGrantedAuthority(p.getFuncao().getNome())); } Authentication auth = new UsernamePasswordAuthenticationToken(nomeUsuario, senha, grantedAuths); return auth; } } catch (Exception e) { //e.printStackTrace(); } return null; }
From source file:controller.OrderProductController.java
@RequestMapping(method = RequestMethod.GET) public String orderProduct(Authentication authen, ModelMap mm) { Distributor dis = disModel.find(authen.getName(), "username", false).get(0); List<Product> listProduct = proModel.find(dis, "distributor", false); Vector data = new Vector(); Vector column = new Vector(); column.add("Product Name"); column.add("Customer Name"); column.add("Serial"); column.add("Price"); for (Product p : listProduct) { List<Requirement> listReq = rqModel.find(p, "product", false); for (Requirement requirement : listReq) { if (requirement != null) { Vector tmp = new Vector(); tmp.add(requirement.getProduct().getProductName()); tmp.add("id://" + requirement.getId().getProductId() + ":" + requirement.getId().getCustomerId() + ":" + requirement.getId().getSerial()); tmp.add(requirement.getCustomer().getCusName()); tmp.add(requirement.getId().getSerial()); tmp.add(nformat.format(requirement.getPrice())); data.add(tmp);// w w w . jav a2s .c om } } } mm.put("column", column); mm.put("data", data); mm.put("title", "Order Product Manager"); return "orderProduct"; }
From source file:fr.univrouen.poste.services.ReturnReceiptService.java
public final void sendDepotStatusIfRequired(Authentication auth) { String emailAddress = auth.getName(); boolean isCandidat = auth.getAuthorities().contains(new GrantedAuthorityImpl("ROLE_CANDIDAT")); if (isCandidat) { MailReturnReceiptModeTypes mailReturnReceiptMode = AppliConfig.getCacheMailReturnReceiptModeType(); if (MailReturnReceiptModeTypes.EACH_SESSION.equals(mailReturnReceiptMode)) { String messageBody = ""; User candidat = User.findUsersByEmailAddress(emailAddress, null, null).getSingleResult(); List<PosteCandidature> candidatures = PosteCandidature.findPosteCandidaturesByCandidat(candidat) .getResultList();//from www .j a v a 2 s . c om for (PosteCandidature candidature : candidatures) { messageBody = messageBody + "\n*Poste n" + candidature.getPoste().getNumEmploi() + "*"; for (PosteCandidatureFile candidatureFile : candidature.getCandidatureFiles()) { String filename = candidatureFile.getFilename(); String fileSize = candidatureFile.getFileSizeFormatted(); String sentDate = dateFormatter.print(candidatureFile.getSendTime(), Locale.getDefault()); messageBody = messageBody + "\n - " + filename + " - " + fileSize + " [" + sentDate + "]"; } } String mailFrom = AppliConfig.getCacheMailFrom(); String mailSubject = AppliConfig.getCacheMailSubject(); String mailMessage = AppliConfig.getCacheTexteMailCandidatReturnReceipt(); mailMessage = mailMessage.replaceAll("@@messageBody@@", messageBody); emailService.sendMessage(mailFrom, emailAddress, mailSubject, mailMessage); } } }
From source file:nz.net.orcon.kanban.security.JcrAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authIn) throws AuthenticationException { String username = authIn.getName(); String password = authIn.getCredentials().toString(); logger.info("Authenticated Request - user: " + username); ObjectContentManager ocm = null;/* w w w. j a va 2 s . c om*/ try { ocm = ocmFactory.getOcm(); User user = (User) ocm.getObject(User.class, String.format(URI.USER_URI, username)); if (user != null && user.checkPassword(password)) { logger.info("Authenticated User: " + username); List<GrantedAuthority> grantedAuths = this.securityTool.getRoles(username); Authentication auth = new UsernamePasswordAuthenticationToken(username, password, grantedAuths); return auth; } else { logger.warn("Authentication Failure: " + username); } } catch (Exception e) { logger.error("Authentication Exception: " + username, e); } finally { if (ocm != null) { ocm.logout(); } } return null; }