/** * Add (or replace) a {@link RequestedPrincipalContext} as a child of this context using the * supplied parameters and the previously established {@link PrincipalEvalPredicateFactoryRegistry} * for comparison handling. * * @param operator matching operator * @param principal principal to request * @param replace whether to replace an existing context or simply return false * * @return true iff a new context was created */ public boolean addRequestedPrincipalContext(@Nonnull @NotEmpty final String operator, @Nonnull final Principal principal, final boolean replace) { return addRequestedPrincipalContext(operator, Collections.singletonList(principal), replace); }
/** * Add (or replace) a {@link RequestedPrincipalContext} as a child of this context using the * supplied parameters and the previously established {@link PrincipalEvalPredicateFactoryRegistry} * for comparison handling. * * @param operator matching operator * @param className name of class to wrap principal names * @param principals names of principals to request * @param replace whether to replace an existing context or simply return false * * @return true iff a new context was created * * @throws Exception if the principal class can't be loaded or instantiated as required */ public boolean addRequestedPrincipalContext(@Nonnull @NotEmpty final String operator, @Nonnull @NotEmpty final String className, @Nonnull final Collection<String> principals, final boolean replace) throws Exception { final Class<? extends Principal> claz = Class.forName(className).asSubclass(Principal.class); final Constructor<? extends Principal> ctor = claz.getConstructor(String.class); final List<Principal> prins = new ArrayList<>(principals.size()); for (final String prin : Collections2.filter(principals, Predicates.notNull())) { prins.add(ctor.newInstance(prin)); } return addRequestedPrincipalContext(operator, prins, replace); }
/** * Add (or replace) a {@link RequestedPrincipalContext} as a child of this context using the * supplied parameters and the previously established {@link PrincipalEvalPredicateFactoryRegistry} * for comparison handling. * * @param operator matching operator * @param className name of class to wrap principal names * @param principal name of principal to request * @param replace whether to replace an existing context or simply return false * * @return true iff a new context was created * * @throws Exception if the principal class can't be loaded or instantiated as required */ public boolean addRequestedPrincipalContext(@Nonnull @NotEmpty final String operator, @Nonnull @NotEmpty final String className, @Nonnull @NotEmpty final String principal, final boolean replace) throws Exception { return addRequestedPrincipalContext(operator, className, Collections.singletonList(principal), replace); }