Esempio n. 1
0
  private <I extends IdentityType> I extractIdentityTypeFromToken(
      JWSToken token,
      Class<I> identityType,
      StereotypeProperty.Property stereotypeProperty,
      Object identifier) {
    if (hasIdentityType(token, stereotypeProperty, identifier)) {
      try {
        I identityTypeInstance = Reflections.newInstance(identityType);
        Property property = resolveProperty(identityType, stereotypeProperty);

        property.setValue(identityTypeInstance, identifier);

        if (Account.class.isAssignableFrom(identityType)) {
          Property userNameProperty =
              resolveProperty(identityType, StereotypeProperty.Property.IDENTITY_ID);

          userNameProperty.setValue(identityTypeInstance, extractSubject(token));
        }

        return identityTypeInstance;
      } catch (Exception e) {
        throw new IdentityManagementException(
            "Could not extract IdentityType [" + identityType + "] from Token [" + token + "].", e);
      }
    }

    return null;
  }
  public IdentityConfigurationBuilder readIDMConfigurationFromIDMType(IDMType idmType) {
    IdentityConfigurationBuilder idmConfigBuilder = new IdentityConfigurationBuilder();

    Builder<?> currentBuilder = idmConfigBuilder;

    for (ConfigBuilderMethodType configBuilderMethodType : idmType.getBuilderMethods()) {
      String methodId = configBuilderMethodType.getMethodId();
      Map<String, String> methodParams = configBuilderMethodType.getMethodParameters();
      Method builderMethod = getBuilderMethod(currentBuilder.getClass(), methodId, methodParams);

      Object[] parameters = getMethodParameters(builderMethod, methodParams);
      currentBuilder =
          Reflections.invokeMethod(builderMethod, Builder.class, currentBuilder, parameters);
    }

    return idmConfigBuilder;
  }