List of usage examples for org.springframework.security.core.context SecurityContextHolder getContext
public static SecurityContext getContext()
SecurityContext
. From source file:org.duracloud.account.db.util.security.SecurityContextUtil.java
public Authentication getAuthentication() throws NoUserLoggedInException { SecurityContext context = SecurityContextHolder.getContext(); Authentication auth = context.getAuthentication(); if (null == auth) { log.debug("no user-auth found."); throw new NoUserLoggedInException(); }/* w w w . j ava 2 s . co m*/ return auth; }
From source file:ro.allevo.fintpws.security.RolesUtils.java
public static boolean hasAdministratorRole() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); UserEntity loggedUser = (UserEntity) authentication.getPrincipal(); List<RoleEntity> roles = (List<RoleEntity>) loggedUser.getAuthorities(); for (int roleIndex = 0; roleIndex < roles.size(); roleIndex++) { if (roles.get(roleIndex).getAuthority().equals("Administrator")) { return true; }//from w ww . j a va 2 s . c om } return false; }
From source file:org.moserp.common.security.SpringSecurityAuditorAware.java
public String getCurrentAuditor() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null || !authentication.isAuthenticated()) { return null; }/*from ww w . j a va 2s . c o m*/ if (authentication.getPrincipal() instanceof String) { return ((String) authentication.getPrincipal()); } if (authentication.getPrincipal() instanceof User) { return ((User) authentication.getPrincipal()).getUsername(); } return authentication.getPrincipal().toString(); }
From source file:com.rockagen.gnext.service.spring.security.aspect.SS3Tools.java
/** * Get remote address /*from ww w. ja v a2 s . c o m*/ * @return ip */ public static String getRemoteAddress() { String temp = "127.0.0.1"; try { temp = ((BasicWebAuthenticationDetails) SecurityContextHolder.getContext().getAuthentication() .getDetails()).getRemoteAddress(); } catch (Exception e) { // do not } return temp; }
From source file:br.com.joaops.smt.configuration.CurrentTenantIdentifierResolverImpl.java
@Override public String resolveCurrentTenantIdentifier() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); String database = "master"; //Nome do Banco de Dados Principal if (authentication != null && authentication.getPrincipal() instanceof SmtUserDetails) { SmtUserDetails user = (SmtUserDetails) authentication.getPrincipal(); database = user.getDatabaseName(); }//from w w w .ja v a2 s. c o m return database; }
From source file:org.zalando.stups.stupsback.admin.domain.ThumbsUpHandler.java
@HandleBeforeCreate public void handleCreate(ThumbsUp likes) { final Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { final Optional<Object> principal = Optional.ofNullable(authentication.getPrincipal()); likes.setUsername(principal.orElse(new String("testuser")).toString()); } else {//from ww w . j a va 2 s . c o m likes.setUsername("anonymous"); } }
From source file:com.trenako.web.security.SpringUserContext.java
@Override public AccountDetails getCurrentUser() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); // throw away anonymous tokens if (authentication instanceof AnonymousAuthenticationToken) { return null; }/*from w ww . j a v a 2s .com*/ return authentication == null ? null : (AccountDetails) authentication.getPrincipal(); }
From source file:hu.unideb.studentSupportInterface.backing.ManageProfile.java
@PostConstruct public void initBean() { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); user = (User) userDao.loadUserByUsername(auth.getName()); selectedLanguages = oldSelectedLanguages = languageDao.getLanguagesByUser(user); languages = languageDao.getAllLanguage(); }
From source file:oobbit.orm.Users.java
public User getCurrentUser() throws SQLException, NothingWasFoundException, NotLoggedInException { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth.getPrincipal().equals("anonymousUser")) { throw new NotLoggedInException("You are not logged in."); }//from w w w. j a v a 2 s . com return this.get((String) auth.getPrincipal()); }
From source file:com.cfs.backingbean.AlterarSenha.java
public void alterarSenha() { user = new Users(); UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal();/*from w w w .j a v a 2s.co m*/ user = usersDao.buscaUsuarioPorUSERNAME(userDetails.getUsername()); if (user == null) { System.out.println(Utilities.getInstance().getLineNumber() + "user null"); return; } if (!BCrypt.checkpw(senhaAtual, user.getPassword())) { JSFUtil.addErrorMessage("Senha atual incorreta."); return; } user.setPassword(HashSenha.hash(senhaNova)); try { usersDao.salvar(user); } catch (DAOException ex) { Logger.getLogger(AlterarSenha.class.getName()).log(Level.SEVERE, null, ex); JSFUtil.addErrorMessage("Erro senha no alterada."); } JSFUtil.addInfoMessage("Senha alterada com sucesso!"); limpar(); }