DefaultSyncConfigImpl extends DefaultSyncConfig { public static DefaultSyncConfig of(ConfigurationParameters params) { DefaultSyncConfig cfg = new DefaultSyncConfigImpl() .setName(params.getConfigValue(PARAM_NAME, PARAM_NAME_DEFAULT)); cfg.user() .setDisableMissing(params.getConfigValue(PARAM_DISABLE_MISSING_USERS, PARAM_DISABLE_MISSING_USERS_DEFAULT)) .setMembershipExpirationTime(getMilliSeconds(params, PARAM_USER_MEMBERSHIP_EXPIRATION_TIME, PARAM_USER_MEMBERSHIP_EXPIRATION_TIME_DEFAULT, ONE_HOUR)) .setMembershipNestingDepth(params.getConfigValue(PARAM_USER_MEMBERSHIP_NESTING_DEPTH, PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT)) .setDynamicMembership(params.getConfigValue(PARAM_USER_DYNAMIC_MEMBERSHIP, PARAM_USER_DYNAMIC_MEMBERSHIP_DEFAULT)) .setExpirationTime(getMilliSeconds(params, PARAM_USER_EXPIRATION_TIME, PARAM_USER_EXPIRATION_TIME_DEFAULT, ONE_HOUR)) .setApplyRFC7613UsernameCaseMapped(params.getConfigValue(PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE, PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE_DEFAULT)) .setPathPrefix(params.getConfigValue(PARAM_USER_PATH_PREFIX, PARAM_USER_PATH_PREFIX_DEFAULT)) .setAutoMembership(params.getConfigValue(PARAM_USER_AUTO_MEMBERSHIP, PARAM_USER_AUTO_MEMBERSHIP_DEFAULT)) .setPropertyMapping(createMapping( params.getConfigValue(PARAM_USER_PROPERTY_MAPPING, PARAM_USER_PROPERTY_MAPPING_DEFAULT))); cfg.group() .setExpirationTime(getMilliSeconds(params, PARAM_GROUP_EXPIRATION_TIME, PARAM_GROUP_EXPIRATION_TIME_DEFAULT, ONE_DAY)) .setApplyRFC7613UsernameCaseMapped(params.getConfigValue(PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE, PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE_DEFAULT)) .setPathPrefix(params.getConfigValue(PARAM_GROUP_PATH_PREFIX, PARAM_GROUP_PATH_PREFIX_DEFAULT)) .setAutoMembership(params.getConfigValue(PARAM_GROUP_AUTO_MEMBERSHIP, PARAM_GROUP_AUTO_MEMBERSHIP_DEFAULT)) .setPropertyMapping(createMapping( params.getConfigValue(PARAM_GROUP_PROPERTY_MAPPING, PARAM_GROUP_PROPERTY_MAPPING_DEFAULT))); return cfg; }  static DefaultSyncConfig of(ConfigurationParameters params); static final String PARAM_NAME_DEFAULT; @Property(
            label = "Sync Handler Name",
            description = "Name of this sync configuration. This is used to reference this handler by the login modules.",
            value = PARAM_NAME_DEFAULT
    )
    static final String PARAM_NAME; static final String PARAM_USER_EXPIRATION_TIME_DEFAULT; @Property(
            label = "User Expiration Time",
            description = "Duration until a synced user gets expired (eg. '1h 30m' or '1d').",
            value = PARAM_USER_EXPIRATION_TIME_DEFAULT
    )
    static final String PARAM_USER_EXPIRATION_TIME; static final String[] PARAM_USER_AUTO_MEMBERSHIP_DEFAULT; @Property(
            label = "User auto membership",
            description = "List of groups that a synced user is added to automatically",
            value = {},
            cardinality = Integer.MAX_VALUE
    )
    static final String PARAM_USER_AUTO_MEMBERSHIP; static final String[] PARAM_USER_PROPERTY_MAPPING_DEFAULT; @Property(
            label = "User property mapping",
            description = "List mapping definition of local properties from external ones. eg: 'profile/email=mail'." +
                    "Use double quotes for fixed values. eg: 'profile/nt:primaryType=\"nt:unstructured\"",
            value = {"rep:fullname=cn"},
            cardinality = Integer.MAX_VALUE
    )
    static final String PARAM_USER_PROPERTY_MAPPING; static final String PARAM_USER_PATH_PREFIX_DEFAULT; @Property(
            label = "User Path Prefix",
            description = "The path prefix used when creating new users.",
            value = PARAM_USER_PATH_PREFIX_DEFAULT
    )
    static final String PARAM_USER_PATH_PREFIX; static final String PARAM_USER_MEMBERSHIP_EXPIRATION_TIME_DEFAULT; @Property(
            label = "User Membership Expiration",
            description = "Time after which membership expires (eg. '1h 30m' or '1d'). Note however, that a membership sync is aways bound to a sync of the user.",
            value = PARAM_USER_MEMBERSHIP_EXPIRATION_TIME_DEFAULT
    )
    static final String PARAM_USER_MEMBERSHIP_EXPIRATION_TIME; static final int PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT; @Property(
            label = "User membership nesting depth",
            description = "Returns the maximum depth of group nesting when membership relations are synced. " +
                    "A value of 0 effectively disables group membership lookup. A value of 1 only adds the direct " +
                    "groups of a user. This value has no effect when syncing individual groups only when syncing a " +
                    "users membership ancestry.",
            intValue = PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT
    )
    static final String PARAM_USER_MEMBERSHIP_NESTING_DEPTH; static final boolean PARAM_USER_DYNAMIC_MEMBERSHIP_DEFAULT; @Property(
            label = "User Dynamic Membership",
            description = "If enabled membership of external identities (user) is no longer fully reflected " +
                    "within the repositories user management.",
            boolValue = PARAM_USER_DYNAMIC_MEMBERSHIP_DEFAULT
    )
    static final String PARAM_USER_DYNAMIC_MEMBERSHIP; static final boolean PARAM_DISABLE_MISSING_USERS_DEFAULT; @Property(
        label = "Disable missing users",
        description = "If true, users that no longer exist on the external provider will be locally disabled, " +
            "and re-enabled if they become valid again. If false (default) they will be removed.",
        boolValue = false
    )
    static final String PARAM_DISABLE_MISSING_USERS; static final String PARAM_GROUP_EXPIRATION_TIME_DEFAULT; @Property(
            label = "Group Expiration Time",
            description = "Duration until a synced group expires (eg. '1h 30m' or '1d').",
            value = PARAM_GROUP_EXPIRATION_TIME_DEFAULT
    )
    static final String PARAM_GROUP_EXPIRATION_TIME; static final String[] PARAM_GROUP_AUTO_MEMBERSHIP_DEFAULT; @Property(
            label = "Group auto membership",
            description = "List of groups that a synced group is added to automatically",
            value = {},
            cardinality = Integer.MAX_VALUE
    )
    static final String PARAM_GROUP_AUTO_MEMBERSHIP; static final String[] PARAM_GROUP_PROPERTY_MAPPING_DEFAULT; @Property(
            label = "Group property mapping",
            description = "List mapping definition of local properties from external ones.",
            value = {},
            cardinality = Integer.MAX_VALUE
    )
    static final String PARAM_GROUP_PROPERTY_MAPPING; static final String PARAM_GROUP_PATH_PREFIX_DEFAULT; @Property(
            label = "Group Path Prefix",
            description = "The path prefix used when creating new groups.",
            value = PARAM_GROUP_PATH_PREFIX_DEFAULT
    )
    static final String PARAM_GROUP_PATH_PREFIX; static final boolean PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE_DEFAULT; @Property(
            label = "RFC7613 Username Normalization Profile",
            description = "Enable the UsercaseMappedProfile defined in RFC7613 for username normalization.",
            boolValue = PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE_DEFAULT
    )
    static final String PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE; }
