/** * Loads demo users into persistence. * * @param rolePrefix the role prefix * @param numPerSeries the number of users to load per series * @param additionalRoles any additional roles to add for each user * @param orgId the organization id */ protected void load(String rolePrefix, int numPerSeries, String[] additionalRoles, String orgId) { String lowerCasePrefix = rolePrefix.toLowerCase(); int totalUsers = numPerSeries * NUM_SERIES; logger.info( "Adding sample {}s, usernames and passwords are {}1/{}1... {}{}/{}{}", new Object[] { lowerCasePrefix, lowerCasePrefix, lowerCasePrefix, lowerCasePrefix, totalUsers, lowerCasePrefix, totalUsers }); for (int i = 1; i <= totalUsers; i++) { if (jpaUserProvider.loadUser(lowerCasePrefix + i, orgId) == null) { Set<String> roleSet = new HashSet<String>(); for (String additionalRole : additionalRoles) { roleSet.add(additionalRole); } roleSet.add(SERIES_PREFIX + (((i - 1) % NUM_SERIES) + 1) + "_" + rolePrefix); JpaUser user = new JpaUser(lowerCasePrefix + i, lowerCasePrefix + i, orgId, roleSet); try { jpaUserProvider.addUser(user); logger.debug("Added {}", user); } catch (Exception e) { logger.warn("Can not add {}: {}", user, e); } } } }
/** * Load a user for testing the ldap provider * * @param organizationId the organization */ protected void loadLdapUser(String organizationId) { Set<String> ldapUserRoles = new HashSet<String>(); ldapUserRoles.add(USER_ROLE); // This is the public identifier for Josh Holtzman in the UC Berkeley Directory, which is // available for anonymous // binding. String ldapUserId = "231693"; if (jpaUserProvider.loadUser(ldapUserId, organizationId) == null) { jpaUserProvider.addUser(new JpaUser(ldapUserId, "ldap", organizationId, ldapUserRoles)); logger.debug("Added ldap user '{}' into organization '{}'", ldapUserId, organizationId); } }