Example usage for org.springframework.security.core.userdetails AuthenticationUserDetailsService loadUserDetails

List of usage examples for org.springframework.security.core.userdetails AuthenticationUserDetailsService loadUserDetails

Introduction

In this page you can find the example usage for org.springframework.security.core.userdetails AuthenticationUserDetailsService loadUserDetails.

Prototype

UserDetails loadUserDetails(T token) throws UsernameNotFoundException;

Source Link

Usage

From source file:se.kth.csc.config.MockAuthConfig.java

@Bean
@Autowired//from  ww w .j a v  a 2  s  .  co m
public AuthenticationProvider authenticationProvider(
        final AuthenticationUserDetailsService<Authentication> authenticationUserDetailsService) {
    return new AuthenticationProvider() {
        @Override
        public Authentication authenticate(final Authentication authentication) throws AuthenticationException {
            final UserDetails userDetails = authenticationUserDetailsService.loadUserDetails(authentication);
            return new Authentication() {
                @Override
                public Collection<? extends GrantedAuthority> getAuthorities() {
                    return userDetails.getAuthorities();
                }

                @Override
                public Object getCredentials() {
                    return authentication.getCredentials();
                }

                @Override
                public Object getDetails() {
                    return authentication.getDetails();
                }

                public UserDetails getUserDetails() {
                    return userDetails;
                }

                @Override
                public Object getPrincipal() {
                    return userDetails;
                }

                @Override
                public boolean isAuthenticated() {
                    return authentication.isAuthenticated();
                }

                @Override
                public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
                    authentication.setAuthenticated(isAuthenticated);
                }

                @Override
                public String getName() {
                    return authentication.getName();
                }
            };
        }

        @Override
        public boolean supports(Class<?> authentication) {
            return true;
        }
    };
}