Package com.nimbusds.oauth2.sdk.id

Examples of com.nimbusds.oauth2.sdk.id.Issuer


    if (StringUtils.isBlank(v))
      throw new ParseException("Missing \"client_id\" parameter",
        OAuth2Error.INVALID_REQUEST);

    ClientID clientID = new ClientID(v);


    // Parse optional redirection URI second
    v = params.get("redirect_uri");
View Full Code Here


    if (clientIDString == null)
      return null;

    else
      return new ClientID(clientIDString);
  }
View Full Code Here

    try {
      String decodedClientID = URLDecoder.decode(credentials[0], UTF8_CHARSET.name());
      String decodedSecret = URLDecoder.decode(credentials[1], UTF8_CHARSET.name());

      return new ClientSecretBasic(new ClientID(decodedClientID), new Secret(decodedSecret));
     
    } catch (UnsupportedEncodingException e) {
   
      throw new ParseException(e.getMessage(), e);
    }
View Full Code Here

  public void testWithAccessTokenAndClientAuth()
    throws Exception {

    URI endpointURI = new URI("https://c2id.com/token/revoke");
    Token token = new BearerAccessToken();
    ClientAuthentication clientAuth = new ClientSecretBasic(new ClientID("123"), new Secret("secret"));

    TokenRevocationRequest request = new TokenRevocationRequest(endpointURI, clientAuth, token);
    assertEquals(endpointURI, request.getEndpointURI());
    assertEquals(clientAuth, request.getClientAuthentication());
    assertEquals(token, request.getToken());
View Full Code Here

  public void testWithRefreshTokenAndClientAuth()
    throws Exception {

    URI endpointURI = new URI("https://c2id.com/token/revoke");
    Token token = new RefreshToken();
    ClientAuthentication clientAuth = new ClientSecretBasic(new ClientID("123"), new Secret("secret"));

    TokenRevocationRequest request = new TokenRevocationRequest(endpointURI, clientAuth, token);
    assertEquals(endpointURI, request.getEndpointURI());
    assertEquals(clientAuth, request.getClientAuthentication());
    assertEquals(token, request.getToken());
View Full Code Here

            final JWTID jti) {

    if (clientID == null)
      throw new IllegalArgumentException("The client ID must not be null");

    iss = new Issuer(clientID.getValue());

    sub = new Subject(clientID.getValue());

   
    if (aud == null)
View Full Code Here

   */
  public static JWTAuthenticationClaimsSet parse(final JSONObject jsonObject)
    throws ParseException {
   
    // Parse required claims
    Issuer iss = new Issuer(JSONObjectUtils.getString(jsonObject, "iss"));
    Subject sub = new Subject(JSONObjectUtils.getString(jsonObject, "sub"));

    Audience aud;

    if (jsonObject.get("aud") instanceof String) {

      aud = new Audience(JSONObjectUtils.getString(jsonObject, "aud"));

    } else {
      String[] audList = JSONObjectUtils.getStringArray(jsonObject, "aud");

      if (audList.length > 1)
        throw new ParseException("Multiple audiences (aud) not supported");

      aud = new Audience(audList[0]);
    }

    Date exp = DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(jsonObject, "exp"));


    // Parse optional claims

    Date nbf = null;

    if (jsonObject.containsKey("nbf"))
      nbf = DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(jsonObject, "nbf"));

    Date iat = null;

    if (jsonObject.containsKey("iat"))
      iat = DateUtils.fromSecondsSinceEpoch(JSONObjectUtils.getLong(jsonObject, "iat"));

    JWTID jti = null;

    if (jsonObject.containsKey("jti"))
      jti = new JWTID(JSONObjectUtils.getString(jsonObject, "jti"));


    // Check client ID

    if (! iss.getValue().equals(sub.getValue()))
      throw new ParseException("JWT issuer and subject must have the same client ID");

    ClientID clientID = new ClientID(iss.getValue());

    return new JWTAuthenticationClaimsSet(clientID, aud, exp, nbf, iat, jti);
  }
