List of usage examples for org.springframework.security.core.userdetails User User
public User(String username, String password, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities)
User
with the details required by org.springframework.security.authentication.dao.DaoAuthenticationProvider . From source file:org.apigw.authserver.x509.CertifiedClientAuthenticationUserDetailsService.java
@Override public UserDetails loadUserDetails(PreAuthenticatedAuthenticationToken token) throws AuthenticationException { if (token.getName() == null) { throw new UsernameNotFoundException("Username null not found"); }//from w ww. j a v a2 s.co m final X509ClientPrincipal principal = (X509ClientPrincipal) token.getPrincipal(); CertifiedClient clientDetails = clientDetailsService.loadClientByX509Cert(principal.getIssuerDN(), principal.getSubjectDN()); boolean expired = hasExpired(clientDetails); boolean enabled = !expired; return new User(clientDetails.getClientId(), "N/A", enabled, !expired, true, !clientDetails.isLocked(), clientDetails.getAuthorities()); }
From source file:ar.com.zauber.commons.auth.acegi.ChangePasswordAdvice.java
/** * @param username username//from ww w.j a v a 2 s . c o m * @param password password */ public final void changePassword(final String username, final String password) { Validate.notNull(username, "username"); Validate.notNull(password, "password"); final UserDetails user = dao.loadUserByUsername(username); dao.getUserMap() .addUser(new User(user.getUsername(), password, user.isEnabled(), user.isAccountNonExpired(), user.isCredentialsNonExpired(), user.isAccountNonLocked(), user.getAuthorities())); }
From source file:com.ushahidi.swiftriver.core.api.controller.AbstractControllerTest.java
protected Authentication getAuthentication(String username) { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); authorities.add(new SimpleGrantedAuthority("user")); User user = new User(username, "password", true, false, false, false, authorities); Authentication authentication = new UsernamePasswordAuthenticationToken(user, null); SecurityContextHolder.getContext().setAuthentication(authentication); return authentication; }
From source file:eionet.transfer.dao.UserManagementServiceJdbc.java
@Override public List<UserDetails> getAllUsers() { return getJdbcTemplate().query(DEF_GET_ALL_USERS_SQL, new String[] {}, new RowMapper<UserDetails>() { public UserDetails mapRow(ResultSet rs, int rowNum) throws SQLException { String username = rs.getString(1); String password = rs.getString(2); boolean enabled = rs.getBoolean(3); return new User(username, password, enabled, true, true, true, loadUserAuthorities(username)); }//w ww .j av a 2s .c o m }); }
From source file:org.appverse.web.framework.backend.api.helpers.security.PreAuthUserDetailsService.java
@SuppressWarnings("unchecked") @Override/*www . j a v a 2 s .c om*/ public UserDetails loadUserDetails(Authentication token) throws UsernameNotFoundException { String username = (String) token.getPrincipal(); List<String> externalAuthorities = null; if (token.getDetails() instanceof String) { externalAuthorities = new ArrayList<String>(); externalAuthorities.add((String) token.getDetails()); } else { externalAuthorities = (List<String>) token.getDetails(); } List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); for (String externalAuthority : externalAuthorities) { GrantedAuthority authority = new SimpleGrantedAuthority(externalAuthority); authorities.add(authority); } User user = new User(username, "", true, true, true, true, authorities); return user; }
From source file:com.blstream.patronage.ctf.security.PasswordEncoderService.java
/** * Prepares security user object based on portal user instance. * @param portalUser//w ww . j a v a 2 s .co m * @return User */ private User prepareUser(final PortalUser portalUser) { User user; if (logger.isDebugEnabled()) { logger.debug("---- prepareUser"); } user = new User(portalUser.getUsername(), portalUser.getPassword(), portalUser.isEnabled(), portalUser.isAccountNonExpired(), portalUser.isCredentialsNonExpired(), portalUser.isAccountNonLocked(), portalUser.getRoles()); if (logger.isInfoEnabled()) { logger.info(String.format( "Security user was prepared: " + "[username: %s, password: *************, isEnabled: %s, isAccountNonExpired: %s, " + "isCredentialsNonExpired: %s, isAccountNonLocked: %s, roles: %s]", user.getUsername(), user.isAccountNonExpired(), user.isCredentialsNonExpired(), user.isAccountNonExpired(), user.isAccountNonLocked(), user.getAuthorities())); } return user; }
From source file:com.climate.oada.security.saml.SAMLUserDetailsServiceImpl.java
@Override public Object loadUserBySAML(SAMLCredential credential) throws UsernameNotFoundException { List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(); String email = credential.getNameID().getValue(); GrantedAuthority authority = new SimpleGrantedAuthority("ROLE_USER"); authorities.add(authority);/* ww w . ja va 2 s . com*/ UserDetails userDetails = new User(email, "password", true, true, true, true, authorities); return userDetails; }
From source file:org.appverse.web.framework.backend.security.authentication.userpassword.managers.UserAndPasswordAuthenticationManagerImpl.java
/** * TODO: Review this method that can be used with PreAuthentication as the *//*from ww w . j a va2s . c om*/ @Override public void authenticatePrincipal(String principal, List<String> credentials) { List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>(); User user = new User(principal, "", true, true, true, true, authList); Authentication authentication = new PreAuthenticatedAuthenticationToken(user, credentials); authenticationManager.authenticate(authentication); }
From source file:com.ixortalk.aws.cognito.boot.mock.WithMockJwtUserSecurityContextFactory.java
@Override public SecurityContext createSecurityContext(WithMockJwtUser mockJwtUser) { String username = mockJwtUser.username(); if (username == null) { throw new IllegalArgumentException( mockJwtUser + " cannot have null username on both username and value properites"); }//from ww w. j a v a 2s. co m List<GrantedAuthority> grantedAuthorities = new ArrayList<GrantedAuthority>(); for (String role : mockJwtUser.roles()) { if (role.startsWith("ROLE_")) { throw new IllegalArgumentException("roles cannot start with ROLE_ Got " + role); } grantedAuthorities.add(new SimpleGrantedAuthority("ROLE_" + role)); } JWTClaimsSet.Builder builder = new JWTClaimsSet.Builder(); for (MockJwtClaim mockJwtClaim : mockJwtUser.mockJwtClaims()) { builder.claim(mockJwtClaim.key(), mockJwtClaim.value()); } JWTClaimsSet jwtClaimsSet = builder.build(); User principal = new User(username, "", true, true, true, true, grantedAuthorities); JwtAuthentication jwtAuthentication = new JwtAuthentication(principal, jwtClaimsSet, grantedAuthorities); SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(jwtAuthentication); return context; }
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. j a va2 s . co m 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)); }