Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Rest 将Jdbc数据存储分配给ClientDetailsService时,Spring AuthorizationServerConfigurerAdapter出错_Rest_Spring Mvc_Spring Security_Orientdb_Spring Security Oauth2 - Fatal编程技术网

Rest 将Jdbc数据存储分配给ClientDetailsService时,Spring AuthorizationServerConfigurerAdapter出错

Rest 将Jdbc数据存储分配给ClientDetailsService时,Spring AuthorizationServerConfigurerAdapter出错,rest,spring-mvc,spring-security,orientdb,spring-security-oauth2,Rest,Spring Mvc,Spring Security,Orientdb,Spring Security Oauth2,您好,我正在使用Spring Oauth2创建AuthorizationServerConfigurerAdapter身份验证服务器。我选择了JdbcTokenStore并将TokenStore数据库设置为OrientDb 下面是我如何定义clientDetailsService的 我还将表格定义如下: orientdb {db=pricewiz}> info class oauth_client_details Class................: oauth_client_d

您好,我正在使用Spring Oauth2创建AuthorizationServerConfigurerAdapter身份验证服务器。我选择了JdbcTokenStore并将TokenStore数据库设置为OrientDb

下面是我如何定义clientDetailsService的

我还将表格定义如下:

orientdb {db=pricewiz}> info class oauth_client_details

Class................: oauth_client_details
Default cluster......: oauth_client_details (id=19)
Supported cluster ids: [19]
Cluster selection....: round-robin

PROPERTIES
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 NAME                          | TYPE        | LINKED TYPE/CLASS             | MANDATORY | READONLY | NOT NULL |    MIN    |    MAX    | COLLATE  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 additional_information        | STRING      | null                          | false     | false    | false    |           |           | default  |
 autoapprove                   | STRING      | null                          | false     | false    | false    |           |           | default  |
 scope                         | STRING      | null                          | false     | false    | false    |           |           | default  |
 web_server_redirect_uri       | STRING      | null                          | false     | false    | false    |           |           | default  |
 authorized_grant_types        | STRING      | null                          | false     | false    | false    |           |           | default  |
 client_secret                 | STRING      | null                          | false     | false    | false    |           |           | default  |
 resource_ids                  | STRING      | null                          | false     | false    | false    |           |           | default  |
 authorities                   | STRING      | null                          | false     | false    | false    |           |           | default  |
 client_id                     | STRING      | null                          | false     | false    | true     |           |           | default  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
orientdb {db=pricewiz}> info class oauth_client_token

Class................: oauth_client_token
Default cluster......: oauth_client_token (id=20)
Supported cluster ids: [20]
Cluster selection....: round-robin

PROPERTIES
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 NAME                          | TYPE        | LINKED TYPE/CLASS             | MANDATORY | READONLY | NOT NULL |    MIN    |    MAX    | COLLATE  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 token_id                      | STRING      | null                          | false     | false    | false    |           |           | default  |
 user_name                     | STRING      | null                          | false     | false    | false    |           |           | default  |
 client_id                     | STRING      | null                          | false     | false    | false    |           |           | default  |
 authentication_id             | STRING      | null                          | false     | false    | false    |           |           | default  |
 token                         | BINARY      | null                          | false     | false    | false    |           |           | default  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
orientdb {db=pricewiz}> info class oauth_access_token

Class................: oauth_access_token
Default cluster......: oauth_access_token (id=21)
Supported cluster ids: [21]
Cluster selection....: round-robin

PROPERTIES
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 NAME                          | TYPE        | LINKED TYPE/CLASS             | MANDATORY | READONLY | NOT NULL |    MIN    |    MAX    | COLLATE  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 refresh_token                 | STRING      | null                          | false     | false    | false    |           |           | default  |
 token_id                      | STRING      | null                          | false     | false    | false    |           |           | default  |
 user_name                     | STRING      | null                          | false     | false    | false    |           |           | default  |
 authentication_id             | STRING      | null                          | false     | false    | false    |           |           | default  |
 client_id                     | STRING      | null                          | false     | false    | false    |           |           | default  |
 authentication                | BINARY      | null                          | false     | false    | false    |           |           | default  |
 token                         | BINARY      | null                          | false     | false    | false    |           |           | default  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
