List of usage examples for org.springframework.security.core Authentication getName
public String getName();
From source file:cz.muni.pa165.carparkapp.configuration.MyAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = authentication.getName(); String password = (String) authentication.getCredentials(); password = DigestUtils.shaHex(password); Employee user = null;/*from ww w . j av a 2 s . co m*/ for (Employee e : dao.getAllEmployees()) { //System.out.println(e); if (e.getUserName().equals(username)) { user = e; break; } } if (user == null) { throw new BadCredentialsException("Username not found."); } if (!password.equals(user.getPassword())) { throw new BadCredentialsException("Wrong password."); } List<GrantedAuthority> authorities = new ArrayList<>(); authorities.add(new SimpleGrantedAuthority("ROLE_" + user.getRole())); return new UsernamePasswordAuthenticationToken(username, password, authorities); }
From source file:mb.MbKonsultacije.java
public void dodajKonsultacije(Konsultacije k) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); k.setProfesorId((Profesor) mbKorisnik.nadjiPoMailu(auth.getName())); sBKonsultacijeLocal.dodajKonsultacije(k); }
From source file:org.modeshape.example.springsecurity.jcr.security.SpringSecurityProvider.java
@Override public ExecutionContext authenticate(Credentials credentials, String repositoryName, String workspaceName, ExecutionContext repositoryContext, Map<String, Object> sessionAttributes) { if (credentials instanceof SpringSecurityCredentials) { SpringSecurityCredentials creds = (SpringSecurityCredentials) credentials; Authentication auth = creds.getAuth(); if (auth != null) { logger.info("[{}] Successfully authenticated.", auth.getName()); return repositoryContext.with(new SpringSecurityContext(auth)); }/*from w ww .ja va 2s. c om*/ } return null; }
From source file:com.cami.web.controller.LeController.java
@RequestMapping(value = "/welcome**", method = RequestMethod.GET) public ModelAndView welcomePage() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); //get logged in username final Role user = roleService.retrieveAUser(name); final Role userConnected = roleService.retrieveAUser(name); ModelAndView model = new ModelAndView(); model.addObject("user", user); model.addObject("userConnected", userConnected); model.setViewName("hello"); return model; }
From source file:cz.muni.pa165.carparkapp.web.LoansController.java
@RequestMapping(method = RequestMethod.GET) public String getEmployee(Model model) { log.debug("getListOfLoans()"); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); EmployeeDTO emp = null;/*from w w w . j a v a2 s .c om*/ for (EmployeeDTO employee : employeeService.getAllEmployees()) { if (employee.getUserName().equals(name)) emp = employee; } List<LoanDTO> list = loanService.getLoansByEmployee(emp); model.addAttribute("loans", list); return "loans"; }
From source file:com.github.cherimojava.orchidae.security.MongoAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { LOG.info(AUTH, "login attempt for user {}", authentication.getName()); UserDetails details = userDetailsService.loadUserByUsername((String) authentication.getPrincipal()); if (details == null || !pwEncoder.matches((String) authentication.getCredentials(), details.getPassword())) { LOG.info(AUTH, "failed to authenticate user {}", authentication.getName()); throw new BadCredentialsException(ERROR_MSG); }//from w ww .ja v a2s.co m LOG.info(AUTH, "login attempt for user {}", authentication.getName()); return new UsernamePasswordAuthenticationToken(authentication.getPrincipal(), authentication.getCredentials(), details.getAuthorities()); }
From source file:org.chtijbug.drools.platform.web.security.Http200AuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { response.setStatus(HttpServletResponse.SC_OK); response.getWriter().write(authentication.getName()); }
From source file:psiprobe.controllers.deploy.DeployContextController.java
@Override public ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { String contextName = ServletRequestUtils.getStringParameter(request, "context", null); if (contextName != null) { try {//from w w w.j av a 2 s . com if (getContainerWrapper().getTomcatContainer().installContext(contextName)) { request.setAttribute("successMessage", getMessageSourceAccessor() .getMessage("probe.src.deploy.context.success", new Object[] { contextName })); // Logging action Authentication auth = SecurityContextHolder.getContext().getAuthentication(); String name = auth.getName(); // get username logger logger.info(getMessageSourceAccessor().getMessage("probe.src.log.deploycontext"), name, contextName); } else { request.setAttribute("errorMessage", getMessageSourceAccessor() .getMessage("probe.src.deploy.context.failure", new Object[] { contextName })); } } catch (Exception e) { request.setAttribute("errorMessage", e.getMessage()); logger.trace("", e); } } return new ModelAndView(new InternalResourceView(getViewName())); }
From source file:shiver.me.timbers.security.web.advanced.spring.UserAuthenticationConverterTest.java
@Test public void Can_create_a_principal() { final String principal = someString(); final Authentication authentication = mock(Authentication.class); // Given/*w w w . ja v a2 s . c o m*/ given(authentication.getName()).willReturn(principal); // When final String actual = new UserAuthenticationConverter(mock(UserRepository.class)).convert(authentication); // Then assertThat(actual, equalTo(principal)); }
From source file:de.blizzy.documentr.web.account.AccountController.java
@RequestMapping(value = "/removeOpenId", method = RequestMethod.GET) @PreAuthorize("isAuthenticated()") public String removeOpenId(@RequestParam String openId, Authentication authentication) throws IOException { String loginName = authentication.getName(); User user = userStore.getUser(loginName); user.removeOpenId(openId);//from ww w .jav a2 s . c o m userStore.saveUser(user, user); return "redirect:/account/openId"; //$NON-NLS-1$ }