Example #1
0
 private static ServerAuthorizationCodeGrant recreateCodeGrantInternal(
     OAuthDataProvider provider, String sequence) {
   String[] parts = getParts(sequence);
   ServerAuthorizationCodeGrant grant =
       new ServerAuthorizationCodeGrant(
           provider.getClient(parts[0]), parts[1], Long.valueOf(parts[2]), Long.valueOf(parts[3]));
   grant.setRedirectUri(getStringPart(parts[4]));
   grant.setAudience(getStringPart(parts[5]));
   grant.setClientCodeVerifier(getStringPart(parts[6]));
   grant.setApprovedScopes(parseSimpleList(parts[7]));
   grant.setSubject(recreateUserSubject(parts[8]));
   return grant;
 }
 @GET
 @Produces({"application/json", "application/jwt"})
 public Response getUserInfo() {
   OAuthContext oauth = OAuthContextUtils.getContext(mc);
   UserInfo userInfo =
       userInfoProvider.getUserInfo(
           oauth.getClientId(), oauth.getSubject(), oauth.getPermissions());
   if (userInfo != null) {
     userInfo.setIssuer(issuer);
   }
   userInfo.setAudience(oauth.getClientId());
   Object responseEntity = userInfo;
   if (super.isJwsRequired() || super.isJweRequired()) {
     responseEntity =
         super.processJwt(
             new JwtToken(userInfo), oauthDataProvider.getClient(oauth.getClientId()));
   }
   return Response.ok(responseEntity).build();
 }
Example #3
0
  private static ServerAccessToken recreateAccessToken(
      OAuthDataProvider provider, String newTokenKey, String[] parts) {

    @SuppressWarnings("serial")
    final ServerAccessToken newToken =
        new ServerAccessToken(
            provider.getClient(parts[4]),
            parts[1],
            newTokenKey == null ? parts[0] : newTokenKey,
            Long.valueOf(parts[2]),
            Long.valueOf(parts[3])) {
          //
        };

    newToken.setRefreshToken(getStringPart(parts[5]));
    newToken.setGrantType(getStringPart(parts[6]));
    newToken.setAudience(getStringPart(parts[7]));
    newToken.setParameters(parseSimpleMap(parts[8]));

    // Permissions
    if (!parts[9].trim().isEmpty()) {
      List<OAuthPermission> perms = new LinkedList<OAuthPermission>();
      String[] allPermParts = parts[9].split("&");
      for (int i = 0; i + 4 < allPermParts.length; i = i + 5) {
        OAuthPermission perm = new OAuthPermission(allPermParts[i], allPermParts[i + 1]);
        perm.setDefault(Boolean.valueOf(allPermParts[i + 2]));
        perm.setHttpVerbs(parseSimpleList(allPermParts[i + 3]));
        perm.setUris(parseSimpleList(allPermParts[i + 4]));
        perms.add(perm);
      }
      newToken.setScopes(perms);
    }
    // UserSubject:
    newToken.setSubject(recreateUserSubject(parts[10]));

    return newToken;
  }