public Directory buildInternalDirectory(InternalDirectoryConfiguration configuration) {
    ImmutableDirectory.Builder builder = createBuilder();
    builder.setAllowedOperations(EnumSet.allOf(OperationType.class));
    builder.setActive(configuration.isActive());
    builder.setId(configuration.getDirectoryId());
    builder.setImplementationClass(InternalDirectory.class.getName());
    builder.setName(configuration.getName());
    builder.setType(DirectoryType.INTERNAL);

    HashMap<String, String> map = new HashMap<String, String>();
    map.put(
        InternalDirectory.ATTRIBUTE_USER_ENCRYPTION_METHOD,
        PasswordEncoderFactory.ATLASSIAN_SECURITY_ENCODER);
    map.put(
        DirectoryImpl.ATTRIBUTE_KEY_USE_NESTED_GROUPS,
        Boolean.valueOf(configuration.isNestedGroupsEnabled()).toString());
    builder.setAttributes(map);

    return builder.toDirectory();
  }
  public InternalDirectoryConfiguration toInternalConfiguration(Directory directory) {
    InternalDirectoryConfiguration configuration = new InternalDirectoryConfiguration();
    configuration.setDirectoryId(directory.getId() != null ? directory.getId() : 0);
    configuration.setActive(directory.isActive());
    configuration.setName(directory.getName());

    Map<String, String> attributes = directory.getAttributes();
    String useNestedGroups = attributes.get(DirectoryImpl.ATTRIBUTE_KEY_USE_NESTED_GROUPS);
    if (useNestedGroups != null) {
      configuration.setNestedGroupsEnabled(Boolean.valueOf(useNestedGroups));
    } else {
      configuration.setNestedGroupsEnabled(false);
    }

    return configuration;
  }