本文整理汇总了Java中org.apereo.cas.ticket.accesstoken.AccessToken类的典型用法代码示例。如果您正苦于以下问题:Java AccessToken类的具体用法?Java AccessToken怎么用?Java AccessToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessToken类属于org.apereo.cas.ticket.accesstoken包,在下文中一共展示了AccessToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCallbackUrlForImplicitTokenResponseType
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
private String buildCallbackUrlForImplicitTokenResponseType(final J2EContext context,
final Authentication authentication,
final Service service,
final String redirectUri,
final String clientId,
final OAuth20ResponseTypes responseType,
final TicketGrantingTicket ticketGrantingTicket) {
try {
final OidcRegisteredService oidcService = (OidcRegisteredService)
OAuth20Utils.getRegisteredOAuthService(this.servicesManager, clientId);
final AccessTokenRequestDataHolder holder = new AccessTokenRequestDataHolder(service, authentication, oidcService, ticketGrantingTicket);
final AccessToken accessToken = generateAccessToken(holder);
LOGGER.debug("Generated OAuth access token: [{}]", accessToken);
final long timeout = casProperties.getTicket().getTgt().getTimeToKillInSeconds();
final String idToken = this.idTokenGenerator.generate(context.getRequest(),
context.getResponse(),
accessToken, timeout, responseType, oidcService);
LOGGER.debug("Generated id token [{}]", idToken);
final List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair(OidcConstants.ID_TOKEN, idToken));
return buildCallbackUrlResponseType(authentication, service, redirectUri, accessToken, params);
} catch (final Exception e) {
throw Throwables.propagate(e);
}
}
示例2: generateJsonInternal
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
@Override
protected void generateJsonInternal(final HttpServletRequest request,
final HttpServletResponse response,
final JsonGenerator jsonGenerator,
final AccessToken accessTokenId,
final RefreshToken refreshTokenId,
final long timeout,
final Service service,
final OAuthRegisteredService registeredService,
final OAuth20ResponseTypes responseType) throws Exception {
super.generateJsonInternal(request, response, jsonGenerator, accessTokenId,
refreshTokenId, timeout, service, registeredService, responseType);
final OidcRegisteredService oidcRegisteredService = (OidcRegisteredService) registeredService;
final String idToken = this.idTokenGenerator.generate(request, response, accessTokenId,
timeout, responseType, oidcRegisteredService);
jsonGenerator.writeStringField(OidcConstants.ID_TOKEN, idToken);
}
示例3: generate
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
/**
* Generate string.
*
* @param request the request
* @param response the response
* @param accessTokenId the access token id
* @param timeout the timeout
* @param responseType the response type
* @param registeredService the registered service
* @return the string
* @throws Exception the exception
*/
public String generate(final HttpServletRequest request,
final HttpServletResponse response,
final AccessToken accessTokenId,
final long timeout,
final OAuth20ResponseTypes responseType,
final OAuthRegisteredService registeredService) throws Exception {
final OidcRegisteredService oidcRegisteredService = (OidcRegisteredService) registeredService;
final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
final Optional<UserProfile> profile = manager.get(true);
LOGGER.debug("Attempting to produce claims for the id token [{}]", accessTokenId);
final JwtClaims claims = produceIdTokenClaims(request, accessTokenId, timeout,
oidcRegisteredService, profile.get(), context, responseType);
LOGGER.debug("Produce claims for the id token [{}] as [{}]", accessTokenId, claims);
return this.signingService.encode(oidcRegisteredService, claims);
}
示例4: generateAccessTokenHash
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
private String generateAccessTokenHash(final AccessToken accessTokenId,
final OidcRegisteredService service) {
final byte[] tokenBytes = accessTokenId.getId().getBytes();
final String hashAlg;
switch (signingService.getJsonWebKeySigningAlgorithm()) {
case AlgorithmIdentifiers.RSA_USING_SHA512:
hashAlg = MessageDigestAlgorithms.SHA_512;
break;
case AlgorithmIdentifiers.RSA_USING_SHA256:
default:
hashAlg = MessageDigestAlgorithms.SHA_256;
}
LOGGER.debug("Digesting access token hash via algorithm [{}]", hashAlg);
final byte[] digested = DigestUtils.rawDigest(hashAlg, tokenBytes);
final byte[] hashBytesLeftHalf = Arrays.copyOf(digested, digested.length / 2);
return EncodingUtils.encodeBase64(hashBytesLeftHalf);
}
示例5: generate
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
@Override
public void generate(final HttpServletRequest request,
final HttpServletResponse response,
final OAuthRegisteredService registeredService,
final Service service,
final AccessToken accessTokenId,
final RefreshToken refreshTokenId,
final long timeout,
final OAuth20ResponseTypes responseType) {
if (registeredService.isJsonFormat()) {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
try (JsonGenerator jsonGenerator = getResponseJsonGenerator(response)) {
jsonGenerator.writeStartObject();
generateJsonInternal(request, response, jsonGenerator, accessTokenId,
refreshTokenId, timeout, service, registeredService, responseType);
jsonGenerator.writeEndObject();
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
throw Throwables.propagate(e);
}
} else {
generateTextInternal(request, response, accessTokenId, refreshTokenId, timeout);
}
}
示例6: generateTextInternal
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
/**
* Generate text internal.
*
* @param request the request
* @param response the response
* @param accessTokenId the access token id
* @param refreshTokenId the refresh token id
* @param timeout the timeout
*/
protected void generateTextInternal(final HttpServletRequest request,
final HttpServletResponse response,
final AccessToken accessTokenId,
final RefreshToken refreshTokenId,
final long timeout) {
final StringBuilder builder = new StringBuilder(
String.format("%s=%s&%s=%s", OAuth20Constants.ACCESS_TOKEN, accessTokenId.getId(),
OAuth20Constants.EXPIRES_IN, timeout));
if (refreshTokenId != null) {
builder.append('&')
.append(OAuth20Constants.REFRESH_TOKEN)
.append('=')
.append(refreshTokenId.getId());
}
OAuth20Utils.writeText(response, builder.toString(), HttpStatus.SC_OK);
}
示例7: generateJsonInternal
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
/**
* Generate internal.
*
* @param request the request
* @param response the response
* @param jsonGenerator the json generator
* @param accessTokenId the access token id
* @param refreshTokenId the refresh token id
* @param timeout the timeout
* @param service the service
* @param registeredService the registered service
* @param responseType the response type
* @throws Exception the exception
*/
protected void generateJsonInternal(final HttpServletRequest request,
final HttpServletResponse response,
final JsonGenerator jsonGenerator,
final AccessToken accessTokenId,
final RefreshToken refreshTokenId,
final long timeout,
final Service service,
final OAuthRegisteredService registeredService,
final OAuth20ResponseTypes responseType) throws Exception {
jsonGenerator.writeStringField(OAuth20Constants.ACCESS_TOKEN, accessTokenId.getId());
jsonGenerator.writeStringField(OAuth20Constants.TOKEN_TYPE, OAuth20Constants.TOKEN_TYPE_BEARER);
jsonGenerator.writeNumberField(OAuth20Constants.EXPIRES_IN, timeout);
if (refreshTokenId != null) {
jsonGenerator.writeStringField(OAuth20Constants.REFRESH_TOKEN, refreshTokenId.getId());
}
}
示例8: handleRequest
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
/**
* Handle request internal response entity.
*
* @param request the request
* @param response the response
* @return the response entity
* @throws Exception the exception
*/
@GetMapping(path = OAuth20Constants.BASE_OAUTH20_URL + '/' + OAuth20Constants.PROFILE_URL, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> handleRequest(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
final String accessToken = getAccessTokenFromRequest(request);
if (StringUtils.isBlank(accessToken)) {
LOGGER.error("Missing [{}]", OAuth20Constants.ACCESS_TOKEN);
return buildUnauthorizedResponseEntity(OAuth20Constants.MISSING_ACCESS_TOKEN);
}
final AccessToken accessTokenTicket = this.ticketRegistry.getTicket(accessToken, AccessToken.class);
if (accessTokenTicket == null || accessTokenTicket.isExpired()) {
LOGGER.error("Expired/Missing access token: [{}]", accessToken);
return buildUnauthorizedResponseEntity(OAuth20Constants.EXPIRED_ACCESS_TOKEN);
}
final TicketGrantingTicket ticketGrantingTicket = accessTokenTicket.getGrantingTicket();
if (ticketGrantingTicket == null || ticketGrantingTicket.isExpired()) {
LOGGER.error("Ticket granting ticket [{}] parenting access token [{}] has expired or is not found", ticketGrantingTicket, accessTokenTicket);
this.ticketRegistry.deleteTicket(accessToken);
return buildUnauthorizedResponseEntity(OAuth20Constants.EXPIRED_ACCESS_TOKEN);
}
updateAccessTokenUsage(accessTokenTicket);
final Map<String, Object> map = writeOutProfileResponse(accessTokenTicket);
final String value = OAuth20Utils.jsonify(map);
LOGGER.debug("Final user profile is [{}]",
JsonValue.readHjson(value).toString(Stringify.FORMATTED));
return new ResponseEntity<>(value, HttpStatus.OK);
}
示例9: generateAccessToken
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
/**
* Generate an access token from a service and authentication.
*
* @param responseHolder the response holder
* @return an access token
*/
protected AccessToken generateAccessToken(final AccessTokenRequestDataHolder responseHolder) {
LOGGER.debug("Creating refresh token for [{}]", responseHolder.getService());
final AccessToken accessToken = this.accessTokenFactory.create(responseHolder.getService(),
responseHolder.getAuthentication(), responseHolder.getTicketGrantingTicket());
LOGGER.debug("Creating access token [{}]", accessToken);
addTicketToRegistry(accessToken, responseHolder.getTicketGrantingTicket());
LOGGER.debug("Added access token [{}] to registry", accessToken);
if (responseHolder.getToken() instanceof OAuthCode) {
final TicketState codeState = TicketState.class.cast(responseHolder.getToken());
codeState.update();
if (responseHolder.getToken().isExpired()) {
this.ticketRegistry.deleteTicket(responseHolder.getToken().getId());
} else {
this.ticketRegistry.updateTicket(responseHolder.getToken());
}
this.ticketRegistry.updateTicket(responseHolder.getTicketGrantingTicket());
}
return accessToken;
}
示例10: verifyExpiredAccessToken
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
@Test
public void verifyExpiredAccessToken() throws Exception {
final Principal principal = CoreAuthenticationTestUtils.getPrincipal(ID, new HashMap<>());
final Authentication authentication = getAuthentication(principal);
final DefaultAccessTokenFactory expiringAccessTokenFactory = new DefaultAccessTokenFactory(new AlwaysExpiresExpirationPolicy());
final AccessToken accessToken = expiringAccessTokenFactory.create(CoreAuthenticationTestUtils.getService(), authentication,
new MockTicketGrantingTicket("casuser"));
this.ticketRegistry.addTicket(accessToken);
final MockHttpServletRequest mockRequest = new MockHttpServletRequest(GET, CONTEXT + OAuth20Constants.PROFILE_URL);
mockRequest.setParameter(OAuth20Constants.ACCESS_TOKEN, accessToken.getId());
final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
final ResponseEntity<String> entity = oAuth20ProfileController.handleRequest(mockRequest, mockResponse);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode());
assertEquals(CONTENT_TYPE, mockResponse.getContentType());
assertTrue(entity.getBody().contains(OAuth20Constants.EXPIRED_ACCESS_TOKEN));
}
示例11: buildCallbackUrlForImplicitTokenResponseType
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
private String buildCallbackUrlForImplicitTokenResponseType(J2EContext context, Authentication authentication, Service service, String redirectUri, String clientId, OAuth20ResponseTypes responseType, TicketGrantingTicket ticketGrantingTicket) {
try {
OidcRegisteredService e = (OidcRegisteredService) OAuth20Utils.getRegisteredOAuthService(this.servicesManager, clientId);
AccessTokenRequestDataHolder holder = new AccessTokenRequestDataHolder(service, authentication, e, ticketGrantingTicket);
AccessToken accessToken = this.generateAccessToken(holder);
LOGGER.debug("Generated OAuth access token: [{}]", accessToken);
long timeout = (long) this.casProperties.getTicket().getTgt().getTimeToKillInSeconds();
String idToken = this.idTokenGenerator.generate(context.getRequest(), context.getResponse(), accessToken, timeout, responseType, e);
LOGGER.debug("Generated id token [{}]", idToken);
ArrayList params = new ArrayList();
params.add(new BasicNameValuePair("id_token", idToken));
return this.buildCallbackUrlResponseType(authentication, service, redirectUri, accessToken, params);
} catch (Exception var15) {
throw Throwables.propagate(var15);
}
}
示例12: generate
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
/**
* Generate string.
*
* @param request the request
* @param response the response
* @param accessTokenId the access token id
* @param timeout the timeout
* @param responseType the response type
* @param registeredService the registered service
* @return the string
* @throws Exception the exception
*/
public String generate(final HttpServletRequest request,
final HttpServletResponse response,
final AccessToken accessTokenId,
final long timeout,
final OAuth20ResponseTypes responseType,
final OAuthRegisteredService registeredService) throws Exception {
final OidcRegisteredService oidcRegisteredService = (OidcRegisteredService) registeredService;
final J2EContext context = WebUtils.getPac4jJ2EContext(request, response);
final ProfileManager manager = WebUtils.getPac4jProfileManager(request, response);
final Optional<UserProfile> profile = manager.get(true);
LOGGER.debug("Attempting to produce claims for the id token [{}]", accessTokenId);
final JwtClaims claims = produceIdTokenClaims(request, accessTokenId, timeout,
oidcRegisteredService, profile.get(), context, responseType);
LOGGER.debug("Produce claims for the id token [{}] as [{}]", accessTokenId, claims);
return this.signingService.encode(oidcRegisteredService, claims);
}
示例13: buildCallbackUrlResponseType
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
protected String buildCallbackUrlResponseType(Authentication authentication, Service service, String redirectUri, AccessToken accessToken, List<NameValuePair> params) throws Exception {
String state = authentication.getAttributes().get("state").toString();
String nonce = authentication.getAttributes().get("nonce").toString();
URIBuilder builder = new URIBuilder(redirectUri);
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("access_token").append('=').append(accessToken.getId()).append('&').append("token_type").append('=').append("bearer").append('&').append("expires_in").append('=').append(this.casProperties.getTicket().getTgt().getTimeToKillInSeconds());
params.forEach((p) -> {
stringBuilder.append('&').append(p.getName()).append('=').append(p.getValue());
});
if(StringUtils.isNotBlank(state)) {
stringBuilder.append('&').append("state").append('=').append(EncodingUtils.urlEncode(state));
}
if(StringUtils.isNotBlank(nonce)) {
stringBuilder.append('&').append("nonce").append('=').append(EncodingUtils.urlEncode(nonce));
}
builder.setFragment(stringBuilder.toString());
String url = builder.toString();
return url;
}
示例14: create
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
@Override
public AccessToken create(Service service, Authentication authentication, TicketGrantingTicket ticketGrantingTicket, Collection<String> scopes) {
LOGGER.debug("Generating JWT Access Token");
LOGGER.debug("Attempting to produce claims for the access token of principal [{}]", authentication.getPrincipal().getId());
OidcRegisteredService registeredService = (OidcRegisteredService)servicesManager.findServiceBy(service);
final JwtClaims claims = produceIdTokenClaims(authentication, expirationPolicy.getTimeToLive(), registeredService);
LOGGER.debug("Produce claims for the access token of principal [{}] as [{}]", authentication.getPrincipal().getId(), claims);
String codeId = this.signingService.encode(registeredService, claims);
AccessToken at = new AccessTokenImpl(codeId, service, authentication, this.expirationPolicy, ticketGrantingTicket, scopes);
if (ticketGrantingTicket != null) {
ticketGrantingTicket.getDescendantTickets().add(at.getId());
}
return at;
}
示例15: configureTicketCatalog
import org.apereo.cas.ticket.accesstoken.AccessToken; //导入依赖的package包/类
@Override
public void configureTicketCatalog(final TicketCatalog plan) {
LOGGER.debug("Registering core OAuth protocol ticket definitions...");
buildAndRegisterOAuthCodeDefinition(plan, buildTicketDefinition(plan, OAuthCode.PREFIX, OAuthCodeImpl.class));
buildAndRegisterAccessTokenDefinition(plan, buildTicketDefinition(plan, AccessToken.PREFIX, AccessTokenImpl.class));
buildAndRegisterRefreshTokenDefinition(plan, buildTicketDefinition(plan, RefreshToken.PREFIX, RefreshTokenImpl.class));
}