Example usage for org.springframework.security.authentication BadCredentialsException BadCredentialsException

List of usage examples for org.springframework.security.authentication BadCredentialsException BadCredentialsException

Introduction

In this page you can find the example usage for org.springframework.security.authentication BadCredentialsException BadCredentialsException.

Prototype

public BadCredentialsException(String msg, Throwable t) 

Source Link

Document

Constructs a BadCredentialsException with the specified message and root cause.

Usage

From source file:org.ngrinder.security.DefaultLoginPlugin.java

@SuppressWarnings("deprecation")
@Override/*ww  w  . j av  a 2 s  .  co  m*/
public boolean validateUser(String userId, String password, String encPass, Object encoder, Object salt) {
    if (StringUtils.isEmpty(password)
            || !((PasswordEncoder) encoder).isPasswordValid(encPass, password, salt)) {
        LOG.debug("Authentication failed: password does not match stored value");

        throw new BadCredentialsException(messages.getMessage(
                "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), userId);
    }
    return true;
}

From source file:com.launchkey.example.springmvc.LaunchKeyAuthenticationProvider.java

@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    String username = authentication.getName();

    try {/*from   w ww .jav  a  2 s  .  com*/
        this.authManager.login(username);
        Boolean authorized = null;
        while (authorized == null) {
            Thread.sleep(100L);
            authorized = this.authManager.isAuthorized();
        }
        if (authorized == null) {
            throw new InsufficientAuthenticationException(
                    "The authentication request was not responded to in sufficient time");
        } else if (!authorized) {
            throw new InsufficientAuthenticationException("The authentication request was denied");
        }
    } catch (InterruptedException e) {
        throw new AuthenticationServiceException("Sleep error");
    } catch (AuthManager.AuthException e) {
        if (e.getCause() instanceof LaunchKeyException) {
            throw new BadCredentialsException("Authentication failure", e.getCause());
        }
    }

    return new UsernamePasswordAuthenticationToken(username, authentication.getCredentials(),
            new ArrayList<GrantedAuthority>());
}

From source file:shiver.me.timbers.spring.security.StormpathAuthenticationProvider.java

@Override
protected UserDetails retrieveUser(String username, UsernamePasswordAuthenticationToken authentication)
        throws AuthenticationException {
    try {/*  w  w w. j  a  v a  2s. c o  m*/
        return converter.create(application.authenticateAccount(requests.create(username, authentication)));
    } catch (ResourceException e) {
        throw new BadCredentialsException("Invalid credentials for " + username, e);
    }
}

From source file:com.sitewhere.security.SitewhereAuthenticationProvider.java

public Authentication authenticate(Authentication input) throws AuthenticationException {
    try {// w  ww  . j  a va  2 s  . co  m
        if (input instanceof UsernamePasswordAuthenticationToken) {
            String username = (String) input.getPrincipal();
            String password = (String) input.getCredentials();
            IUser user = SiteWhereServer.getInstance().getUserManagement().authenticate(username, password);
            List<IGrantedAuthority> auths = SiteWhereServer.getInstance().getUserManagement()
                    .getGrantedAuthorities(user.getUsername());
            SitewhereUserDetails details = new SitewhereUserDetails(user, auths);
            return new SitewhereAuthentication(details, password);
        } else if (input instanceof SitewhereAuthentication) {
            return input;
        } else {
            throw new AuthenticationServiceException("Unknown authentication: " + input.getClass().getName());
        }
    } catch (SiteWhereException e) {
        throw new BadCredentialsException("Unable to authenticate.", e);
    }
}

From source file:com.springsource.greenhouse.account.UsernamePasswordAuthenticationProvider.java

public Authentication authenticate(Authentication authentication) throws AuthenticationException {
    UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
    try {//from   w  w  w .  j  a va2 s . c  om
        Account account = accountRepository.authenticate(token.getName(), (String) token.getCredentials());
        return authenticatedToken(account, authentication);
    } catch (SignInNotFoundException e) {
        throw new org.springframework.security.core.userdetails.UsernameNotFoundException(token.getName(), e);
    } catch (InvalidPasswordException e) {
        throw new BadCredentialsException("Invalid password", e);
    }
}

From source file:at.ac.univie.isc.asio.security.DelegationDetailsSource.java

private Identity findDelegatedCredentials(final HttpServletRequest request) {
    try {/*w w  w  .  j  a  v a  2  s  .  co m*/
        final String header = request.getHeader(delegatedCredentialsHeader);
        return Objects.firstNonNull(parser.convert(header), Identity.undefined());
    } catch (final InvalidUsage malformedCredentials) {
        throw new BadCredentialsException(
                "illegal delegated credentials in '" + delegatedCredentialsHeader + "' header",
                malformedCredentials);
    }
}

From source file:miage.ecom.web.security.AdminAuthenticationProvider.java

@Override
protected void additionalAuthenticationChecks(UserDetails ud,
        UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {

    if (authentication.getCredentials() == null) {
        logger.debug("Authentication failed: no credentials provided");

        throw new BadCredentialsException(messages.getMessage(
                "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), null);
    }//from  ww  w. j av a 2  s.  c  o m

    String presentedPassword = authentication.getCredentials().toString();

    if (adminFacade.authenticate(ud.getUsername(), presentedPassword) == null) {
        logger.debug("Authentication failed: password does not match stored value");

        throw new BadCredentialsException(messages.getMessage(
                "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), null);
    }

}

From source file:miage.ecom.web.security.UserAuthenticationProvider.java

@Override
protected void additionalAuthenticationChecks(UserDetails ud,
        UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {

    if (authentication.getCredentials() == null) {
        logger.debug("Authentication failed: no credentials provided");

        throw new BadCredentialsException(messages.getMessage(
                "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), null);
    }//from   w  w  w.  ja  v a 2  s  .  com

    String presentedPassword = authentication.getCredentials().toString();

    if (customerFacade.authenticate(ud.getUsername(), presentedPassword) == null) {
        logger.debug("Authentication failed: password does not match stored value");

        throw new BadCredentialsException(messages.getMessage(
                "AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"), null);
    }

}

From source file:com.yuchengtech.mobile.console.service.security.DaoAuthenticationProvider.java

protected void additionalAuthenticationChecks(UserDetails userDetails,
        UsernamePasswordAuthenticationToken authentication) throws AuthenticationException {
    Object salt = null;/*  w w w.j a va2s . co m*/

    if (this.saltSource != null) {
        salt = this.saltSource.getSalt(userDetails);
    }

    if (authentication.getCredentials() == null) {
        throw new BadCredentialsException(messages
                .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"),
                includeDetailsObject ? userDetails : null);
    }

    String presentedPassword = authentication.getCredentials().toString();
    //        if (!isBobEmpNo(userDetails.getUsername())) {
    if (!passwordEncoder.isPasswordValid(userDetails.getPassword(), presentedPassword, salt)) {
        throw new BadCredentialsException(messages
                .getMessage("AbstractUserDetailsAuthenticationProvider.badCredentials", "Bad credentials"),
                includeDetailsObject ? userDetails : null);
    }
    //      }
}

From source file:cn.com.fubon.springboot.starter.jwt.auth.JwtTokenServiceImpl.java

@Override
public Authentication parseJwtToken(String jwtToken) throws AuthenticationException {
    try {/*  www  . ja va2s  . c  o m*/
        Claims claims = Jwts.parser().setSigningKey(secretkey).parseClaimsJws(jwtToken).getBody();

        return JwtAuthenticationToken.of(claims);
    } catch (ExpiredJwtException | SignatureException e) {
        throw new BadCredentialsException(e.getMessage(), e);
    } catch (UnsupportedJwtException | MalformedJwtException e) {
        throw new AuthenticationServiceException(e.getMessage(), e);
    } catch (IllegalArgumentException e) {
        throw new InternalAuthenticationServiceException(e.getMessage(), e);
    }
}