本文整理汇总了Java中com.nimbusds.oauth2.sdk.token.BearerAccessToken类的典型用法代码示例。如果您正苦于以下问题:Java BearerAccessToken类的具体用法?Java BearerAccessToken怎么用?Java BearerAccessToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BearerAccessToken类属于com.nimbusds.oauth2.sdk.token包,在下文中一共展示了BearerAccessToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Override
public OIDCClientInformation create(OIDCClientMetadata metadata, boolean dynamicRegistration) {
metadata.applyDefaults();
ClientID id = new ClientID(UUID.randomUUID().toString());
Instant issueDate = Instant.now();
Secret secret = isTokenEndpointAuthEnabled(metadata) ? new Secret() : null;
URI registrationUri = dynamicRegistration
? URI.create(this.registrationUriTemplate.replace("{id}", id.getValue()))
: null;
BearerAccessToken accessToken = dynamicRegistration ? new BearerAccessToken() : null;
OIDCClientInformation client = new OIDCClientInformation(id, Date.from(issueDate), metadata, secret,
registrationUri, accessToken);
this.clientRepository.save(client);
return client;
}
示例2: mapRow
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Override
public OIDCClientInformation mapRow(ResultSet rs, int rowNum) throws SQLException {
try {
String id = rs.getString("id");
Date issueDate = rs.getTimestamp("issue_date");
String metadata = rs.getString("metadata");
String secret = rs.getString("secret");
String registrationUri = rs.getString("registration_uri");
String accessToken = rs.getString("access_token");
return new OIDCClientInformation(new ClientID(id), issueDate,
OIDCClientMetadata.parse(JSONObjectUtils.parse(metadata)),
(secret != null) ? new Secret(secret) : null,
(registrationUri != null) ? URI.create(registrationUri) : null,
(accessToken != null) ? new BearerAccessToken(accessToken) : null);
}
catch (ParseException e) {
throw new TypeMismatchDataAccessException(e.getMessage(), e);
}
}
示例3: getClientRegistrations
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@GetMapping
public void getClientRegistrations(HttpServletRequest request, HttpServletResponse response) throws Exception {
HTTPRequest httpRequest = ServletUtils.createHTTPRequest(request);
try {
String authorizationHeader = httpRequest.getAuthorization();
if (authorizationHeader == null) {
throw new GeneralException(BearerTokenError.INVALID_TOKEN);
}
BearerAccessToken requestAccessToken = BearerAccessToken.parse(authorizationHeader);
validateAccessToken(requestAccessToken);
List<OIDCClientInformation> clients = this.clientRepository.findAll();
response.setContentType("application/json; charset=UTF-8");
PrintWriter writer = response.getWriter();
writer.print(toJsonObject(clients).toJSONString());
writer.close();
}
catch (GeneralException e) {
ClientRegistrationResponse registrationResponse = new ClientRegistrationErrorResponse(e.getErrorObject());
ServletUtils.applyHTTPResponse(registrationResponse.toHTTPResponse(), response);
}
}
示例4: resolveAndValidateClient
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
private OIDCClientInformation resolveAndValidateClient(ClientID clientId, ProtectedResourceRequest request)
throws GeneralException {
OIDCClientInformation client = this.clientRepository.findById(clientId);
if (client != null) {
AccessToken requestAccessToken = request.getAccessToken();
BearerAccessToken registrationAccessToken = client.getRegistrationAccessToken();
BearerAccessToken apiAccessToken = this.apiAccessToken;
if (requestAccessToken.equals(registrationAccessToken) || requestAccessToken.equals(apiAccessToken)) {
return client;
}
}
throw new GeneralException(BearerTokenError.INVALID_TOKEN);
}
示例5: implicitWithIdTokenAndToken_minimumParams_isSuccess
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void implicitWithIdTokenAndToken_minimumParams_isSuccess() throws Exception {
BearerAccessToken accessToken = new BearerAccessToken();
JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
given(this.clientRepository.findById(any(ClientID.class))).willReturn(implicitWithIdTokenAndTokenClient());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.will(returnsSecondArg());
MockHttpServletRequestBuilder request = get(
"/oauth2/authorize?scope=openid&response_type=id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test")
.session(this.session);
this.mvc.perform(request).andExpect(status().isFound())
.andExpect(redirectedUrlTemplate(
"http://example.com#access_token={accessToken}&id_token={idToken}&token_type=Bearer",
accessToken.getValue(), idToken.serialize()));
}
示例6: implicitWithIdTokenAndToken_withState_isSuccess
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void implicitWithIdTokenAndToken_withState_isSuccess() throws Exception {
BearerAccessToken accessToken = new BearerAccessToken();
JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
State state = new State();
given(this.clientRepository.findById(any(ClientID.class))).willReturn(implicitWithIdTokenAndTokenClient());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.will(returnsSecondArg());
MockHttpServletRequestBuilder request = get(
"/oauth2/authorize?scope=openid&response_type=id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test&state="
+ state.getValue()).session(this.session);
this.mvc.perform(request).andExpect(status().isFound()).andExpect(redirectedUrlTemplate(
"http://example.com#access_token={accessToken}&id_token={idToken}&state={state}&token_type=Bearer",
accessToken.getValue(), idToken.serialize(), state.getValue()));
}
示例7: hybridWithIdTokenAndToken_minimumParams_isSuccess
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void hybridWithIdTokenAndToken_minimumParams_isSuccess() throws Exception {
BearerAccessToken accessToken = new BearerAccessToken();
JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
AuthorizationCode authorizationCode = new AuthorizationCode();
given(this.clientRepository.findById(any(ClientID.class))).willReturn(hybridWithIdTokenAndTokenClient());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
given(this.authorizationCodeService.create(any(AuthorizationCodeContext.class))).willReturn(authorizationCode);
given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.will(returnsSecondArg());
MockHttpServletRequestBuilder request = get(
"/oauth2/authorize?scope=openid&response_type=code id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test")
.session(this.session);
this.mvc.perform(request).andExpect(status().isFound()).andExpect(redirectedUrlTemplate(
"http://example.com#access_token={accessToken}&code={code}&id_token={idToken}&token_type=Bearer",
accessToken.getValue(), authorizationCode.getValue(), idToken.serialize()));
}
示例8: hybridWithToken_minimumParams_isSuccess
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void hybridWithToken_minimumParams_isSuccess() throws Exception {
BearerAccessToken accessToken = new BearerAccessToken();
AuthorizationCode authorizationCode = new AuthorizationCode();
given(this.clientRepository.findById(any(ClientID.class))).willReturn(hybridWithTokenClient());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.authorizationCodeService.create(any(AuthorizationCodeContext.class))).willReturn(authorizationCode);
given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.will(returnsSecondArg());
MockHttpServletRequestBuilder request = get(
"/oauth2/authorize?scope=openid&response_type=code token&client_id=test-client&redirect_uri=http://example.com&nonce=test")
.session(this.session);
this.mvc.perform(request).andExpect(status().isFound())
.andExpect(redirectedUrlTemplate(
"http://example.com#access_token={accessToken}&code={code}&token_type=Bearer",
accessToken.getValue(), authorizationCode.getValue()));
}
示例9: hybridWithIdTokenAndToken_withState_isSuccess
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void hybridWithIdTokenAndToken_withState_isSuccess() throws Exception {
BearerAccessToken accessToken = new BearerAccessToken();
JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
AuthorizationCode authorizationCode = new AuthorizationCode();
State state = new State();
given(this.clientRepository.findById(any(ClientID.class))).willReturn(hybridWithIdTokenAndTokenClient());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
given(this.authorizationCodeService.create(any(AuthorizationCodeContext.class))).willReturn(authorizationCode);
given(this.subjectResolver.resolveSubject(any(HttpServletRequest.class))).willReturn(new Subject("user"));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.will(returnsSecondArg());
MockHttpServletRequestBuilder request = get(
"/oauth2/authorize?scope=openid&response_type=code id_token token&client_id=test-client&redirect_uri=http://example.com&nonce=test&state="
+ state.getValue()).session(this.session);
this.mvc.perform(request).andExpect(status().isFound()).andExpect(redirectedUrlTemplate(
"http://example.com#access_token={accessToken}&code={code}&id_token={idToken}&state={state}&token_type=Bearer",
accessToken.getValue(), authorizationCode.getValue(), idToken.serialize(), state.getValue()));
}
示例10: authCode_postAuth_isOk
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void authCode_postAuth_isOk() throws Exception {
ClientID clientId = new ClientID("test-client");
URI redirectUri = URI.create("http://rp.example.com");
AuthorizationCode authorizationCode = new AuthorizationCode();
ClientSecretPost clientAuth = new ClientSecretPost(clientId, new Secret("test-secret"));
TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
new AuthorizationCodeGrant(authorizationCode, redirectUri));
AuthorizationCodeContext context = new AuthorizationCodeContext(new Subject("user"), clientId, redirectUri,
new Scope(OIDCScopeValue.OPENID), Instant.now(), new ACR("1"), AMR.PWD, new SessionID("test"), null,
null, null);
BearerAccessToken accessToken = new BearerAccessToken();
JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
given(this.clientRepository.findById(any(ClientID.class)))
.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_POST));
given(this.authorizationCodeService.consume(eq(authorizationCode))).willReturn(context);
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
this.mvc.perform(request).andExpect(status().isOk());
}
示例11: authCode_pkcePlain_isOk
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void authCode_pkcePlain_isOk() throws Exception {
ClientID clientId = new ClientID("test-client");
URI redirectUri = URI.create("http://rp.example.com");
CodeVerifier codeVerifier = new CodeVerifier();
CodeChallengeMethod codeChallengeMethod = CodeChallengeMethod.PLAIN;
AuthorizationCode authorizationCode = new AuthorizationCode();
TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientId,
new AuthorizationCodeGrant(authorizationCode, redirectUri, codeVerifier));
AuthorizationCodeContext context = new AuthorizationCodeContext(new Subject("user"), clientId, redirectUri,
new Scope(OIDCScopeValue.OPENID), Instant.now(), new ACR("1"), AMR.PWD, new SessionID("test"),
CodeChallenge.compute(codeChallengeMethod, codeVerifier), codeChallengeMethod, null);
BearerAccessToken accessToken = new BearerAccessToken();
JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
given(this.clientRepository.findById(any(ClientID.class))).willReturn(client(ClientAuthenticationMethod.NONE));
given(this.authorizationCodeService.consume(eq(authorizationCode))).willReturn(context);
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
this.mvc.perform(request).andExpect(status().isOk());
}
示例12: authCode_pkceS256_isOk
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void authCode_pkceS256_isOk() throws Exception {
ClientID clientId = new ClientID("test-client");
URI redirectUri = URI.create("http://rp.example.com");
CodeVerifier codeVerifier = new CodeVerifier();
CodeChallengeMethod codeChallengeMethod = CodeChallengeMethod.S256;
AuthorizationCode authorizationCode = new AuthorizationCode();
TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientId,
new AuthorizationCodeGrant(authorizationCode, URI.create("http://rp.example.com"), codeVerifier));
AuthorizationCodeContext context = new AuthorizationCodeContext(new Subject("user"), clientId, redirectUri,
new Scope(OIDCScopeValue.OPENID), Instant.now(), new ACR("1"), AMR.PWD, new SessionID("test"),
CodeChallenge.compute(codeChallengeMethod, codeVerifier), codeChallengeMethod, null);
BearerAccessToken accessToken = new BearerAccessToken();
JWT idToken = new PlainJWT(new JWTClaimsSet.Builder().build());
given(this.clientRepository.findById(any(ClientID.class))).willReturn(client(ClientAuthenticationMethod.NONE));
given(this.authorizationCodeService.consume(eq(authorizationCode))).willReturn(context);
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
given(this.tokenService.createIdToken(any(IdTokenRequest.class))).willReturn(idToken);
MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
this.mvc.perform(request).andExpect(status().isOk());
}
示例13: resourceOwnerPasswordCredentials_basicAuth_isOk
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void resourceOwnerPasswordCredentials_basicAuth_isOk() throws Exception {
ClientSecretBasic clientAuth = new ClientSecretBasic(new ClientID("test-client"), new Secret("test-secret"));
TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
new ResourceOwnerPasswordCredentialsGrant("user", new Secret("password")),
new Scope(OIDCScopeValue.OPENID));
BearerAccessToken accessToken = new BearerAccessToken();
given(this.clientRepository.findById(any(ClientID.class)))
.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_BASIC));
given(this.authenticationHandler.authenticate(any(ResourceOwnerPasswordCredentialsGrant.class)))
.willReturn(new Subject("user"));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.willAnswer(returnsSecondArg());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.header("Authorization", clientAuth.toHTTPAuthorizationHeader());
this.mvc.perform(request).andExpect(status().isOk());
}
示例14: resourceOwnerPasswordCredentials_postAuth_isOk
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void resourceOwnerPasswordCredentials_postAuth_isOk() throws Exception {
ClientSecretPost clientAuth = new ClientSecretPost(new ClientID("test-client"), new Secret("test-secret"));
TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
new ResourceOwnerPasswordCredentialsGrant("user", new Secret("password")),
new Scope(OIDCScopeValue.OPENID));
BearerAccessToken accessToken = new BearerAccessToken();
given(this.clientRepository.findById(any(ClientID.class)))
.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_POST));
given(this.authenticationHandler.authenticate(any(ResourceOwnerPasswordCredentialsGrant.class)))
.willReturn(new Subject("user"));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.willAnswer(returnsSecondArg());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
.contentType(MediaType.APPLICATION_FORM_URLENCODED);
this.mvc.perform(request).andExpect(status().isOk());
}
示例15: clientCredentials_basicAuth_isOk
import com.nimbusds.oauth2.sdk.token.BearerAccessToken; //导入依赖的package包/类
@Test
public void clientCredentials_basicAuth_isOk() throws Exception {
ClientSecretBasic clientAuth = new ClientSecretBasic(new ClientID("test-client"), new Secret("test-secret"));
TokenRequest tokenRequest = new TokenRequest(URI.create("http://op.example.com"), clientAuth,
new ClientCredentialsGrant(), new Scope("test"));
BearerAccessToken accessToken = new BearerAccessToken();
given(this.clientRepository.findById(any(ClientID.class)))
.willReturn(client(ClientAuthenticationMethod.CLIENT_SECRET_BASIC));
given(this.scopeResolver.resolve(any(Subject.class), any(Scope.class), any(OIDCClientMetadata.class)))
.willAnswer(returnsSecondArg());
given(this.tokenService.createAccessToken(any(AccessTokenRequest.class))).willReturn(accessToken);
MockHttpServletRequestBuilder request = post("/oauth2/token").content(tokenRequest.toHTTPRequest().getQuery())
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
.header("Authorization", clientAuth.toHTTPAuthorizationHeader());
this.mvc.perform(request).andExpect(status().isOk());
}