List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:com.sitewhere.web.rest.documentation.RestDocumentationGenerator.java
public static void main(String[] args) { if (args.length < 2) { throw new RuntimeException("Missing arguments needed to create REST documentation."); }// w w w . j a v a 2 s . c om System.out.println("Generating SiteWhere REST documentation..."); try { // Required since some internal operations require a user to be // logged in. try { SecurityContextHolder.getContext().setAuthentication(SiteWhereServer.getSystemAuthentication()); } catch (SiteWhereException e) { throw new RuntimeException("Unable to set system user.", e); } File resources = new File(args[0]); if (!resources.exists()) { throw new SiteWhereException("Unable to find REST documentation resources folder."); } List<ParsedController> controllers = parseControllers(resources); generateRestDocumentation(controllers, resources, args[1]); } catch (SiteWhereException e) { System.err.println("Unable to generate SiteWhere REST documentation."); e.printStackTrace(System.err); } System.out.println("Finished generating SiteWhere REST documentation..."); }
From source file:org.tjm.user.security.SecurityUtil.java
public static UserDetails getUserDetails() { Object object = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (object instanceof UserDetails) { return (UserDetails) object; } else {//from ww w . j a va2 s .c o m return null; } }
From source file:quanlyhocvu.api.web.util.Tools.java
public static String getCurrentUser() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null) { return auth.getName(); }/*from w ww . j a v a 2s. c o m*/ return null; }
From source file:quanlyhocvu.api.web.util.Utils.java
/** * Get current user id//from w ww .ja v a 2s .co m * @param mongoService * @return */ public static String getCurrentUserId(MongoService mongoService) { String username = SecurityContextHolder.getContext().getAuthentication().getName(); return mongoService.loadUserByUserName(username).getUserId(); }
From source file:br.com.jreader.util.security.Session.java
public static String getUserSession() { SecurityContext context = SecurityContextHolder.getContext(); if (context instanceof SecurityContext) { Authentication authentication = context.getAuthentication(); if (authentication instanceof Authentication) { return authentication.getName(); }/*from ww w . j ava 2s. c o m*/ } return null; }
From source file:co.com.soinsoftware.altablero.utils.AuthenticationUtils.java
public static boolean isAnonymusAuthentication() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); return auth instanceof AnonymousAuthenticationToken; }
From source file:x1.markdown.security.SecurityUtils.java
public static String getCurrentLogin() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); String userName = null;/*w ww . j a v a 2s . c om*/ if (authentication != null) { if (authentication.getPrincipal() instanceof UserDetails) { UserDetails springSecurityUser = (UserDetails) authentication.getPrincipal(); userName = springSecurityUser.getUsername(); } else if (authentication.getPrincipal() instanceof String) { userName = (String) authentication.getPrincipal(); } } return userName; }
From source file:com.pamarin.income.security.SecurityUtils.java
public static User getUser() { SecurityContext securityContext = SecurityContextHolder.getContext(); Authentication authentication = securityContext.getAuthentication(); User user = null;//w w w . j a v a 2s . c o m if (authentication != null) { Object principal = authentication.getPrincipal(); if (principal instanceof User) { user = (User) principal; } else { user = new User(ANONYMOUS, null); } } return user; }
From source file:co.com.soinsoftware.altablero.utils.AuthenticationUtils.java
public static String getDocumentNumberFromAuthentication() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); return auth.getName(); }
From source file:net.kamhon.ieagle.security.SecurityUtil.java
public static UserDetails getLoginUser() { return (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); }