List of usage examples for org.springframework.security.authentication DisabledException DisabledException
public DisabledException(String msg)
DisabledException
with the specified message. From source file:net.triptech.buildulator.service.OpenIdUserDetailsService.java
/** * Implementation of {@code UserDetailsService}. We only need this to * satisfy the {@code RememberMeServices} requirements. *///w w w . ja v a2 s .c o m public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { Person person = Person.findByOpenIdIdentifier(id); if (person == null) { throw new UsernameNotFoundException(id); } if (!person.isEnabled()) { throw new DisabledException("This user is disabled"); } return person; }
From source file:net.triptech.metahive.service.OpenIdUserDetailsService.java
/** * Implementation of {@code UserDetailsService}. We only need this to * satisfy the {@code RememberMeServices} requirements. *///from ww w. j a v a 2 s . c o m public UserDetails loadUserByUsername(String id) throws UsernameNotFoundException { List<Person> people = Person.findPeopleByOpenIdIdentifier(id).getResultList(); Person person = people.size() == 0 ? null : people.get(0); if (person == null) { throw new UsernameNotFoundException(id); } if (!person.isEnabled()) { throw new DisabledException("This user is disabled"); } return person; }
From source file:br.com.sicva.seguranca.ProvedorAutenticacao.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { String name = authentication.getName(); String password = authentication.getCredentials().toString(); UsuariosDao usuariosDao = new UsuariosDao(); Usuarios usuario = usuariosDao.PesquisarUsuario(name); if (usuario == null || !usuario.getUsuariosCpf().equalsIgnoreCase(name)) { throw new BadCredentialsException("Username not found."); }//from ww w .j a va 2 s . c om if (!GenerateMD5.generate(password).equals(usuario.getUsuarioSenha())) { throw new LockedException("Wrong password."); } if (!usuario.getUsuarioAtivo()) { throw new DisabledException("User is disable"); } List<GrantedAuthority> funcoes = new ArrayList<>(); funcoes.add(new SimpleGrantedAuthority("ROLE_" + usuario.getFuncao().getFuncaoDescricao())); Collection<? extends GrantedAuthority> authorities = funcoes; return new UsernamePasswordAuthenticationToken(name, password, authorities); }
From source file:grails.plugin.springsecurity.userdetails.DefaultPreAuthenticationChecks.java
public void check(UserDetails user) { if (!user.isAccountNonLocked()) { log.debug("User account is locked"); throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked", "User account is locked")); }/* w w w .j a v a 2s . c o m*/ if (!user.isEnabled()) { log.debug("User account is disabled"); throw new DisabledException( messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", "User is disabled")); } if (!user.isAccountNonExpired()) { log.debug("User account is expired"); throw new AccountExpiredException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.expired", "User account has expired")); } }
From source file:com.spfsolutions.ioms.auth.UserAuthenticationProvider.java
@Override public Authentication authenticate(Authentication authentication) throws AuthenticationException { try {//w ww. j av a2 s . c o m UserEntity userEntity = userDao.queryForFirst( userDao.queryBuilder().where().eq("Username", authentication.getName()).prepare()); String inputHash = MD5.encrypt(authentication.getCredentials().toString()); if (userEntity == null || !userEntity.getPassword().equals(inputHash)) { throw new BadCredentialsException("Username or password incorrect."); } else if (!userEntity.isEnabled()) { throw new DisabledException("The username is disabled. Please contact your System Administrator."); } userEntity.setLastSuccessfulLogon(new DateTime(DateTimeZone.UTC).toDate()); userDao.createOrUpdate(userEntity); Collection<SimpleGrantedAuthority> authorities = buildRolesFromUser(userEntity); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( authentication.getName(), authentication.getCredentials(), authorities); return token; } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { userDao.getConnectionSource().closeQuietly(); } return null; }
From source file:oauth2.authentication.DefaultUserAuthenticationStrategy.java
@Override public void authenticate(User user, Object credentials) { checkNotNull(user);// w w w.j a v a2 s . com String userId = user.getUserId(); if (!user.isEnabled()) { LOGGER.debug("User {} is disabled", userId); throw new DisabledException( messages.getMessage("AbstractUserDetailsAuthenticationProvider.disabled", "User is disabled")); } if (user.isAccountLocked()) { LOGGER.debug("User account {} is locked", userId); throw new LockedException(messages.getMessage("AbstractUserDetailsAuthenticationProvider.locked", "User account is locked")); } if (credentials == null) { LOGGER.debug("Authentication for user {} failed: No credentials provided", userId); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); } if (!passwordEncoder.matches(credentials.toString(), user.getPassword())) { LOGGER.debug("Authentication for user {} failed: Password does not match stored value", userId); throw new BadCredentialsException(messages .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials")); } }
From source file:cn.net.withub.demo.bootsec.hello.security.CustomAuthenticationProvider.java
@Transactional @Override/*from ww w. java 2 s . c o m*/ public Authentication authenticate(Authentication authentication) throws AuthenticationException { UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication; String username = token.getName(); //??? //? UserDetails userDetails = null; if (username != null) { userDetails = userDetailsService.loadUserByUsername(username); } if (userDetails == null) { return null;//null?? //throw new UsernameNotFoundException("??/?"); } else if (!userDetails.isEnabled()) { throw new DisabledException("?"); } else if (!userDetails.isAccountNonExpired()) { throw new AccountExpiredException("?"); } else if (!userDetails.isAccountNonLocked()) { throw new LockedException("??"); } else if (!userDetails.isCredentialsNonExpired()) { throw new LockedException("?"); } //?? String encPass = userDetails.getPassword(); //authentication?credentials if (!md5PasswordEncoder.isPasswordValid(encPass, token.getCredentials().toString(), null)) { throw new BadCredentialsException("Invalid username/password"); } //? return new UsernamePasswordAuthenticationToken(userDetails, encPass, userDetails.getAuthorities()); }
From source file:org.xaloon.wicket.security.spring.SpringUserDetailsService.java
private UserDetails createAdaptor(org.xaloon.core.api.security.model.UserDetails userDetails) { if (!userDetails.isEnabled()) { throw new DisabledException(SecurityFacade.ACCOUNT_DISABLED); }/*from w w w . j ava 2 s. c o m*/ if (!userDetails.isAccountNonExpired()) { throw new AccountExpiredException(SecurityFacade.ACCOUNT_EXPIRED); } if (!userDetails.isAccountNonLocked()) { throw new LockedException(SecurityFacade.ACCOUNT_LOCKED); } if (!userDetails.isCredentialsNonExpired()) { throw new CredentialsExpiredException(SecurityFacade.CREDENTIALS_EXPIRED); } DefaultUserDetails details = new DefaultUserDetails(); details.setAccountNonExpired(userDetails.isAccountNonExpired()); details.setAccountNonLocked(userDetails.isAccountNonLocked()); details.setCredentialsNonExpired(userDetails.isCredentialsNonExpired()); details.setEnabled(userDetails.isEnabled()); details.setPassword(userDetails.getPassword()); details.setUsername(userDetails.getUsername()); List<Authority> authorities = loginService.getIndirectAuthoritiesForUsername(userDetails.getUsername()); if (!authorities.isEmpty()) { createAdaptorForAuthorities(details, authorities); } if (!userDetails.getAliases().isEmpty()) { details.getAliases().addAll(userDetails.getAliases()); } return details; }
From source file:com.daimler.spm.b2bacceleratoraddon.security.B2BAcceleratorAuthenticationProvider.java
/** * @see de.hybris.platform.acceleratorstorefrontcommons.security.AbstractAcceleratorAuthenticationProvider#additionalAuthenticationChecks(org.springframework.security.core.userdetails.UserDetails, * org.springframework.security.authentication.AbstractAuthenticationToken) *//*from ww w.ja va2s. c om*/ @Override protected void additionalAuthenticationChecks(final UserDetails details, final AbstractAuthenticationToken authentication) throws AuthenticationException { super.additionalAuthenticationChecks(details, authentication); final UserModel userModel = getUserService().getUserForUID(StringUtils.lowerCase(details.getUsername())); final UserGroupModel b2bgroup = getUserService().getUserGroupForUID(B2BConstants.B2BGROUP); // Check if the customer is B2B type if (getUserService().isMemberOfGroup(userModel, b2bgroup)) { if (!getB2bUserGroupProvider().isUserAuthorized(details.getUsername())) { throw new InsufficientAuthenticationException( messages.getMessage("checkout.error.invalid.accountType", "You are not allowed to login")); } // if its a b2b user, check if it is active if (!getB2bUserGroupProvider().isUserEnabled(details.getUsername())) { throw new DisabledException("User " + details.getUsername() + " is disabled... " + messages.getMessage("text.company.manage.units.disabled")); } } }
From source file:com.rockagen.gnext.service.spring.security.extension.BasicUrlAuthenticationFailureHandler.java
/** * handle locked ?//from w w w. ja v a2s .c o m * * @param userId * @return */ protected AuthenticationException handlerLocked(String userId) { AuthUser user = authUserServ.load(userId); if (user.getErrorCount() >= 5) { Long dateTime = user.getStateTime().getTime(); // 1 DAY = 86 400 000 ms if (new Date().getTime() - dateTime < 86400000) { // Locked user if input 6 error password user.setEnabled(0); authUserServ.add(user); return new DisabledException(messages.getMessage("AccountStatusUserDetailsChecker.locked")); } } else { // error count ++ user.setErrorCount(user.getErrorCount() + 1); // state time user.setStateTime(new Date()); } int onlyCount = 6 - user.getErrorCount(); authUserServ.add(user); return new BadCredentialsException( messages.getMessage("AccountStatusUserDetailsChecker.onlyCount", new Object[] { onlyCount })); }