orientdb {db=pricewiz}> info class oauth_refresh_token

Class................: oauth_refresh_token
Default cluster......: oauth_refresh_token (id=22)
Supported cluster ids: [22]
Cluster selection....: round-robin

PROPERTIES
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 NAME                          | TYPE        | LINKED TYPE/CLASS             | MANDATORY | READONLY | NOT NULL |    MIN    |    MAX    | COLLATE  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 token_id                      | STRING      | null                          | false     | false    | false    |           |           | default  |
 token                         | BINARY      | null                          | false     | false    | false    |           |           | default  |
 authentication                | BINARY      | null                          | false     | false    | false    |           |           | default  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
orientdb {db=pricewiz}> info class oauth_code

Class................: oauth_code
Default cluster......: oauth_code (id=23)
Supported cluster ids: [23]
Cluster selection....: round-robin

PROPERTIES
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 NAME                          | TYPE        | LINKED TYPE/CLASS             | MANDATORY | READONLY | NOT NULL |    MIN    |    MAX    | COLLATE  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 code                          | STRING      | null                          | false     | false    | false    |           |           | default  |
 authentication                | BINARY      | null                          | false     | false    | false    |           |           | default  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
orientdb {db=pricewiz}> info class oauth_approvals

Class................: oauth_approvals
Default cluster......: oauth_approvals (id=24)
Supported cluster ids: [24]
Cluster selection....: round-robin

PROPERTIES
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 NAME                          | TYPE        | LINKED TYPE/CLASS             | MANDATORY | READONLY | NOT NULL |    MIN    |    MAX    | COLLATE  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
 clientId                      | STRING      | null                          | false     | false    | false    |           |           | default  |
 scope                         | STRING      | null                          | false     | false    | false    |           |           | default  |
 userId                        | STRING      | null                          | false     | false    | false    |           |           | default  |
 lastModifiedAt                | DATE        | null                          | false     | false    | false    |           |           | default  |
 expiresAt                     | DATE        | null                          | false     | false    | false    |           |           | default  |
 status                        | STRING      | null                          | false     | false    | false    |           |           | default  |
-------------------------------+-------------+-------------------------------+-----------+----------+----------+-----------+-----------+----------+
orientdb {db=pricewiz}>
现在,当我尝试使用curl获取身份验证密钥时,它给出了以下错误:

{"timestamp":1420109129595,"status":401,"error":"Unauthorized","message":"Error creating bean with name 'scopedTarget.clientDetailsService' defined in class path resource [org/springframework/security/oauth2/config/annotation/configuration/ClientDetailsServiceConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.security.oauth2.provider.ClientDetailsService]: Factory method 'clientDetailsService' threw exception; nested exception is java.lang.ClassCastException: com.orientechnologies.orient.core.record.impl.ODocument cannot be cast to java.lang.Integer"}
Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:558)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)
请帮助我,因为我是春天安全的新手

谢谢, 努鲁尔

编辑

我根据建议尝试使用MariaDB,并在XML文件中移动了OAuth部分

spring-servlet.xml

你能告诉我现在有什么问题吗

谢谢,
Noorul

我对orientdb不太了解,但所有这些字符串类型看起来都有点错误,错误表明您有一个错误类型的列。这里至少有一些DDL需要从普通SQL数据库开始:。为什么不先尝试不同的数据库来让它工作呢?

