@Parameters({"redirectUris"})
  @Test
  public void registerWithCustomURI(final String redirectUris) throws Exception {
    showTitle("requestClientAssociate1");

    List<String> redirectUriList =
        Lists.newArrayList(StringUtils.spaceSeparatedToList(redirectUris));
    redirectUriList.add("myschema://client.example.com/cb"); // URI with custom schema

    RegisterRequest registerRequest =
        new RegisterRequest(
            ApplicationType.NATIVE,
            "oxAuth native test app with custom schema in URI",
            redirectUriList);
    registerRequest.setSubjectType(SubjectType.PUBLIC);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setExecutor(clientExecutor(true));
    registerClient.setRequest(registerRequest);
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
  }
Пример #2
0
  /** Generates the sample collections that will be used in testing */
  private static HashMap<DataType, Object> getSampleCollections() {
    HashMap<DataType, Object> sampleCollections = new HashMap<DataType, Object>();
    HashMap<DataType, Object> setAndListCollection;
    HashMap<DataType, HashMap<DataType, Object>> mapCollection;

    for (DataType.Name dataTypeName : DATA_TYPE_NON_PRIMITIVE_NAMES) {
      switch (dataTypeName) {
        case LIST:
          for (DataType typeArgument : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument)) continue;

            List<Object> list = new ArrayList<Object>();
            for (int i = 0; i < 5; i++) {
              list.add(SAMPLE_DATA.get(typeArgument));
            }

            setAndListCollection = new HashMap<DataType, Object>();
            setAndListCollection.put(typeArgument, list);
            sampleCollections.put(DataType.list(typeArgument), setAndListCollection);
          }
          break;
        case SET:
          for (DataType typeArgument : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument)) continue;

            Set<Object> set = new HashSet<Object>();
            for (int i = 0; i < 5; i++) {
              set.add(SAMPLE_DATA.get(typeArgument));
            }

            setAndListCollection = new HashMap<DataType, Object>();
            setAndListCollection.put(typeArgument, set);
            sampleCollections.put(DataType.set(typeArgument), setAndListCollection);
          }
          break;
        case MAP:
          for (DataType typeArgument1 : DATA_TYPE_PRIMITIVES) {
            if (exclude(typeArgument1)) continue;

            for (DataType typeArgument2 : DATA_TYPE_PRIMITIVES) {
              if (exclude(typeArgument2)) continue;

              HashMap<DataType, Object> map = new HashMap<DataType, Object>();
              map.put(typeArgument1, SAMPLE_DATA.get(typeArgument2));

              mapCollection = new HashMap<DataType, HashMap<DataType, Object>>();
              mapCollection.put(typeArgument1, map);
              sampleCollections.put(DataType.map(typeArgument1, typeArgument2), mapCollection);
            }
          }
          break;
        default:
          throw new RuntimeException("Missing handling of " + dataTypeName);
      }
    }

    return sampleCollections;
  }
 @Test
 public void testEquals() {
   List<AmountFormatContext> contexts = new ArrayList<AmountFormatContext>();
   contexts.add(AmountFormatContextBuilder.of(Locale.ENGLISH).build());
   contexts.add(AmountFormatContextBuilder.of(Locale.GERMAN).build());
   Set<AmountFormatContext> checkContexts = new HashSet<AmountFormatContext>();
   for (AmountFormatContext amountFormatContext : contexts) {
     checkContexts.add(amountFormatContext);
   }
   // Check we have 5 distinct hash codes...
   assertTrue(checkContexts.size() == 2);
 }
