Adicionar UserDetailsService personalizado ao aplicativo Spring Security OAuth2

Como adiciono o costumeUserDetailsService abaixo deesta amostra do Spring OAuth2?

O padrãouser com padrãopassword é definido noapplication.properties arquivo doauthserver aplicativo.

No entanto, gostaria de adicionar o seguinte costumeUserDetailsService paraademo pacote doauthserver aplicativo para fins de teste:

package demo;

import java.util.List;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.provisioning.UserDetailsManager;
import org.springframework.stereotype.Service;

@Service
class Users implements UserDetailsManager {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        String password;
        List<GrantedAuthority> auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_USER");
        if (username.equals("Samwise")) {
            auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_HOBBIT");
            password = "TheShire";
        }
        else if (username.equals("Frodo")){
            auth = AuthorityUtils.commaSeparatedStringToAuthorityList("ROLE_HOBBIT");
            password = "MyRing";
        }
        else{throw new UsernameNotFoundException("Username was not found. ");}
        return new org.springframework.security.core.userdetails.User(username, password, auth);
    }

    @Override
    public void createUser(UserDetails user) {// TODO Auto-generated method stub
    }

    @Override
    public void updateUser(UserDetails user) {// TODO Auto-generated method stub
    }

    @Override
    public void deleteUser(String username) {// TODO Auto-generated method stub
    }

    @Override
    public void changePassword(String oldPassword, String newPassword) {
        // TODO Auto-generated method stub
    }

    @Override
    public boolean userExists(String username) {
        // TODO Auto-generated method stub
        return false;
    }
}

Como você pode ver, issoUserDetailsService&nbsp;não éautowired&nbsp;no entanto, e propositalmente usa senhas inseguras porque foi projetado apenas para fins de teste.

Que mudanças específicas precisam ser feitas parao aplicativo de exemplo do GitHub&nbsp;para que um usuário possa fazer login comousername=Samwise&nbsp;compassword=TheShireou comousername=Frodo&nbsp;compassword=MyRing?&nbsp;É necessário fazer alterações paraAuthserverApplication.java&nbsp;ou em outro lugar?

SUGESTÕES:

oGuia do desenvolvedor do Spring OAuth2&nbsp;diz para usar umGlobalAuthenticationManagerConfigurer&nbsp;para configurar umUserDetailsService&nbsp;globalmente. No entanto, pesquisar esses nomes no Google produz resultados menos que úteis.

Além disso, um aplicativo diferente que usa a segurança interna da mola INSTEAD OF OAuth usa a seguinte sintaxe para conectar oUserDetailsService, mas não sei como ajustar sua sintaxe ao OP atual:

@Order(Ordered.HIGHEST_PRECEDENCE)
@Configuration
protected static class AuthenticationSecurity extends GlobalAuthenticationConfigurerAdapter {

    @Autowired
    private Users users;

    @Override
    public void init(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(users);
    }
}

Eu tentei usar@Autowire&nbsp;dentro deOAuth2AuthorizationConfig&nbsp;conectarUsers&nbsp;aoAuthorizationServerEndpointsConfigurer&nbsp;do seguinte modo:

@Autowired//THIS IS A TEST
private Users users;//THIS IS A TEST

@Override
public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception {
   endpoints.authenticationManager(authenticationManager)
        .accessTokenConverter(jwtAccessTokenConverter())
        .userDetailsService(users)//DetailsService)//THIS LINE IS A TEST
        ;
}

Mas os logs do Spring Boot indicam que o usuárioSamwise&nbsp;não foi encontrado, o que significa que oUserDetailsService&nbsp;não foi conectado com êxito. Aqui está o trecho relevante dos logs do Spring Boot:

2016-04-20 15:34:39.998 DEBUG 5535 --- [nio-9999-exec-9] o.s.s.a.dao.DaoAuthenticationProvider    :  
        User 'Samwise' not found
2016-04-20 15:34:39.998 DEBUG 5535 --- [nio-9999-exec-9]   
        w.a.UsernamePasswordAuthenticationFilter :  
        Authentication request failed:  
        org.springframework.security.authentication.BadCredentialsException:  
        Bad credentials

O que mais posso tentar?