List of usage examples for org.springframework.security.authentication LockedException LockedException
public LockedException(String msg)
LockedException
with the specified message. 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."); }// ww w. j a v a 2 s . co m 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")); }// ww w. jav a 2 s . co 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:oauth2.authentication.DefaultUserAuthenticationStrategy.java
@Override public void authenticate(User user, Object credentials) { checkNotNull(user);/*from w ww . j av a 2s . c o m*/ 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:com.ctc.storefront.security.AcceleratorAuthenticationProvider.java
/** * @see de.hybris.platform.acceleratorstorefrontcommons.security.AbstractAcceleratorAuthenticationProvider#additionalAuthenticationChecks(org.springframework.security.core.userdetails.UserDetails, * org.springframework.security.authentication.AbstractAuthenticationToken) *//*from w w w. j a v a2 s .com*/ @Override protected void additionalAuthenticationChecks(final UserDetails details, final AbstractAuthenticationToken authentication) throws AuthenticationException { super.additionalAuthenticationChecks(details, authentication); // Check if the user is in role admingroup if (getAdminAuthority() != null && details.getAuthorities().contains(getAdminAuthority())) { throw new LockedException("Login attempt as " + Constants.USER.ADMIN_USERGROUP + " is rejected"); } }
From source file:cn.net.withub.demo.bootsec.hello.security.CustomAuthenticationProvider.java
@Transactional @Override/*from w w w .j av a 2 s .co 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 ww w. j a v a2 s . co 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.erudika.para.security.PasswordAuthFilter.java
/** * Handles an authentication request./* w w w .ja v a 2s .c o m*/ * @param request HTTP request * @param response HTTP response * @return an authentication object that contains the principal object if successful. * @throws IOException ex * @throws ServletException ex */ @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String requestURI = request.getRequestURI(); Authentication userAuth = null; User user = new User(); if (requestURI.endsWith(PASSWORD_ACTION)) { user.setIdentifier(request.getParameter(EMAIL)); user.setPassword(request.getParameter(PASSWORD)); if (User.passwordMatches(user) && StringUtils.contains(user.getIdentifier(), "@")) { //success! user = User.readUserForIdentifier(user); userAuth = new UserAuthentication(new AuthenticatedUserDetails(user)); } } if (userAuth == null || user == null || user.getIdentifier() == null) { throw new BadCredentialsException("Bad credentials."); } else if (!user.getActive()) { throw new LockedException("Account is locked."); // } else { // SecurityUtils.setAuthCookie(user, request, response); } return userAuth; }
From source file:com.erudika.para.security.OpenIDAuthFilter.java
/** * Handles an authentication request.//from w w w . java2 s . c o m * @param request HTTP request * @param response HTTP response * @return an authentication object that contains the principal object if successful. * @throws IOException ex */ @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws IOException { final String requestURI = request.getRequestURI(); Authentication userAuth = null; User user = null; if (requestURI.endsWith(OPENID_ACTION)) { Authentication oidAuth = super.attemptAuthentication(request, response); if (oidAuth == null) { // hang on... redirecting to openid provider return null; } else { //success! user = (User) oidAuth.getPrincipal(); userAuth = new UserAuthentication(user); } } if (userAuth == null || user == null || user.getIdentifier() == null) { throw new BadCredentialsException("Bad credentials."); } else if (!user.isEnabled()) { throw new LockedException("Account is locked."); } return userAuth; }
From source file:com.epam.training.storefront.security.AcceleratorAuthenticationProvider.java
@Override public Authentication authenticate(final Authentication authentication) throws AuthenticationException { final String username = (authentication.getPrincipal() == null) ? "NONE_PROVIDED" : authentication.getName();/* w w w. j a v a 2 s . c o m*/ CustomerModel userModel = null; try { userModel = (CustomerModel) getUserService().getUserForUID(StringUtils.lowerCase(username)); } catch (final UnknownIdentifierException e) { LOG.warn("Brute force attack attempt for non existing user name " + username); } if (userModel == null) { throw new BadCredentialsException("Bad credentials"); } if (getBruteForceAttackCounter().isAttack(username)) { userModel.setLoginDisabled(true); userModel.setStatus(Boolean.TRUE); userModel.setAttemptCount(0); getModelService().save(userModel); bruteForceAttackCounter.resetUserCounter(userModel.getUid()); throw new LockedException("Locked account"); } else { userModel.setAttemptCount(bruteForceAttackCounter.getUserFailedLogins(username)); getModelService().save(userModel); } return super.authenticate(authentication); }