Package com.nimbusds.oauth2.sdk

Examples of com.nimbusds.oauth2.sdk.ParseException


    Map<String,String> params = request.getQueryParameters();

    String accessTokenValue = params.get("access_token");

    if (StringUtils.isBlank(accessTokenValue))
      throw new ParseException("Missing access token value", BearerTokenError.MISSING_TOKEN);
     
    return new BearerAccessToken(accessTokenValue);
  }
View Full Code Here


        try {
          redirectURIs.add(new URI(uriString));

        } catch (URISyntaxException e) {

          throw new ParseException("Invalid \"redirect_uris\" parameter: " +
                              e.getMessage());
        }
      }

      metadata.setRedirectionURIs(redirectURIs);
      jsonObject.remove("redirect_uris");
    }


    if (jsonObject.containsKey("scope")) {
      metadata.setScope(Scope.parse(JSONObjectUtils.getString(jsonObject, "scope")));
      jsonObject.remove("scope");
    }


    if (jsonObject.containsKey("response_types")) {

      Set<ResponseType> responseTypes = new LinkedHashSet<>();

      for (String rt: JSONObjectUtils.getStringArray(jsonObject, "response_types")) {

        responseTypes.add(ResponseType.parse(rt));
      }

      metadata.setResponseTypes(responseTypes);
      jsonObject.remove("response_types");
    }


    if (jsonObject.containsKey("grant_types")) {

      Set<GrantType> grantTypes = new LinkedHashSet<>();

      for (String grant: JSONObjectUtils.getStringArray(jsonObject, "grant_types")) {

        grantTypes.add(GrantType.parse(grant));
      }

      metadata.setGrantTypes(grantTypes);
      jsonObject.remove("grant_types");
    }


    if (jsonObject.containsKey("contacts")) {

      List<InternetAddress> emailList = new LinkedList<>();

      for (String emailString: JSONObjectUtils.getStringArray(jsonObject, "contacts")) {

        try {
          emailList.add(new InternetAddress(emailString));

        } catch (AddressException e) {

          throw new ParseException("Invalid \"contacts\" parameter: " +
                       e.getMessage());
        }
      }

      metadata.setContacts(emailList);
      jsonObject.remove("contacts");
    }


    // Find lang-tagged client_name params
    Map<LangTag,Object> matches = LangTagUtils.find("client_name", jsonObject);

    for (Map.Entry<LangTag,Object> entry: matches.entrySet()) {

      try {
        metadata.setName((String)entry.getValue(), entry.getKey());

      } catch (ClassCastException e) {

        throw new ParseException("Invalid \"client_name\" (language tag) parameter");
      }

      removeMember(jsonObject, "client_name", entry.getKey());
    }


    matches = LangTagUtils.find("logo_uri", jsonObject);

    for (Map.Entry<LangTag,Object> entry: matches.entrySet()) {

      try {
        metadata.setLogoURI(new URI((String)entry.getValue()), entry.getKey());

      } catch (Exception e) {

        throw new ParseException("Invalid \"logo_uri\" (language tag) parameter");
      }

      removeMember(jsonObject, "logo_uri", entry.getKey());
    }


    matches = LangTagUtils.find("client_uri", jsonObject);

    for (Map.Entry<LangTag,Object> entry: matches.entrySet()) {

      try {
        metadata.setURI(new URI((String)entry.getValue()), entry.getKey());


      } catch (Exception e) {

        throw new ParseException("Invalid \"client_uri\" (language tag) parameter");
      }

      removeMember(jsonObject, "client_uri", entry.getKey());
    }


    matches = LangTagUtils.find("policy_uri", jsonObject);

    for (Map.Entry<LangTag,Object> entry: matches.entrySet()) {

      try {
        metadata.setPolicyURI(new URI((String)entry.getValue()), entry.getKey());

      } catch (Exception e) {

        throw new ParseException("Invalid \"policy_uri\" (language tag) parameter");
      }

      removeMember(jsonObject, "policy_uri", entry.getKey());
    }


    matches = LangTagUtils.find("tos_uri", jsonObject);

    for (Map.Entry<LangTag,Object> entry: matches.entrySet()) {

      try {
        metadata.setTermsOfServiceURI(new URI((String)entry.getValue()), entry.getKey());

      } catch (Exception e) {

        throw new ParseException("Invalid \"tos_uri\" (language tag) parameter");
      }

      removeMember(jsonObject, "tos_uri", entry.getKey());
    }


    if (jsonObject.containsKey("token_endpoint_auth_method")) {
      metadata.setTokenEndpointAuthMethod(new ClientAuthenticationMethod(
        JSONObjectUtils.getString(jsonObject, "token_endpoint_auth_method")));

      jsonObject.remove("token_endpoint_auth_method");
    }


    if (jsonObject.containsKey("jwks_uri")) {
      metadata.setJWKSetURI(JSONObjectUtils.getURI(jsonObject, "jwks_uri"));
      jsonObject.remove("jwks_uri");
    }

    if (jsonObject.containsKey("jwks")) {

      try {
        metadata.setJWKSet(JWKSet.parse(JSONObjectUtils.getJSONObject(jsonObject, "jwks")));

      } catch (java.text.ParseException e) {
        throw new ParseException(e.getMessage(), e);
      }

      jsonObject.remove("jwks");
    }
