List of usage examples for org.springframework.security.core Authentication isAuthenticated
boolean isAuthenticated();
AuthenticationManager
. From source file:com.wiiyaya.framework.provider.utils.ConsumerUtils.java
private static Authentication getAuthentication() { SecurityContext context = SecurityContextHolder.getContext(); if (context == null) { return null; }/*from www .j av a2s . c o m*/ Authentication authentication = context.getAuthentication(); if (authentication == null || !authentication.isAuthenticated() || authentication instanceof AnonymousAuthenticationToken) { return null; } return authentication; }
From source file:com.erudika.para.security.SecurityUtils.java
/** * Extracts a User object from the security context * @return an authenticated user or null if a user is not authenticated */// ww w . j a v a 2 s.c om public static User getAuthenticatedUser() { User u = null; if (SecurityContextHolder.getContext().getAuthentication() != null) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth.isAuthenticated() && auth.getPrincipal() instanceof User) { u = (User) auth.getPrincipal(); } } return u; }
From source file:com.mothsoft.alexis.security.CurrentUserUtil.java
public static boolean isAuthenticated() { final Authentication auth = SecurityContextHolder.getContext().getAuthentication(); return auth != null && auth.isAuthenticated() && !"anonymousUser".equals(auth.getName()); }
From source file:edu.zipcloud.cloudstreetmarket.core.util.AuthenticationUtil.java
public static boolean userHasRole(Role role) { SecurityContext securityContext = SecurityContextHolder.getContext(); if (securityContext != null) { Authentication auth = securityContext.getAuthentication(); if (auth != null) { if (!auth.isAuthenticated()) { return false; }/* w ww . j av a 2 s .c o m*/ } } return UserDetailsUtil.hasRole(getPrincipal(), role); }
From source file:com.mothsoft.alexis.security.CurrentUserUtil.java
public static UserAuthenticationDetails getCurrentUser() { final SecurityContext ctx = SecurityContextHolder.getContext(); final Authentication authentication = ctx.getAuthentication(); try {/* w ww . j a va2 s. c o m*/ return authentication != null && authentication.isAuthenticated() ? (UserAuthenticationDetails) authentication.getPrincipal() : null; } catch (ClassCastException e) { throw new AuthenticationServiceException(e.getLocalizedMessage(), e); } }
From source file:org.meruvian.yama.web.SessionCredentials.java
public static User getCurrentUser() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { return null; }//from w ww . j a v a 2 s . c o m if (authentication.getPrincipal() instanceof DefaultUserDetails) { DefaultUserDetails user = (DefaultUserDetails) authentication.getPrincipal(); return user.getUser(); } if (authentication.getPrincipal() instanceof String) { String principal = (String) authentication.getPrincipal(); if ("anonymousUser".equals(principal)) { return null; } User user = new User(); user.setUsername((String) authentication.getPrincipal()); return user; } return null; }
From source file:org.red5.demo.auth.Application.java
public static boolean isAuthorized(String... roles) { // get the auth from the security context Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null && auth.isAuthenticated()) { UserDetails deets = (UserDetails) auth.getPrincipal(); log.debug("enabled: {}", deets.isEnabled()); Collection<GrantedAuthority> granted = deets.getAuthorities(); for (GrantedAuthority authority : granted) { if (Arrays.asList(roles).contains(authority.getAuthority())) { log.debug("Authorized"); return true; }//from w w w . j av a 2s .com } } log.debug("Not Authorized. User has not been granted any of: {}", roles); return false; }
From source file:ru.org.linux.auth.AuthUtil.java
public static void updateLastLogin(Authentication authentication, UserDao userDao) { if (authentication != null && (authentication.isAuthenticated())) { Object principal = authentication.getPrincipal(); if (principal instanceof UserDetailsImpl) { UserDetailsImpl userDetails = (UserDetailsImpl) principal; User user = userDetails.getUser(); userDao.updateLastlogin(user, true); }//from w ww.j a va2 s. com } }
From source file:nl.surfnet.coin.selfservice.util.SpringSecurity.java
/** * @return//from ww w.j av a 2 s .c o m */ public static boolean isFullyAuthenticated() { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && authentication.isAuthenticated() && authentication.getPrincipal() instanceof CoinUser; }
From source file:ru.org.linux.auth.AuthUtil.java
public static boolean isSessionAuthorized() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); return authentication != null && (authentication.isAuthenticated() && !hasAuthority("ROLE_SYSTEM_ANONYMOUS") && hasAuthority("ROLE_ANONYMOUS")); }