Mysql
 sql >> Cơ Sở Dữ Liệu >  >> RDS >> Mysql

Làm cách nào để thêm một ứng dụng khách bằng JDBC cho ClientDetailsServiceConfigurer trong Spring?

Vui lòng bỏ qua các bước sau:

  1. đặt schema.sql này bên trong thư mục tài nguyên của bạn để SpringBoot phát hiện khi bạn khởi động máy chủ của mình. Nếu bạn không sử dụng khởi động mùa xuân, đừng lo lắng, chỉ cần nhập tập lệnh này từ bất kỳ Ứng dụng khách Mysql nào (phpmyadmin, HeidiSQL, Navicat ..)

    drop table if exists oauth_client_details; create table oauth_client_details ( client_id VARCHAR(255) PRIMARY KEY, resource_ids VARCHAR(255), client_secret VARCHAR(255), scope VARCHAR(255), authorized_grant_types VARCHAR(255), web_server_redirect_uri VARCHAR(255), authorities VARCHAR(255), access_token_validity INTEGER, refresh_token_validity INTEGER, additional_information VARCHAR(4096), autoapprove VARCHAR(255) ); drop table if exists oauth_client_token; create table oauth_client_token ( token_id VARCHAR(255), token LONG VARBINARY, authentication_id VARCHAR(255) PRIMARY KEY, user_name VARCHAR(255), client_id VARCHAR(255) ); drop table if exists oauth_access_token; create table oauth_access_token ( token_id VARCHAR(255), token LONG VARBINARY, authentication_id VARCHAR(255) PRIMARY KEY, user_name VARCHAR(255), client_id VARCHAR(255), authentication LONG VARBINARY, refresh_token VARCHAR(255) ); drop table if exists oauth_refresh_token; create table oauth_refresh_token ( token_id VARCHAR(255), token LONG VARBINARY, authentication LONG VARBINARY ); drop table if exists oauth_code; create table oauth_code ( code VARCHAR(255), authentication LONG VARBINARY ); drop table if exists oauth_approvals; create table oauth_approvals ( userId VARCHAR(255), clientId VARCHAR(255), scope VARCHAR(255), status VARCHAR(10), expiresAt TIMESTAMP, lastModifiedAt TIMESTAMP ); drop table if exists ClientDetails; create table ClientDetails ( appId VARCHAR(255) PRIMARY KEY, resourceIds VARCHAR(255), appSecret VARCHAR(255), scope VARCHAR(255), grantTypes VARCHAR(255), redirectUrl VARCHAR(255), authorities VARCHAR(255), access_token_validity INTEGER, refresh_token_validity INTEGER, additionalInformation VARCHAR(4096), autoApproveScopes VARCHAR(255) );
  2. Chèn DataSource, AuthenticManager, UserDetailsService của bạn vào bên trong OthorizationServer của bạn

    @Autowired private MyUserDetailsService userDetailsService; @Inject private AuthenticationManager authenticationManager; @Autowired private DataSource dataSource;
  3. Bạn sẽ cần tạo hai hạt đậu này

    @Bean public JdbcTokenStore tokenStore() { return new JdbcTokenStore(dataSource); } @Bean protected AuthorizationCodeServices authorizationCodeServices() { return new JdbcAuthorizationCodeServices(dataSource); }

    và đừng quên về @Configuration ở đầu lớp AuthorizationServer của bạn

  4. Định cấu hình các ứng dụng khách của bạn sẽ được tạo trong cơ sở dữ liệu mysql của bạn:clients.jdbc(dataSource).withClient("clientapp") .authorizedGrantTypes("password", "refresh_token") .authorities("USER") .scopes("read", "write") .resourceIds(RESOURCE_ID) .secret("123456");

    bạn đã làm điều này.

  5. điều quan trọng nhất (và tôi nghĩ rằng bạn đã quên điều đó ..) là:định cấu hình các điểm cuối của bạn với AuthorizationServerEndpointsConfigurer:

    endpoints.userDetailsService(userDetailsService) .authorizationCodeServices(authorizationCodeServices()).authenticationManager(this.authenticationManager).tokenStore(tokenStore()).approvalStoreDisabled();

và đó là người đàn ông, bây giờ nó sẽ hoạt động;)

Và vui lòng yêu cầu thêm ... Tôi sẽ sẵn lòng trợ giúp

Tôi đã gửi cho bạn một tin nhắn từ tweeter!



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MySQL COUNT DISTINCT

  2. Làm cách nào để ngăn vượt quá max_user_connections khi tải lại / làm mới trang nhiều lần?

  3. Làm thế nào để xây dựng lại một MySQL Slave không nhất quán?

  4. this._callback.apply không phải là một hàm! Node js Mysql error

  5. MySQL LIMIT trong một truy vấn con tương ứng