View Full Code Here

  public static BearerTokenError parse(final String wwwAuth)
    throws ParseException {

    // We must have a WWW-Authenticate header set to Bearer .*
    if (! wwwAuth.regionMatches(true, 0, "Bearer", 0, "Bearer".length()))
      throw new ParseException("WWW-Authenticate scheme must be OAuth 2.0 Bearer");
   
    Matcher m;
   
    // Parse optional realm
    m = realmPattern.matcher(wwwAuth);
   
    String realm = null;
   
    if (m.find())
      realm = m.group(1);
   
   
    // Parse optional error
    String errorCode = null;
    String errorDescription = null;
    URI errorURI = null;

    m = errorPattern.matcher(wwwAuth);
   
    if (m.find()) {

      errorCode = m.group(1);

      // Parse optional error description
      m = errorDescriptionPattern.matcher(wwwAuth);

      if (m.find())
        errorDescription = m.group(1);

     
      // Parse optional error URI
      m = errorURIPattern.matcher(wwwAuth);
     
      if (m.find()) {
     
        try {
          errorURI = new URI(m.group(1));
         
        } catch (URISyntaxException e) {
       
          throw new ParseException("Invalid error URI: " + m.group(1), e);
        }
      }
    }


View Full Code Here

      try {
        stmt = SignedJWT.parse(JSONObjectUtils.getString(jsonObject, "software_statement"));

      } catch (java.text.ParseException e) {

        throw new ParseException("Invalid software statement JWT: " + e.getMessage());
      }

      // Prevent the JWT from appearing in the metadata
      jsonObject.remove("software_statement");
    }

    // Parse the client metadata
    ClientMetadata metadata = ClientMetadata.parse(jsonObject);

    // Parse the optional bearer access token
    BearerAccessToken accessToken = null;
   
    String authzHeaderValue = httpRequest.getAuthorization();
   
    if (StringUtils.isNotBlank(authzHeaderValue))
      accessToken = BearerAccessToken.parse(authzHeaderValue);

    try {
      URI endpointURI = httpRequest.getURL().toURI();

      return new ClientRegistrationRequest(endpointURI, metadata, stmt, accessToken);

    } catch (URISyntaxException | IllegalArgumentException e) {

      throw new ParseException(e.getMessage(), e);
    }
  }
View Full Code Here

    try {
      endpointURI = httpRequest.getURL().toURI();

    } catch (URISyntaxException e) {

      throw new ParseException(e.getMessage(), e);
    }
   
    return new ClientReadRequest(endpointURI, accessToken);
  }
View Full Code Here

    try {
      endpointURI = httpRequest.getURL().toURI();

    } catch (URISyntaxException e) {

      throw new ParseException(e.getMessage(), e);
    }

    return new ClientUpdateRequest(endpointURI, id, accessToken, metadata, clientSecret);
  }
View Full Code Here

      try {
        claimsSet = new UserInfo(httpResponse.getContentAsJSONObject());
       
      } catch (Exception e) {
       
        throw new ParseException("Couldn't parse UserInfo claims: " +
                           e.getMessage(), e);
      }
     
      response = new UserInfoSuccessResponse(claimsSet);
    }
    else if (ct.match(CommonContentTypes.APPLICATION_JWT)) {
   
      JWT jwt;
     
      try {
        jwt = httpResponse.getContentAsJWT();
       
      } catch (ParseException e) {
     
        throw new ParseException("Couldn't parse UserInfo claims JWT: " +
                           e.getMessage(), e);
      }
     
      response = new UserInfoSuccessResponse(jwt);
    }
    else {
      throw new ParseException("Unexpected Content-Type, must be " +
                               CommonContentTypes.APPLICATION_JSON +
             " or " +
             CommonContentTypes.APPLICATION_JWT);
    }
   
View Full Code Here

      endpointURI = httpRequest.getURL().toURI();

    } catch (URISyntaxException e) {

      throw new ParseException(e.getMessage(), e);
    }
 
    return new UserInfoRequest(endpointURI, httpMethod, accessToken);
  }
View Full Code Here

   
    for (String s: collection)
      prompt.add(Prompt.Type.parse(s));
   
    if (! prompt.isValid())
      throw new ParseException("Invalid prompt: " + collection);
   
    return prompt; 
  }
View Full Code Here

    while (st.hasMoreTokens())
      prompt.add(Prompt.Type.parse(st.nextToken()));
   
    if (! prompt.isValid())
      throw new ParseException("Invalid prompt: " + s);
   
    return prompt;
  }
View Full Code Here

TOP

Related Classes of com.nimbusds.oauth2.sdk.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.