@Test public void testDefaultName() { DefaultSyncConfig config = DefaultSyncConfigImpl.of(ConfigurationParameters.EMPTY); assertEquals(DefaultSyncConfigImpl.PARAM_NAME_DEFAULT, config.getName()); }
@Test public void testDefaultUser() { DefaultSyncConfig.User userConfig = DefaultSyncConfigImpl.of(ConfigurationParameters.EMPTY).user(); assertEquals(PARAM_DISABLE_MISSING_USERS_DEFAULT, userConfig.getDisableMissing()); assertEquals(PARAM_USER_DYNAMIC_MEMBERSHIP_DEFAULT, userConfig.getDynamicMembership()); assertEquals(PARAM_USER_MEMBERSHIP_NESTING_DEPTH_DEFAULT, userConfig.getMembershipNestingDepth()); assertEquals(ConfigurationParameters.Milliseconds.of(PARAM_USER_MEMBERSHIP_EXPIRATION_TIME_DEFAULT), ConfigurationParameters.Milliseconds.of(userConfig.getMembershipExpirationTime())); assertEquals(ConfigurationParameters.Milliseconds.of(PARAM_USER_EXPIRATION_TIME_DEFAULT), ConfigurationParameters.Milliseconds.of(userConfig.getExpirationTime())); assertEquals(PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE_DEFAULT, userConfig.isApplyRFC7613UsernameCaseMapped()); assertArrayEquals(PARAM_USER_AUTO_MEMBERSHIP_DEFAULT, userConfig.getAutoMembership().toArray(new String[0])); assertEquals(getMapping(PARAM_USER_PROPERTY_MAPPING_DEFAULT), userConfig.getPropertyMapping()); assertEquals(PARAM_USER_PATH_PREFIX_DEFAULT, userConfig.getPathPrefix()); }
@Test public void testDefaultGroup() { DefaultSyncConfig.Group groupConfig = DefaultSyncConfigImpl.of(ConfigurationParameters.EMPTY).group(); assertEquals(ConfigurationParameters.Milliseconds.of(PARAM_GROUP_EXPIRATION_TIME_DEFAULT), ConfigurationParameters.Milliseconds.of(groupConfig.getExpirationTime())); assertEquals(PARAM_ENABLE_RFC7613_USERCASE_MAPPED_PROFILE_DEFAULT, groupConfig.isApplyRFC7613UsernameCaseMapped()); assertArrayEquals(PARAM_GROUP_AUTO_MEMBERSHIP_DEFAULT, groupConfig.getAutoMembership().toArray(new String[0])); assertEquals(getMapping(PARAM_GROUP_PROPERTY_MAPPING_DEFAULT), groupConfig.getPropertyMapping()); assertEquals(PARAM_GROUP_PATH_PREFIX_DEFAULT, groupConfig.getPathPrefix()); }
@Test public void testInvalidMapping() { String[] invalidMapping = new String[] {"invalid:Mapping"}; DefaultSyncConfig.User userConfig = DefaultSyncConfigImpl.of(ConfigurationParameters.of(PARAM_USER_PROPERTY_MAPPING, invalidMapping)).user(); assertEquals(Collections.emptyMap(), userConfig.getPropertyMapping()); }
@Test public void testValidMapping() { String[] validMapping = new String[] {"valid=mapping","valid2=mapping"}; DefaultSyncConfig.User userConfig = DefaultSyncConfigImpl.of(ConfigurationParameters.of(PARAM_USER_PROPERTY_MAPPING, validMapping)).user(); assertEquals(ImmutableMap.of("valid","mapping","valid2","mapping"), userConfig.getPropertyMapping()); }