List of usage examples for org.springframework.security.core Authentication getPrincipal
Object getPrincipal();
From source file:com.github.carlomicieli.nerdmovies.security.SpringSecurityService.java
@Override public MailUserDetails getCurrentUser() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication == null ? null : (MailUserDetails) authentication.getPrincipal(); }
From source file:com.wonders.bud.freshmommy.service.sysuser.service.impl.LoginSuccessHandler.java
/** * <p>/*from w w w. j a v a2s .co m*/ * Description:[??] * </p> * * @param request * @param authentication */ @Transactional(readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = { Exception.class }) public void saveLoginInfo(HttpServletRequest request, Authentication authentication) { UserInfo user = (UserInfo) authentication.getPrincipal(); SysUserPO login = sysUserService.getById(user.getUid()); try { login.setLastLoginTime(new Date()); login.setLastLoginIp(getIpAddress(request)); sysUserService.update(login); } catch (DataAccessException e) { if (logger.isWarnEnabled()) { logger.info("??"); } } }
From source file:org.openmhealth.shim.AccessParameterClientTokenServices.java
@Override public void saveAccessToken(OAuth2ProtectedResourceDetails resource, Authentication authentication, OAuth2AccessToken accessToken) { String username = authentication.getPrincipal().toString(); String shimKey = authentication.getDetails().toString(); AccessParameters accessParameters = accessParametersRepo.findByUsernameAndShimKey(username, shimKey, new Sort(Sort.Direction.DESC, "dateCreated")); if (accessParameters == null) { accessParameters = new AccessParameters(); accessParameters.setUsername(username); accessParameters.setShimKey(shimKey); }//from w w w . ja v a2 s. c om accessParameters.setSerializedToken(SerializationUtils.serialize(accessToken)); accessParametersRepo.save(accessParameters); }
From source file:org.client.one.service.UserIdentityDetailsService.java
@Override public UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException { return (UserDetails) token.getPrincipal(); }
From source file:org.socialsignin.exfmproxy.mvc.workaround.auth.WorkaroundUsernamePasswordAuthenticationFilter.java
@Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { Authentication a = super.attemptAuthentication(request, response); String[] usernameAndPassword = ((User) a.getPrincipal()).getUsername().split(USERNAME_PASSWORD_DELIMITER); User user = new User(usernameAndPassword[0], usernameAndPassword[1], a.getAuthorities()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(user, usernameAndPassword[1], a.getAuthorities()); setDetails(request, authentication); return authentication; }
From source file:ar.com.zauber.commons.social.oauth.examples.services.ExampleAuthenticationSuccessHandler.java
/** * @see AuthenticationSuccessHandler#onAuthenticationSuccess(HttpServletRequest, * HttpServletResponse, Authentication) *///w ww.ja va2 s. co m @Override public final void onAuthenticationSuccess(final HttpServletRequest request, final HttpServletResponse response, final Authentication authentication) throws IOException, ServletException { ExampleUserDetails userDetails = (ExampleUserDetails) authentication.getPrincipal(); if (userDetails.getUsername() == null) { // logged in with twitter, but no username for this application response.sendRedirect("/api/welcome/"); } else { response.sendRedirect("/api/welcome/"); } }
From source file:org.wallride.web.support.AuthorizedUserMethodArgumentResolver.java
@Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); AuthorizedUser authorizedStaff = null; if (auth != null && auth.getPrincipal() instanceof AuthorizedUser) { authorizedStaff = (AuthorizedUser) auth.getPrincipal(); }//from w ww.ja v a 2 s.c o m return authorizedStaff; }
From source file:eu.supersede.fe.notification.NotificationUtil.java
private String getCurrentTenant() { String tenant = null;//from w ww .jav a 2s . c o m SecurityContext securityContext = SecurityContextHolder.getContext(); if (securityContext != null) { Authentication authentication = securityContext.getAuthentication(); if (authentication != null && authentication.getPrincipal() instanceof DatabaseUser) { DatabaseUser userDetails = (DatabaseUser) authentication.getPrincipal(); tenant = userDetails.getTenantId(); } } return tenant; }
From source file:eu.freme.broker.security.DatabaseAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String username = (String) authentication.getPrincipal(); String password = (String) authentication.getCredentials(); User user = userRepository.findOneByName(username); if (user == null) { throw new BadCredentialsException("authentication failed"); }/* ww w .j ava2 s .c o m*/ try { if (!PasswordHasher.check(password, user.getPassword())) { throw new BadCredentialsException("authentication failed"); } } catch (BadCredentialsException e) { throw e; } catch (Exception e) { logger.error(e); throw new InternalServerErrorException(); } Token token = tokenService.generateNewToken(user); AuthenticationWithToken auth = new AuthenticationWithToken(user, null, AuthorityUtils.commaSeparatedStringToAuthorityList(user.getRole()), token); return auth; }
From source file:org.obozek.minermonitor.config.SecurityContextHelperImpl.java
@Override public MinerUserDetails getUserDetails() { MinerUserDetails userDetails = null; SecurityContext sc = getSecurityContext(); Authentication auth = sc.getAuthentication(); if (!(auth instanceof AnonymousAuthenticationToken)) { userDetails = (MinerUserDetails) auth.getPrincipal(); }/*from w ww . j a va2 s .c om*/ return userDetails; }