/** * Create a simple role decoder which returns the values of the given attribute. * * @param attribute the attribute * @return the roles */ static RoleDecoder simple(String attribute) { return identity -> { final Attributes.Entry entry = identity.getAttributes().get(attribute); return entry.isEmpty() ? Roles.NONE : entry instanceof Attributes.SetEntry ? Roles.fromSet((Attributes.SetEntry) entry) : Roles.fromSet(new HashSet<>(entry)); }; } }
/** * Get the attributes associated with this identity. * * @return a read-only instance of {@link Attributes} with all attributes associated with this identity */ public Attributes getAttributes() { return this.authorizationIdentity.getAttributes().asReadOnly(); }
/** * Build and return the resulting {@link PermissionMapper}. * * @return the resulting {@link PermissionMapper} */ public PermissionMapper build() { assertNotBuilt(); built = true; return new SimplePermissionMapper(mappingMode, mappings); }
/** * Determine if the given key has values in this collection. * * @param key the key * @return {@code true} if the key has values, {@code false} otherwise */ default boolean containsKey(String key) { return key != null && size(key) > 0; }
/** * Get the first value mapped to the given key. * * @param key the key * @return the value * @throws IndexOutOfBoundsException if there are no values for the given key */ default String getFirst(String key) { return get(key, 0); }
/** * Remove the first value mapped to the given key. * * @param key the key * @return the value * @throws IndexOutOfBoundsException if there are no values for the given key */ default String removeFirst(String key) { return remove(key, 0); }
public Iterator<String> iterator() { final Iterator<String> iterator = delegate.iterator(); return new Iterator<String>() { public boolean hasNext() { return iterator.hasNext(); } public String next() { return iterator.next() + suffix; } }; } }
public Collection<String> values() { final Collection<String> values = this.values; if (values != null) { return values; } return this.values = Attributes.super.values(); }
/** * Determine if the given key has a mapping for the given value in this collection. * * @param key the key * @param value the value * @return {@code true} if the key has a mapping to the given value, {@code false} otherwise */ default boolean containsValue(String key, String value) { return key != null && value != null && indexOf(key, value) >= 0; }
/** * Construct a new {@link Builder} for creating the {@link MappedRoleMapper}. * * @return a new {@link Builder} for creating the {@link MappedRoleMapper}. */ public static Builder builder() { return new Builder(); }
/** * Construct a new {@link Builder} for creating the {@link PermissionMapper}. * * @return a new {@link Builder} for creating the {@link PermissionMapper}. */ public static Builder builder() { return new Builder(); }
/** * Add a value before the first mapping for the given key. * * @param key the key * @param value the value */ default void addFirst(String key, String value) { add(key, 0, value); }
/** * Set the mapping mode that the newly created {@link PermissionMapper} should use. * * @param mappingMode the mapping mode. * @return {@code this} builder to allow chaining. */ public Builder setMappingMode(MappingMode mappingMode) { assertNotBuilt(); this.mappingMode = mappingMode; return this; }
public Iterator<String> iterator() { final Iterator<String> iterator = delegate.iterator(); return new Iterator<String>() { public boolean hasNext() { return iterator.hasNext(); } public String next() { return prefix + iterator.next(); } }; } }