View Full Code Here


  public void testGettersAndSetters()
    throws Exception {

    Issuer issuer = new Issuer("https://c2id.com");

    List<SubjectType> subjectTypes = new LinkedList<>();
    subjectTypes.add(SubjectType.PAIRWISE);
    subjectTypes.add(SubjectType.PUBLIC);

    URI jwkSetURI = new URI("https://c2id.com/jwks.json");

    OIDCProviderMetadata meta = new OIDCProviderMetadata(issuer, subjectTypes, jwkSetURI);

    assertEquals(issuer.getValue(), meta.getIssuer().getValue());
    assertEquals(SubjectType.PAIRWISE, meta.getSubjectTypes().get(0));
    assertEquals(SubjectType.PUBLIC, meta.getSubjectTypes().get(1));
    assertEquals(jwkSetURI.toString(), meta.getJWKSetURI().toString());

    meta.setAuthorizationEndpointURI(new URI("https://c2id.com/authz"));
    assertEquals("https://c2id.com/authz", meta.getAuthorizationEndpointURI().toString());

    meta.setTokenEndpointURI(new URI("https://c2id.com/token"));
    assertEquals("https://c2id.com/token", meta.getTokenEndpointURI().toString());

    meta.setUserInfoEndpointURI(new URI("https://c2id.com/userinfo"));
    assertEquals("https://c2id.com/userinfo", meta.getUserInfoEndpointURI().toString());

    meta.setRegistrationEndpointURI(new URI("https://c2id.com/reg"));
    assertEquals("https://c2id.com/reg", meta.getRegistrationEndpointURI().toString());

    meta.setCheckSessionIframeURI(new URI("https://c2id.com/session"));
    assertEquals("https://c2id.com/session", meta.getCheckSessionIframeURI().toString());

    meta.setEndSessionEndpointURI(new URI("https://c2id.com/logout"));
    assertEquals("https://c2id.com/logout", meta.getEndSessionEndpointURI().toString());

    meta.setScopes(Scope.parse("openid email profile"));
    assertTrue(Scope.parse("openid email profile").containsAll(meta.getScopes()));

    List<ResponseType> responseTypes = new LinkedList<>();
    ResponseType rt1 = new ResponseType();
    rt1.add(ResponseType.Value.CODE);
    responseTypes.add(rt1);
    meta.setResponseTypes(responseTypes);
    responseTypes = meta.getResponseTypes();
    assertEquals(ResponseType.Value.CODE, responseTypes.iterator().next().iterator().next());
    assertEquals(1, responseTypes.size());

    List<ResponseMode> responseModes = new LinkedList<>();
    responseModes.add(ResponseMode.QUERY);
    responseModes.add(ResponseMode.FRAGMENT);
    meta.setResponseModes(responseModes);
    assertTrue(meta.getResponseModes().contains(ResponseMode.QUERY));
    assertTrue(meta.getResponseModes().contains(ResponseMode.FRAGMENT));
    assertEquals(2, meta.getResponseModes().size());

    List<GrantType> grantTypes = new LinkedList<>();
    grantTypes.add(GrantType.AUTHORIZATION_CODE);
    grantTypes.add(GrantType.REFRESH_TOKEN);
    meta.setGrantTypes(grantTypes);
    assertTrue(meta.getGrantTypes().contains(GrantType.AUTHORIZATION_CODE));
    assertTrue(meta.getGrantTypes().contains(GrantType.REFRESH_TOKEN));
    assertEquals(2, meta.getGrantTypes().size());

    List<ACR> acrList = new LinkedList<>();
    acrList.add(new ACR("1"));
    meta.setACRs(acrList);
    assertEquals("1", meta.getACRs().get(0).getValue());

    List<ClientAuthenticationMethod> authMethods = new LinkedList<>();
    authMethods.add(ClientAuthenticationMethod.CLIENT_SECRET_BASIC);
    meta.setTokenEndpointAuthMethods(authMethods);
    assertEquals(ClientAuthenticationMethod.CLIENT_SECRET_BASIC, meta.getTokenEndpointAuthMethods().get(0));

    List<JWSAlgorithm> tokenEndpointJWSAlgs = new LinkedList<>();
    tokenEndpointJWSAlgs.add(JWSAlgorithm.HS256);
    tokenEndpointJWSAlgs.add(JWSAlgorithm.HS384);
    tokenEndpointJWSAlgs.add(JWSAlgorithm.HS512);
    meta.setTokenEndpointJWSAlgs(tokenEndpointJWSAlgs);
    assertEquals(JWSAlgorithm.HS256, meta.getTokenEndpointJWSAlgs().get(0));
    assertEquals(JWSAlgorithm.HS384, meta.getTokenEndpointJWSAlgs().get(1));
    assertEquals(JWSAlgorithm.HS512, meta.getTokenEndpointJWSAlgs().get(2));

    List<JWSAlgorithm> requestObjectJWSAlgs = new LinkedList<>();
    requestObjectJWSAlgs.add(JWSAlgorithm.HS256);
    meta.setRequestObjectJWSAlgs(requestObjectJWSAlgs);
    assertEquals(JWSAlgorithm.HS256, meta.getRequestObjectJWSAlgs().get(0));

    List<JWEAlgorithm> requestObjectJWEAlgs = new LinkedList<>();
    requestObjectJWEAlgs.add(JWEAlgorithm.A128KW);
    meta.setRequestObjectJWEAlgs(requestObjectJWEAlgs);
    assertEquals(JWEAlgorithm.A128KW, meta.getRequestObjectJWEAlgs().get(0));

    List<EncryptionMethod> requestObjectEncs = new LinkedList<>();
    requestObjectEncs.add(EncryptionMethod.A128GCM);
    meta.setRequestObjectJWEEncs(requestObjectEncs);
    assertEquals(EncryptionMethod.A128GCM, meta.getRequestObjectJWEEncs().get(0));

    List<JWSAlgorithm> idTokenJWSAlgs = new LinkedList<>();
    idTokenJWSAlgs.add(JWSAlgorithm.RS256);
    meta.setIdTokenJWSAlgs(idTokenJWSAlgs);
    assertEquals(JWSAlgorithm.RS256, meta.getIDTokenJWSAlgs().get(0));

    List<JWEAlgorithm> idTokenJWEalgs = new LinkedList<>();
    idTokenJWEalgs.add(JWEAlgorithm.A256KW);
    meta.setIDTokenJWEAlgs(idTokenJWEalgs);

    List<EncryptionMethod> idTokenEncs = new LinkedList<>();
    idTokenEncs.add(EncryptionMethod.A128GCM);
    meta.setIdTokenJWEEncs(idTokenEncs);
    assertEquals(EncryptionMethod.A128GCM, meta.getIDTokenJWEEncs().get(0));

    List<JWSAlgorithm> userInfoJWSAlgs = new LinkedList<>();
    userInfoJWSAlgs.add(JWSAlgorithm.RS256);
    meta.setUserInfoJWSAlgs(userInfoJWSAlgs);
    assertEquals(JWSAlgorithm.RS256, meta.getUserInfoJWSAlgs().get(0));

    List<JWEAlgorithm> userInfoJWEAlgs = new LinkedList<>();
    userInfoJWEAlgs.add(JWEAlgorithm.RSA1_5);
    meta.setUserInfoJWEAlgs(userInfoJWEAlgs);
    assertEquals(JWEAlgorithm.RSA1_5, meta.getUserInfoJWEAlgs().get(0));

    List<EncryptionMethod> userInfoEncs = new LinkedList<>();
    userInfoEncs.add(EncryptionMethod.A128CBC_HS256);
    meta.setUserInfoJWEEncs(userInfoEncs);
    assertEquals(EncryptionMethod.A128CBC_HS256, meta.getUserInfoJWEEncs().get(0));

    List<Display> displays = new LinkedList<>();
    displays.add(Display.PAGE);
    displays.add(Display.POPUP);
    meta.setDisplays(displays);
    assertEquals(Display.PAGE, meta.getDisplays().get(0));
    assertEquals(Display.POPUP, meta.getDisplays().get(1));
    assertEquals(2, meta.getDisplays().size());

    List<ClaimType> claimTypes = new LinkedList<>();
    claimTypes.add(ClaimType.NORMAL);
    meta.setClaimTypes(claimTypes);
    assertEquals(ClaimType.NORMAL, meta.getClaimTypes().get(0));

    List<String> claims = new LinkedList<>();
    claims.add("name");
    claims.add("email");
    meta.setClaims(claims);
    assertEquals("name", meta.getClaims().get(0));
    assertEquals("email", meta.getClaims().get(1));
    assertEquals(2, meta.getClaims().size());

    List<LangTag> claimLocales = new LinkedList<>();
    claimLocales.add(LangTag.parse("en-GB"));
    meta.setClaimLocales(claimLocales);
    assertEquals("en-GB", meta.getClaimsLocales().get(0).toString());

    List<LangTag> uiLocales = new LinkedList<>();
    uiLocales.add(LangTag.parse("bg-BG"));
    meta.setUILocales(uiLocales);
    assertEquals("bg-BG", meta.getUILocales().get(0).toString());

    meta.setServiceDocsURI(new URI("https://c2id.com/docs"));
    assertEquals("https://c2id.com/docs", meta.getServiceDocsURI().toString());

    meta.setPolicyURI(new URI("https://c2id.com/policy"));
    assertEquals("https://c2id.com/policy", meta.getPolicyURI().toString());

    meta.setTermsOfServiceURI(new URI("https://c2id.com/tos"));
    assertEquals("https://c2id.com/tos", meta.getTermsOfServiceURI().toString());

    meta.setSupportsClaimsParams(true);
    assertTrue(meta.supportsClaimsParam());

    meta.setSupportsRequestParam(true);
    assertTrue(meta.supportsRequestParam());

    meta.setSupportsRequestURIParam(true);
    assertTrue(meta.supportsRequestURIParam());

    meta.setRequiresRequestURIRegistration(true);
    assertTrue(meta.requiresRequestURIRegistration());

    String json = meta.toJSONObject().toJSONString();

    meta = OIDCProviderMetadata.parse(JSONObjectUtils.parseJSONObject(json));

    assertEquals(issuer.getValue(), meta.getIssuer().getValue());
    assertEquals(SubjectType.PAIRWISE, meta.getSubjectTypes().get(0));
    assertEquals(SubjectType.PUBLIC, meta.getSubjectTypes().get(1));
    assertEquals(jwkSetURI.toString(), meta.getJWKSetURI().toString());

    assertEquals("https://c2id.com/authz", meta.getAuthorizationEndpointURI().toString());
View Full Code Here


  public void testRejectNoneAlgForTokenJWTAuth()
    throws Exception {

    Issuer issuer = new Issuer("https://c2id.com");

    List<SubjectType> subjectTypes = new ArrayList<>();
    subjectTypes.add(SubjectType.PUBLIC);

    URI jwksURI = new URI("https://c2id.com/jwks.json");
View Full Code Here


  public void testApplyDefaults()
    throws Exception {

    Issuer issuer = new Issuer("https://c2id.com");

    List<SubjectType> subjectTypes = new ArrayList<>();
    subjectTypes.add(SubjectType.PUBLIC);

    URI jwksURI = new URI("https://c2id.com/jwks.json");
View Full Code Here

TOP

Related Classes of com.nimbusds.oauth2.sdk.id.Issuer

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.