List of usage examples for org.springframework.security.core.userdetails User getPassword
public String getPassword()
From source file:org.carewebframework.security.spring.AbstractAuthenticationProvider.java
/** * Authentication Provider. Produces a trusted <code>UsernamePasswordAuthenticationToken</code> * if// w ww . j a v a2s. com * * @param authentication The authentication context. * @return authentication Authentication object if authentication succeeded. Null if not. */ @Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { CWFAuthenticationDetails details = (CWFAuthenticationDetails) authentication.getDetails(); String username = (String) authentication.getPrincipal(); String password = (String) authentication.getCredentials(); String domain = null; if (log.isDebugEnabled()) { log.debug("User: " + username); log.debug("Details, RA: " + details == null ? "null" : details.getRemoteAddress()); } if (username != null) { String pcs[] = username.split("\\\\", 2); domain = pcs[0]; username = pcs.length > 1 ? pcs[1] : null; } ISecurityDomain securityDomain = domain == null ? null : SecurityUtil.getSecurityService().getSecurityDomain(domain); if (username == null || password == null || securityDomain == null) { throw new BadCredentialsException("Missing security credentials."); } IUser user = authenticate(username, password, securityDomain, details); details.setDetail("user", user); List<GrantedAuthority> userAuthorities = new ArrayList<GrantedAuthority>(); List<String> list = getAuthorities(user); Set<String> authorities = list == null ? new HashSet<String>() : new HashSet<String>(list); for (String grantedAuthority : grantedAuthorities) { if (grantedAuthority.startsWith("-")) { authorities.remove(grantedAuthority.substring(1)); } else { authorities.add(grantedAuthority); } } for (String authority : authorities) { if (!authority.isEmpty()) { userAuthorities.add(new SimpleGrantedAuthority(authority)); } } User principal = new User(username, password, true, true, true, true, userAuthorities); authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities()); ((UsernamePasswordAuthenticationToken) authentication).setDetails(details); return authentication; }
From source file:fr.mycellar.interfaces.web.security.MyCellarAuthenticationProvider.java
@Override protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication) throws AuthenticationException { if (StringUtils.isBlank(username)) { throw new UsernameNotFoundException("Username is empty."); }/* w w w . j a v a 2 s . c o m*/ logger.debug("Security verification for username '{}'.", username); fr.mycellar.domain.user.User user = userServiceFacade.getUserByEmail(username); if (user == null) { throw new UsernameNotFoundException("Username '" + username + "' not found."); } return new User(user.getEmail(), user.getPassword(), getAuthoritiesFromProfile(user.getProfile())); }
From source file:org.starfishrespect.myconsumption.server.business.security.AuthConfig.java
@Bean UserDetailsService userDetailsService() { return new UserDetailsService() { @Override/*from w w w . j a v a 2 s .com*/ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { org.starfishrespect.myconsumption.server.business.entities.User account = mUserRepository .getUser(username); if (account != null) { List<GrantedAuthority> auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER"); return new User(account.getName(), account.getPassword(), auth); } else { throw new UsernameNotFoundException("could not find the user '" + username + "'"); } } }; }
From source file:com.github.fedorchuck.webstore.accountservice.AccountDetailsServiceImpl.java
@Override @SuppressWarnings("unchecked") public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { com.github.fedorchuck.webstore.domainmodels.User user = userRepository.findByUsername(email); Set<GrantedAuthority> roles = new HashSet(); roles.add(new SimpleGrantedAuthority(UserRoleEnum.USER.name()));//TODO: userRepository.getRole() //TODO: what if null (account is undefined) UserDetails userDetails = new User(user.getUsername(), user.getPassword(), roles); return userDetails; }
From source file:org.parancoe.plugins.securityevolution.ParancoeUserDetailsService.java
@Override public UserDetails loadUserByUsername(java.lang.String username) throws UsernameNotFoundException, DataAccessException { org.parancoe.plugins.securityevolution.User user = userDao.findByUsername(username); if (user == null) throw new UsernameNotFoundException("username " + username + " not found in the system"); List<Authority> authorities = authorityDao.findAllAuthoritiesAssociatedToUsername(username); return new User(user.getUsername(), user.getPassword(), user.isEnabled(), true, true, !user.isLocked(), authorities2GrantedAuthorities(authorities)); }
From source file:org.ff4j.console.auth.UserAuthenticationService.java
/** {@inheritDoc} */ @Override/*from www .j a v a2 s . c om*/ public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { log.info("Authenticating user <" + username + ">"); List<GrantedAuthority> listOfRoles = new ArrayList<GrantedAuthority>(); if (xmlParser.getConf().getMapOfUser().containsKey(username)) { org.ff4j.console.conf.xml.User xmlUser = xmlParser.getConf().getMapOfUser().get(username); // if flag as admin if (xmlUser.isAdmin()) { listOfRoles.add(new SimpleGrantedAuthority(ROLE_ADMIN)); } listOfRoles.add(new SimpleGrantedAuthority(ROLE_USER)); return new User(username, xmlUser.getPassword(), listOfRoles); } // invalid user return new User("ko", "ko", listOfRoles); }
From source file:com.gsr.myschool.server.security.StatelessUserDetailService.java
@Override public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { com.gsr.myschool.server.business.User user = userRepos.findByEmail(email); if (user == null) { throw new UsernameNotFoundException("Bad credentials"); } else {//from w w w . j av a 2 s . co m List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new SimpleGrantedAuthority(user.getAuthority().name())); return new User(user.getEmail(), user.getPassword(), user.getStatus() == UserStatus.ACTIVE, true, true, true, authorities); } }
From source file:tr.edu.gsu.peralab.mobilesensing.web.service.CustomUserDetailsService.java
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { tr.edu.gsu.peralab.mobilesensing.web.entity.User domainUser = userDao.retrieveUser(username); User user = null;//from w ww .j a v a 2s .c o m boolean enabled = true; boolean accountNonExpired = true; boolean credentialsNonExpired = true; boolean accountNonLocked = true; if (domainUser != null) { user = new User(domainUser.getUserName(), domainUser.getPassword().toLowerCase(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, getAuthorities(domainUser.getRights())); } return user; }
From source file:net.przemkovv.sphinx.service.CustomUserDetailsService.java
@Override public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { net.przemkovv.sphinx.model.User domainUser = userService.getUser(email); if (domainUser == null) { throw new UsernameNotFoundException(email); }/*from www.jav a 2 s. c om*/ boolean enabled = true; boolean accountNonExpired = true; boolean credentialsNonExpired = true; boolean accountNonLocked = true; return new User(domainUser.getEmail(), domainUser.getPassword(), enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, getAuthorities(domainUser)); }
From source file:com.example.server.user.CustomUserDetailsService.java
@Override public UserDetails loadUserByUsername(String string) throws UsernameNotFoundException { User user = dao.findByUserName(string); if (user == null) { throw new UsernameNotFoundException("user with name " + string + " not found"); }//ww w . ja v a2 s . c o m GrantedAuthority authority = new SimpleGrantedAuthority(user.getRole()); List<GrantedAuthority> list = new ArrayList<>(); list.add(authority); return new org.springframework.security.core.userdetails.User(user.getUsername(), user.getPassword(), list); }