/** * Converts a {@link Collection} of {@link DomainCredentials} into a {@link Map} keyed by {@link Domain} with * {@link List} of {@link Credentials} as values. * * @param collection the collection. * @return the corresponding map. */ @NonNull public static Map<Domain, List<Credentials>> asMap(@CheckForNull Collection<DomainCredentials> collection) { Map<Domain, List<Credentials>> map = new LinkedHashMap<Domain, List<Credentials>>(); if (collection != null) { for (DomainCredentials item : collection) { List<Credentials> existing = map.get(item.getDomain()); if (existing == null) { map.put(item.getDomain(), new CopyOnWriteArrayList<Credentials>(item.getCredentials())); } else { // allow combining for malformed requests existing.addAll(item.getCredentials()); } } } return new CopyOnWriteMap.Hash<Domain, List<Credentials>>(map); }
/** * Converts a {@link Collection} of {@link DomainCredentials} into a {@link Map} keyed by {@link Domain} with * {@link List} of {@link Credentials} as values. * * @param collection the collection. * @return the corresponding map. */ @NonNull public static Map<Domain, List<Credentials>> asMap(@CheckForNull Collection<DomainCredentials> collection) { Map<Domain, List<Credentials>> map = new LinkedHashMap<Domain, List<Credentials>>(); if (collection != null) { for (DomainCredentials item : collection) { List<Credentials> existing = map.get(item.getDomain()); if (existing == null) { map.put(item.getDomain(), new CopyOnWriteArrayList<Credentials>(item.getCredentials())); } else { // allow combining for malformed requests existing.addAll(item.getCredentials()); } } } return new CopyOnWriteMap.Hash<Domain, List<Credentials>>(map); }
@Override protected int run() throws Exception { store.checkPermission(CredentialsProvider.CREATE); store.checkPermission(CredentialsProvider.MANAGE_DOMAINS); List<DomainCredentials> replacement = (List<DomainCredentials>) Items.XSTREAM.unmarshal(safeXmlStreamReader(stdin)); for (DomainCredentials domain : replacement) { for (Credentials credentials : domain.getCredentials()) { store.addDomain(domain.getDomain(), credentials); } } return 0; }