Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.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
Java Spring OAuth2-如何配置身份验证服务,使其能够通过请求头或请求体传递用户凭据_Java_Spring_Spring Mvc_Spring Security_Spring Security Oauth2 - Fatal编程技术网

Java Spring OAuth2-如何配置身份验证服务,使其能够通过请求头或请求体传递用户凭据

Java Spring OAuth2-如何配置身份验证服务,使其能够通过请求头或请求体传递用户凭据,java,spring,spring-mvc,spring-security,spring-security-oauth2,Java,Spring,Spring Mvc,Spring Security,Spring Security Oauth2,我有一个应用程序是使用SpringSecurityOAuth22.0版实现的,所以如果用户需要访问令牌。他需要将用户凭据作为查询参数发送: /oauth/token?grant_type=password&client_id=website-CLIENT&username=test1&password=test1 请任何人都可以帮助我什么样的配置应该这样做,用户凭据可以作为请求体或请求头 Spring配置文件: <!-- Definition of the Au

我有一个应用程序是使用SpringSecurityOAuth22.0版实现的,所以如果用户需要访问令牌。他需要将用户凭据作为查询参数发送:

/oauth/token?grant_type=password&client_id=website-CLIENT&username=test1&password=test1
请任何人都可以帮助我什么样的配置应该这样做,用户凭据可以作为请求体或请求头

Spring配置文件:

 <!-- Definition of the Authentication Service -->
<http pattern="/oauth/token" create-session="stateless" authentication-manager-ref="clientAuthenticationManager"
      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"/>
    <!-- include this only if you need to authenticate clients via request parameters -->
    <custom-filter ref="clientCredentialsTokenEndpointFilter" after="BASIC_AUTH_FILTER"/>
    <access-denied-handler ref="oauthAccessDeniedHandler"/>
</http>

<bean id="oauthAuthenticationEntryPoint"
      class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint"/>

<bean id="clientAuthenticationEntryPoint"
      class="org.springframework.security.oauth2.provider.error.OAuth2AuthenticationEntryPoint">
    <property name="realmName" value="client"/>
    <property name="typeName" value="Basic"/>
</bean>

<bean id="oauthAccessDeniedHandler"
      class="org.springframework.security.oauth2.provider.error.OAuth2AccessDeniedHandler"/>

<bean id="clientCredentialsTokenEndpointFilter"
      class="org.springframework.security.oauth2.provider.client.ClientCredentialsTokenEndpointFilter">
    <property name="authenticationManager" ref="clientAuthenticationManager"/>
</bean>

<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased"
      xmlns="http://www.springframework.org/schema/beans">
    <constructor-arg>
        <list>
            <bean class="org.springframework.security.oauth2.provider.vote.ScopeVoter"/>
            <bean class="org.springframework.security.access.vote.RoleVoter"/>
            <bean class="org.springframework.security.access.vote.AuthenticatedVoter"/>
        </list>
    </constructor-arg>
</bean>

<bean id="customAuthenticationManager"
      class="com.xyz.authentication.XYZDBAuthenticationProvider"/>

<!-- Authentication in config file -->
<authentication-manager id="clientAuthenticationManager" xmlns="http://www.springframework.org/schema/security">
    <authentication-provider user-service-ref="clientDetailsUserService"/>
</authentication-manager>

<authentication-manager alias="authenticationManager" xmlns="http://www.springframework.org/schema/security">
    <authentication-provider ref="customAuthenticationManager"/>
</authentication-manager>

<bean id="clientDetailsUserService"
      class="org.springframework.security.oauth2.provider.client.ClientDetailsUserDetailsService">
    <constructor-arg ref="clientDetails"/>
</bean>

<!-- Token Store  -->
<bean id="tokenStore" class="org.springframework.security.oauth2.provider.token.store.JdbcTokenStore">
    <constructor-arg ref="jdbcTokenStore" />
</bean>

<bean id="jdbcTokenStore"
      class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url" value="#{systemProperties['JDBC_CONNECTION_STRING']}/#{systemProperties['DATABASE']}?autoReconnect=true"/>
    <property name="username" value="#{systemProperties['USER_NAME']}"/>
    <property name="password" value="#{systemProperties['PASSWORD']}"/>
</bean>


<bean id="tokenServices" class="xyz.oauth2.CustomTokenServices">
    <property name="tokenStore" ref="tokenStore"/>
    <property name="supportRefreshToken" value="true"/>
    <property name="clientDetailsService" ref="clientDetails"/>
    <!-- VIV -->
    <property name="accessTokenValiditySeconds" value="7776000"/>
</bean>

<bean id="userApprovalHandler"
      class="org.springframework.security.oauth2.provider.approval.TokenStoreUserApprovalHandler">
    <property name="tokenStore" ref="tokenStore"/>
    <property name="requestFactory" ref="oAuth2RequestFactory"/>
</bean>

<bean id="oAuth2RequestFactory"
      class="org.springframework.security.oauth2.provider.request.DefaultOAuth2RequestFactory">
    <constructor-arg ref="clientDetails"/>
</bean>
<!-- Token management -->
<oauth:authorization-server client-details-service-ref="clientDetails" token-services-ref="tokenServices"
                            user-approval-handler-ref="userApprovalHandler">
    <oauth:implicit/>
    <oauth:refresh-token/>
    <oauth:client-credentials/>
    <oauth:password/>
</oauth:authorization-server>

<oauth:resource-server id="resourceServerFilter"
                       token-services-ref="tokenServices"/>


<!-- Client Definition -->
<oauth:client-details-service id="clientDetails">

    <oauth:client client-id="mobile-CLIENT"
                  authorized-grant-types="password,refresh_token,implicit"
                  authorities="ROLE_CLIENT, ROLE_TRUSTED_CLIENT"
                  scope="read,write,trust"
                  access-token-validity="7776000"
                  refresh-token-validity="15552000"/>

    <oauth:client client-id="website-CLIENT"
                  authorized-grant-types="password,refresh_token,implicit"
                  authorities="ROLE_CLIENT, ROLE_TRUSTED_CLIENT"
                  scope="read,write,trust"
                  access-token-validity="7776000"
                  refresh-token-validity="15552000"/>

</oauth:client-details-service>

    <sec:global-method-security pre-post-annotations="enabled" proxy-target-class="true">
    <sec:expression-handler ref="oauthExpressionHandler"/>
</sec:global-method-security>
<oauth:expression-handler id="oauthExpressionHandler"/>
<oauth:web-expression-handler id="oauthWebExpressionHandler"/>


请帮助任何人:'(我的截止日期快到了:'(至少guide mecontent type:x-www-url-encoded with POST request是唯一的方法。请帮助任何人:'(我的截止日期快到了:'(至少guide mecontent type:x-www-url-encoded with POST request是唯一的方法)。