Example usage for org.springframework.security.authentication ProviderNotFoundException getMessage

List of usage examples for org.springframework.security.authentication ProviderNotFoundException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.bac.accountserviceapp.AccountServiceApp.java

@Override
public Authentication login(AbstractAuthenticationToken authentication) {

    Objects.requireNonNull(authenticationManager, noAuthManagerMsg);
    Objects.requireNonNull(authentication, noAuthenticationMsg);

    try {//from  w w w.  j  a  v  a  2 s  .  c  o m
        authentication = (AbstractAuthenticationToken) authenticationManager.authenticate(authentication);
    } catch (ProviderNotFoundException e) {
        logger.warn("No authentication provider available for principal: '{}'", authentication.getPrincipal());
        authentication.setDetails(NO_PROVIDER);
        return authentication;
    } catch (BadCredentialsException | IllegalArgumentException e) {
        logger.warn("Unable to authenticate for principal: '{}'", authentication.getPrincipal());
        authentication.setDetails(BAD_CREDENTIALS);
        return authentication;
    } catch (UsernameNotFoundException e) {
        logger.warn("Unable to authenticate for principal: '{}'", e.getMessage());
        authentication.setDetails(UNKNOWN_PRINCIPAL);
        return authentication;
    } catch (DisabledException e) {
        logger.warn("Principal is disabled: '{}'", authentication.getPrincipal());
        authentication.setDetails(DISABLED_PRINCIPAL);
        return authentication;
    }
    authentication.setDetails(AUTHENTICATED);
    return authentication;
}