2017-04-05 9 views
0

私は基本的なoauth2認証サーバーを設定しています。ここに私のアプリケーション構成があります。スプリングブートoauth2 "/ auth/oauth/token"が禁止されています

@SpringBootApplication 
@RestController 
@EnableResourceServer 
@EnableAuthorizationServer 
public class Application { 

    @RequestMapping(value = { "/user" }, produces = "application/json") 
    public Map<String, Object> user(OAuth2Authentication user) { 
     Map<String, Object> userInfo = new HashMap<>(); 
     userInfo.put("user", user.getUserAuthentication().getPrincipal()); 
     userInfo.put("authorities", AuthorityUtils.authorityListToSet(user.getUserAuthentication().getAuthorities())); 
     return userInfo; 
    } 


    public static void main(String[] args) { 
     SpringApplication.run(Application.class, args); 
    } 


} 

WebSecurityConfigurer

import org.springframework.context.annotation.Bean; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.security.authentication.AuthenticationManager; 
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; 
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; 
import org.springframework.security.core.userdetails.UserDetailsService; 


    @Configuration 
    public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter { 
     @Override 
     @Bean 
     public AuthenticationManager authenticationManagerBean() throws Exception { 
      return super.authenticationManagerBean(); 
     } 

     @Override 
     @Bean 
     public UserDetailsService userDetailsServiceBean() throws Exception { 
      return super.userDetailsServiceBean(); 
     } 


     @Override 
     protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
      auth 
        .inMemoryAuthentication() 
        .withUser("john.carnell").password("password1").roles("USER") 
        .and() 
        .withUser("william.woodward").password("password2").roles("USER", "ADMIN"); 
     } 
    } 

と私のOauth2Config

@Configuration 
public class OAuth2Config extends AuthorizationServerConfigurerAdapter { 

    @Autowired 
    private AuthenticationManager authenticationManager; 

    @Autowired 
    private UserDetailsService userDetailsService; 

    @Override 
    public void configure(ClientDetailsServiceConfigurer clients) throws Exception { 
     clients.inMemory() 
       .withClient("eagleeye") 
       .secret("thisissecret") 
       .authorizedGrantTypes("refresh_token", "password", "client_credentials") 
       .scopes("webclient", "mobileclient"); 
    } 

    @Override 
    public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { 
     endpoints 
       .authenticationManager(authenticationManager) 
       .userDetailsService(userDetailsService); 
    } 
} 

私はローカルホストからのトークンを取得しようとしています:8080 /認証/ OAuthの/郵便配達を使用してトークンが、それはこれだけをスローしますエラー。

{ 
    "error": "unauthorized", 
    "error_description": "Full authentication is required to access this resource" 
} 

、ここだ、私は郵便配達から

enter image description here enter image description here

+0

にURLを変更しましたhttpの呼び出しに対して認証が不足していますか? @Overrideを追加するとどうなりますか? protected void configure(HttpSecurity http)例外をスローします( http.authorizeRequests()。anyRequest()。authenticated() .and() .httpBasic(); } '' WebSecurityConfigurer 'に? (ログなしで伝えるのは難しいですが、私は '@ EnableResourceServer'がすでにこれをしていると思います) – ninj

+0

郵便配達員の投稿要求のURLにclient_idとgrant_typeを追加します。 .../oauth/token?client_id = eagleeye&grant_type = passwordのようになります。 – Johna

答えて

0

を渡していた値は、私は、エンドポイントにアクセスすることができましたが、それはエラーを返しましたが、それはまた別の問題のためです。私はちょうどlocalhost:8080/auth/oauth/tokeからlocalhost:8080/oauth/token

関連する問題