Пример #4
0
  /** Generates the insert statements that will be used in testing */
  @SuppressWarnings("unchecked")
  private static Collection<String> getCollectionInsertStatements() {
    ArrayList<String> insertStatements = new ArrayList<String>();

    String tableName;
    String key;
    String value;
    for (DataType dataType : SAMPLE_COLLECTIONS.keySet()) {
      HashMap<DataType, Object> sampleValueMap =
          (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType);

      // Create tableName in form of: DataType_TypeArgument[_TypeArgument]
      tableName = helperGenerateTableName(dataType);

      if (dataType.getName() == DataType.Name.MAP) {
        List<DataType> typeArgument = dataType.getTypeArguments();

        key = helperStringifiedData(typeArgument.get(0));
        value = helperStringifiedData(typeArgument.get(1));

        insertStatements.add(String.format(MAP_INSERT_FORMAT, tableName, key, value));
      } else if (dataType.getName() == DataType.Name.LIST) {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        key = helperStringifiedData(typeArgument);

        // Create the value to be a list of the same 5 elements
        value = "[";
        for (int i = 0; i < 5; i++) value += key + ',';
        value = value.substring(0, value.length() - 1) + ']';

        insertStatements.add(String.format(COLLECTION_INSERT_FORMAT, tableName, key, value));
      } else {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        key = helperStringifiedData(typeArgument);
        value = '{' + key + '}';

        insertStatements.add(String.format(COLLECTION_INSERT_FORMAT, tableName, key, value));
      }
    }

    return insertStatements;
  }
  @Parameters({"redirectUris", "sectorIdentifierUri", "logoutUri"})
  @Test
  public void requestClientAssociate2(
      final String redirectUris, final String sectorIdentifierUri, final String logoutUri)
      throws Exception {
    showTitle("requestClientAssociate2");

    RegisterRequest registerRequest =
        new RegisterRequest(
            ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
    registerRequest.setContacts(Arrays.asList("*****@*****.**", "*****@*****.**"));
    registerRequest.setScopes(
        Arrays.asList(
            "openid", "address", "profile", "email", "phone", "clientinfo", "invalid_scope"));
    registerRequest.setLogoUri("http://www.gluu.org/wp-content/themes/gluursn/images/logo.png");
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    registerRequest.setPolicyUri("http://www.gluu.org/policy");
    registerRequest.setJwksUri("http://www.gluu.org/jwks");
    registerRequest.setSectorIdentifierUri(sectorIdentifierUri);
    registerRequest.setSubjectType(SubjectType.PAIRWISE);
    registerRequest.setRequestUris(Arrays.asList("http://www.gluu.org/request"));
    registerRequest.setFrontChannelLogoutUris(Lists.newArrayList(logoutUri));
    registerRequest.setFrontChannelLogoutSessionRequired(true);
    registerRequest.setIdTokenSignedResponseAlg(SignatureAlgorithm.RS512);
    registerRequest.setIdTokenEncryptedResponseAlg(KeyEncryptionAlgorithm.RSA1_5);
    registerRequest.setIdTokenEncryptedResponseEnc(BlockEncryptionAlgorithm.A128CBC_PLUS_HS256);
    registerRequest.setUserInfoSignedResponseAlg(SignatureAlgorithm.RS384);
    registerRequest.setUserInfoEncryptedResponseAlg(KeyEncryptionAlgorithm.A128KW);
    registerRequest.setUserInfoEncryptedResponseEnc(BlockEncryptionAlgorithm.A128GCM);
    registerRequest.setRequestObjectSigningAlg(SignatureAlgorithm.RS256);
    registerRequest.setRequestObjectEncryptionAlg(KeyEncryptionAlgorithm.A256KW);
    registerRequest.setRequestObjectEncryptionEnc(BlockEncryptionAlgorithm.A256CBC_PLUS_HS512);
    registerRequest.setTokenEndpointAuthMethod(AuthenticationMethod.CLIENT_SECRET_JWT);
    registerRequest.setTokenEndpointAuthSigningAlg(SignatureAlgorithm.ES256);

    RegisterClient registerClient = new RegisterClient(registrationEndpoint);
    registerClient.setRequest(registerRequest);
    registerClient.setExecutor(clientExecutor(true));
    RegisterResponse response = registerClient.exec();

    showClient(registerClient);
    assertEquals(response.getStatus(), 200, "Unexpected response code: " + response.getEntity());
    assertNotNull(response.getClientId());
    assertNotNull(response.getClientSecret());
    assertNotNull(response.getRegistrationAccessToken());
    assertNotNull(response.getClientSecretExpiresAt());
    assertNotNull(response.getClaims().get(SCOPES.toString()));
    assertNotNull(response.getClaims().get(FRONT_CHANNEL_LOGOUT_SESSION_REQUIRED.toString()));
    assertTrue(
        Boolean.parseBoolean(
            response.getClaims().get(FRONT_CHANNEL_LOGOUT_SESSION_REQUIRED.toString())));
    assertNotNull(response.getClaims().get(FRONT_CHANNEL_LOGOUT_URI.toString()));
    assertTrue(
        new JSONArray(response.getClaims().get(FRONT_CHANNEL_LOGOUT_URI.toString()))
            .getString(0)
            .equals(logoutUri));
    assertNotNull(response.getClaims().get(ID_TOKEN_SIGNED_RESPONSE_ALG.toString()));
    assertEquals(
        SignatureAlgorithm.RS512,
        SignatureAlgorithm.fromString(
            response.getClaims().get(ID_TOKEN_SIGNED_RESPONSE_ALG.toString())));
    assertNotNull(response.getClaims().get(ID_TOKEN_ENCRYPTED_RESPONSE_ALG.toString()));
    assertEquals(
        KeyEncryptionAlgorithm.RSA1_5,
        KeyEncryptionAlgorithm.fromName(
            response.getClaims().get(ID_TOKEN_ENCRYPTED_RESPONSE_ALG.toString())));
    assertNotNull(response.getClaims().get(ID_TOKEN_ENCRYPTED_RESPONSE_ENC.toString()));
    assertEquals(
        BlockEncryptionAlgorithm.A128CBC_PLUS_HS256,
        BlockEncryptionAlgorithm.fromName(
            response.getClaims().get(ID_TOKEN_ENCRYPTED_RESPONSE_ENC.toString())));
    assertNotNull(response.getClaims().get(USERINFO_SIGNED_RESPONSE_ALG.toString()));
    assertEquals(
        SignatureAlgorithm.RS384,
        SignatureAlgorithm.fromString(
            response.getClaims().get(USERINFO_SIGNED_RESPONSE_ALG.toString())));
    assertNotNull(response.getClaims().get(USERINFO_ENCRYPTED_RESPONSE_ALG.toString()));
    assertEquals(
        KeyEncryptionAlgorithm.A128KW,
        KeyEncryptionAlgorithm.fromName(
            response.getClaims().get(USERINFO_ENCRYPTED_RESPONSE_ALG.toString())));
    assertNotNull(response.getClaims().get(USERINFO_ENCRYPTED_RESPONSE_ENC.toString()));
    assertEquals(
        BlockEncryptionAlgorithm.A128GCM,
        BlockEncryptionAlgorithm.fromName(
            response.getClaims().get(USERINFO_ENCRYPTED_RESPONSE_ENC.toString())));
    assertNotNull(response.getClaims().get(REQUEST_OBJECT_SIGNING_ALG.toString()));
    assertEquals(
        SignatureAlgorithm.RS256,
        SignatureAlgorithm.fromString(
            response.getClaims().get(REQUEST_OBJECT_SIGNING_ALG.toString())));
    assertNotNull(response.getClaims().get(REQUEST_OBJECT_ENCRYPTION_ALG.toString()));
    assertEquals(
        KeyEncryptionAlgorithm.A256KW,
        KeyEncryptionAlgorithm.fromName(
            response.getClaims().get(REQUEST_OBJECT_ENCRYPTION_ALG.toString())));
    assertNotNull(response.getClaims().get(REQUEST_OBJECT_ENCRYPTION_ENC.toString()));
    assertEquals(
        BlockEncryptionAlgorithm.A256CBC_PLUS_HS512,
        BlockEncryptionAlgorithm.fromName(
            response.getClaims().get(REQUEST_OBJECT_ENCRYPTION_ENC.toString())));
    assertNotNull(response.getClaims().get(TOKEN_ENDPOINT_AUTH_METHOD.toString()));
    assertEquals(
        AuthenticationMethod.CLIENT_SECRET_JWT,
        AuthenticationMethod.fromString(
            response.getClaims().get(TOKEN_ENDPOINT_AUTH_METHOD.toString())));
    assertNotNull(response.getClaims().get(TOKEN_ENDPOINT_AUTH_SIGNING_ALG.toString()));
    assertEquals(
        SignatureAlgorithm.ES256,
        SignatureAlgorithm.fromString(
            response.getClaims().get(TOKEN_ENDPOINT_AUTH_SIGNING_ALG.toString())));
    JSONArray scopesJsonArray = new JSONArray(response.getClaims().get(SCOPES.toString()));
    List<String> scopes = new ArrayList<String>();
    for (int i = 0; i < scopesJsonArray.length(); i++) {
      scopes.add(scopesJsonArray.get(i).toString());
    }
    assertTrue(scopes.contains("openid"));
    assertTrue(scopes.contains("address"));
    assertTrue(scopes.contains("email"));
    assertTrue(scopes.contains("profile"));
    assertTrue(scopes.contains("phone"));
    assertTrue(scopes.contains("clientinfo"));

    clientId1 = response.getClientId();
    registrationAccessToken1 = response.getRegistrationAccessToken();
    registrationClientUri1 = response.getRegistrationClientUri();
  }