/** * Creates a new holder and populates all convenience data structures. * * @param tenants the current tenants instance */ public UserGroupHolder(final Tenants tenants) { this.tenants = tenants; // load all users final Users users = tenants.getUsers(); final Set<User> allUsers = Collections.unmodifiableSet(createUsers(users)); // load all groups final Groups groups = tenants.getGroups(); final Set<Group> allGroups = Collections.unmodifiableSet(createGroups(groups, users)); // create a convenience map to retrieve a user by id final Map<String, User> userByIdMap = Collections.unmodifiableMap(createUserByIdMap(allUsers)); // create a convenience map to retrieve a user by identity final Map<String, User> userByIdentityMap = Collections.unmodifiableMap(createUserByIdentityMap(allUsers)); // create a convenience map to retrieve a group by id final Map<String, Group> groupByIdMap = Collections.unmodifiableMap(createGroupByIdMap(allGroups)); // create a convenience map to retrieve the groups for a user identity final Map<String, Set<Group>> groupsByUserIdentityMap = Collections.unmodifiableMap(createGroupsByUserIdentityMap(allGroups, allUsers)); // set all the holders this.allUsers = allUsers; this.allGroups = allGroups; this.usersById = userByIdMap; this.usersByIdentity = userByIdentityMap; this.groupsById = groupByIdMap; this.groupsByUserIdentity = groupsByUserIdentityMap; }