Giriş
Bu sınıf maintenance modda.@EnableAuthorizationServer yazısına bakabilirsiniz.
Bu sınıf maintenance modda.@EnableAuthorizationServer yazısına bakabilirsiniz.
Daha derli doplu bir yazı için Authorization Code Grant yazısına bakabilirsiniz
Örnek
Şöyle yaparız.
configure metodu - AuthorizationServerSecurityConfigurer
İmzası şöyle. Bu metod'da hep aynı şey yapılıyor.
Şöyle yaparız.
Eğer kullanıcı bilgisi şifreli gelsin istersek şöyle yaparız. PasswordEncoder olarak örneğin BCryptPasswordEncoder kullanılabilir
configure - ClientDetailsServiceConfigurer - Kullanıcı Bilgileri
İmzası şöyle. Kullanıcı bilgileri ve token ile ilgili ayarlar burada yapılır.
Açıklama şöyle
Şöyle yaparız. Burada authorizedGrantTypes() metoduna "password" geçildiği için client şifresini gönderip token alabilir.
Şöyle yaparız. Burada authorizedGrantTypes() metoduna "password" ve "refresh_token" geçildiği için client şifresini gönderip token alabilir. Token'ı yenileyebilir.
configure - AuthorizationServerEndpointsConfigurer - TokenStore ve AuthenticationManager Ayarları
Authorization için kullanılack endpoint'lerin ayarlarını yapabilmeyi sağlar.
@Configuration
@EnableAuthorizationServer
protected static class AuthorizationServerConfiguration extends
  AuthorizationServerConfigurerAdapter {
  @Autowired
  private AuthenticationManager authenticationManager;
  @Autowired
  private UserDetailsService userDetailsService;
  @Autowired
  private PasswordEncoder passwordEncoder;
  @Autowired
  private TokenStore tokenStore;
  @Autowired
  private SecurityConfiguration securityConfiguration;
  ...
  
}configure metodu - AuthorizationServerSecurityConfigurer
İmzası şöyle. Bu metod'da hep aynı şey yapılıyor.
@Override
public void configure(AuthorizationServerSecurityConfigurer security) throws Exception;Şöyle yaparız.
@Override
public void configure(AuthorizationServerSecurityConfigurer security) {
  security.tokenKeyAccess("permitAll()")
    .checkTokenAccess("isAuthenticated()");
}Eğer kullanıcı bilgisi şifreli gelsin istersek şöyle yaparız. PasswordEncoder olarak örneğin BCryptPasswordEncoder kullanılabilir
@Override
public void configure(AuthorizationServerSecurityConfigurer security) {
  security.tokenKeyAccess("permitAll()")
    .checkTokenAccess("isAuthenticated()")
    .passwordEncoder(this.passwordEncoder);
}Örnek
Şöyle yaparız
@Override
public void configure(AuthorizationServerSecurityConfigurer oauthServer){
  oauthServer
    .tokenKeyAccess("permitAll()")
    .checkTokenAccess("permitAll()")
    .passwordEncoder(passwordEncoder)
    .allowFormAuthenticationForClients();
}İmzası şöyle. Kullanıcı bilgileri ve token ile ilgili ayarlar burada yapılır.
@Override
 public void configure(ClientDetailsServiceConfigurer clients) throws Exception;Açıklama şöyle
grant_type means the client can get access_token by client username and password or refresh_token.Örnek
Şöyle yaparız. Burada authorizedGrantTypes() metoduna "password" geçildiği için client şifresini gönderip token alabilir.
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  clients.inMemory().withClient("client")
    .secret(passwordEncoder.encode(("secret")))
    .authorizedGrantTypes("password")
    .scopes("webclient","mobileclient");
}
Şöyle yaparız. Burada authorizedGrantTypes() metoduna "password" ve "refresh_token" geçildiği için client şifresini gönderip token alabilir. Token'ı yenileyebilir.
clients.inMemory()
  .withClient(...)
  .authorizedGrantTypes("password", "refresh_token")
  .scopes("mobile_app")
  .resourceIds(...)
  .accessTokenValiditySeconds(...)
  .refreshTokenValiditySeconds(...)
  .secret(...);Örnek
Şöyle yaparız
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
  //IN-memory authentication configuration
  clients.inMemory()
      .withClient("web-portal")
      .authorizedGrantTypes("password", "authorization_code", "refresh_token", "implicit")
      .scopes("ui")
      .autoApprove(true)
      .secret(passwordEncoder.encode("password"))
      .redirectUris("http://localhost:8093/socialDiagnostica/login/oauth2/code/")
    .and()
      withClient("mobile-app")
      authorizedGrantTypes("client_credentials", "refresh_token", "password")
      scopes("ui")
      .autoApprove(true)
      .secret(passwordEncoder.encode("password"))
    .and()
      .withClient("social-diagnostica-service")
      .secret(passwordEncoder.encode("password"))
      .authorizedGrantTypes("client_credentials", "refresh_token")
      .scopes("server")
      .autoApprove(true);
//clients.jdbc(dataSource);
}Authorization için kullanılack endpoint'lerin ayarlarını yapabilmeyi sağlar.
