mam w pamięci, co działa w następujący sposób:Jak dodać klienta przy użyciu JDBC dla ClientDetailsServiceConfigurer na wiosnę?
@Override
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {
clients.inMemory()
.withClient("clientapp")
.authorizedGrantTypes("password", "refresh_token")
.authorities("USER")
.scopes("read", "write")
.resourceIds(RESOURCE_ID)
.secret("123456");
}
Chciałbym użyć realizacji JDBC. W tym celu utworzyłem następujące tabele (używając MySQL):
-- Tables for OAuth token store
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 TINYINT
);
CREATE TABLE oauth_client_token (
token_id VARCHAR(255),
token BLOB,
authentication_id VARCHAR(255),
user_name VARCHAR(255),
client_id VARCHAR(255)
);
CREATE TABLE oauth_access_token (
token_id VARCHAR(255),
token BLOB,
authentication_id VARCHAR(255),
user_name VARCHAR(255),
client_id VARCHAR(255),
authentication BLOB,
refresh_token VARCHAR(255)
);
CREATE TABLE oauth_refresh_token (
token_id VARCHAR(255),
token BLOB,
authentication BLOB
);
CREATE TABLE oauth_code (
code VARCHAR(255),
authentication BLOB
);
Czy muszę ręcznie dodawać klienta do tabel MySQL?
Próbowałem to:
clients.jdbc(dataSource).withClient("clientapp")
.authorizedGrantTypes("password", "refresh_token")
.authorities("USER")
.scopes("read", "write")
.resourceIds(RESOURCE_ID)
.secret("123456");
Mając nadzieję, że wiosna będzie wstawić odpowiednie rzeczy w dobrych tabel, ale nie wydaje się, aby to zrobić. Dlaczego możesz dalej łączyć się po jdbc()
?
Podążyłem za twoją odpowiedzią i skonfigurowałem serwer tak jak wspomniałeś i pomysł. Ale dostaję następujący błąd. Masz jakiś pomysł? {"Timestamp": 1458109110864, "status": 401, "error": "Unauthorized", "message": "Błąd tworzenia komponentu bean o nazwie" scopedTarget.clientDetailsService "zdefiniowany w ścieżce klasy resource [org/Spring Framework/hartowane/OAuth2/konfiguracji/adnotacji/konfiguracji/ClientDetailsServiceConfiguration.class] Fasola instancji poprzez metody fabryki nie powiodła się zagnieżdżony wyjątek org.springframework.beans.BeanInstantiationException: – Waruna
udało się wystąpienia [org.springframework.security.oauth2.provider. ClientDetailsService]: Metoda fabryczna "clientDetailsService" zwróciła wyjątek, zagnieżdżony wyjątek to org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; zła gramatyka SQL [wstawić do oauth_client_details (client_secret, resource_ids, scope, authorized_grant_types, web_server_redirect_uri, authority, access_token_validity, refresh_token_validity, additional_information, autoapprove, client_id) wartości (?,?,?,?,?,?,?,?,?,?,?)]; – Waruna
wyjątek zagnieżdżony to org.h2.jdbc.JdbcSQLException: nie znaleziono tabeli \ "OAUTH_CLIENT_DETAILS \"; Instrukcja SQL:????? \ nWstaw do oauth_client_details wartości (client_secret, resource_ids, zakres, authorized_grant_types, web_server_redirect_uri władze, access_token_validity, refresh_token_validity, additional_information, autoapprove, CLIENT_ID) (,,,,,,,,, ?,) [42102-190]”,«ścieżka»:«/ OAuth/żeton»} – Waruna