关于XML,我什么也没说。新的错误只是说您没有配置数据源。查看《Spring Boot用户指南》以获得有关如何工作的帮助。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:oauth="http://www.springframework.org/schema/security/oauth2"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:sec="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security/oauth2 http://www.springframework.org/schema/security/spring-security-oauth2.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">
       <http pattern="/oauth/token" create-session="stateless"
             authentication-manager-ref="authenticationManager"
             xmlns="http://www.springframework.org/schema/security" >
              <intercept-url pattern="/oauth/token" access="IS_AUTHENTICATED_FULLY" />
              <anonymous enabled="false" />
              <http-basic entry-point-ref="clientAuthenticationEntryPoint"/>
              <custom-filter ref="clientCredentialsTokenEndpointFilter"         before="BASIC_AUTH_FILTER" />
              <access-denied-handler ref="oauthAccessDeniedHandler" />
       </http>
       <bean id="clientCredentialsTokenEndpointFilter"
             class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
              <property name="authenticationManager" ref="authenticationManager" />
       </bean>

       <authentication-manager alias="authenticationManager"
                               xmlns="http://www.springframework.org/schema/security">
              <authentication-provider user-service-ref="clientDetailsUserService" />
       </authentication-manager>
       <bean id="clientDetailsUserService"
             class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
              <constructor-arg ref="clientDetails" />
       </bean>
       <bean id="clientDetails" class="com.rayat.pricewizWS.security.ClientDetailsServiceImpl"></bean>
       <bean id="clientAuthenticationEntryPoint"
             class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
              <property name="realmName" value="springsec/client" />
              <property name="typeName" value="Basic" />
       </bean>
       <bean id="oauthAccessDeniedHandler"
             class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler"/>

       <oauth:authorization-server
               client-details-service-ref="clientDetails" token-services-ref="tokenServices">
              <oauth:authorization-code />
              <oauth:implicit/>
              <oauth:refresh-token/>
              <oauth:client-credentials />
              <oauth:password authentication-manager-ref="userAuthenticationManager"/>
       </oauth:authorization-server>

       <authentication-manager id="userAuthenticationManager"
                               xmlns="http://www.springframework.org/schema/security">
              <authentication-provider  ref="customUserAuthenticationProvider">
              </authentication-provider>
       </authentication-manager>
       <bean id="customUserAuthenticationProvider"
             class="com.rayat.pricewizWS.security.CustomUserAuthenticationProvider">
       </bean>

       <bean id="tokenServices"
             class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
              <property name="tokenStore" ref="tokenStore" />
              <property name="supportRefreshToken" value="true" />
              <property name="accessTokenValiditySeconds" value="900000000"></property>
              <property name="clientDetailsService" ref="clientDetails" />
       </bean>
       <bean id="tokenStore"
             class="org.springframework.security.oauth2.provider.token.store.JdbcTokenStore">
           <constructor-arg ref="mariadbJdbcTemplate"/>
       </bean>
       <bean id="mariadbJdbcTemplate"
             class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
            <property name="driverClassName" value="org.mariadb.jdbc.Driver"/>
            <property name="url" value="jdbc:mariadb://localhost:3306/oauthdb"/>
            <property name="username" value="root"/>
            <property name="password" value="xxxxxxxx"/>
       </bean>
        <bean id="orientDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="com.orientechnologies.orient.jdbc.OrientJdbcDriver"/>
            <property name="url" value="jdbc:orient:remote:localhost/pricewiz"/>
            <property name="username" value="admin"/>
            <property name="password" value="xxxxxxxx"/>
        </bean>
       <bean id="oauthAuthenticationEntryPoint"
             class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
       </bean>
       <http pattern="/product/**" create-session="never"
             entry-point-ref="oauthAuthenticationEntryPoint"
             xmlns="http://www.springframework.org/schema/security">
              <anonymous enabled="false" />
              <intercept-url pattern="/product/**"  access="IS_AUTHENTICATED_FULLY" />
              <custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
              <access-denied-handler ref="oauthAccessDeniedHandler" />
       </http>
       <oauth:resource-server id="resourceServerFilter"
                              resource-id="springsec" token-services-ref="tokenServices" />
       <http pattern="/logout" create-session="never" entry-point-ref="oauthAuthenticationEntryPoint"
             xmlns="http://www.springframework.org/schema/security">
              <anonymous enabled="false" />
              <intercept-url pattern="/logout" access="ROLE_CLIENT" method="GET" />
              <sec:logout invalidate-session="true" logout-url="/logout" success-handler-ref="logoutSuccessHandler"/>
              <custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
              <access-denied-handler ref="oauthAccessDeniedHandler" />
       </http>
       <bean id="logoutSuccessHandler"
             class="com.rayat.pricewizWS.security.LogoutImpl" >
              <property name="tokenstore" ref="tokenStore"></property>
       </bean>
</beans>
Failed to instantiate [javax.sql.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath.
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:558)
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331)