我目前正在配置我的Oauth2RestTemplate與我的控制器的點。所述控制器將接收用戶的用戶名和密碼,以便在ResourceOwnerPasswordResourceDetails中設置,但是,我沒有看到如何設置。此應用程序用於Oauth2客戶端設置。ResourceOwnerPasswordResourceDetails與Oauth2RestTemplate,設置用戶名和密碼
//An extention of ResourceOwnerPasswordResourceDetails that adds a property 'token'.
<bean id="cPassword" class="com.cointraders.site.overrides.TokenOauthResourceDetails">
<property name="grantType" value="c_password"></property>
<property name="clientAuthenticationScheme" value="header"></property>
<property name="clientId" value="cointraders"></property>
<property name="clientSecret" value="[email protected]"></property>
<property name="accessTokenUri" value="${oauth.accessTokenUri}"></property>
</bean>
//My controller using the 'cPassword' bean above
<bean id="loginController" class="com.cointraders.site.controllers.LoginController">
<property name="checkCredentialRest">
<oauth:rest-template resource="cPassword">
</oauth:rest-template>
</property>
</bean>
//My Controller
@RequestMapping(value="/login")
public class LoginController {
private OAuth2RestTemplate checkCredentialRest;
private OAuth2RestTemplate loginCredentialRest;
public void setCheckCredentialRest(OAuth2RestTemplate checkCredentialRest) {
this.checkCredentialRest = checkCredentialRest;
}
public void setLoginCredentialRest(OAuth2RestTemplate loginCredentialRest) {
this.loginCredentialRest = loginCredentialRest;
}
@RequestMapping(method=RequestMethod.POST)
@ResponseStatus(value=HttpStatus.OK)
public void verifyCredential(@RequestBody LoginCredential creds)
{
}
}
正如所看到的,從我的「verifyCredential」我傳遞映射到DataMapper的LoginCredential的憑據。該類爲用戶提供了「用戶名」,「密碼」和「令牌」屬性。在這一點上,我認爲將LoginCredential的對象屬性傳遞給OAuth2RestTemplate loginCredentialRest很容易,但事實並非如此。
此外,我已經配置了ResourceOwnerPasswordResourceDetails與訪問令牌端點(accessTokenUri),並基本上將此對象連接到Oauth2RestTemplate。我將如何使用它向訪問令牌端點提供請求,爲Access令牌提供「用戶名」,「密碼」和「令牌」?