/** * Process the messages collected into an {@link Errors} instance. * Clear this collector (e.g. it can be used to collect new messages). * * @return new {@link Errors} instance built with messages collected by this collecto */ public Errors collect() { Errors errors = new Errors(this); clear(); return errors; }
/** * Add a hint message to the list of messages. * * @param message message of the hint * @return updated collector */ public Collector hint(String message) { return hint(StackWalker.getInstance(WALKER_OPTIONS).getCallerClass(), message); }
/** * Add a fatal error to the list of messages. * * @param message message of the error * @return updated collector */ public Collector fatal(String message) { return fatal(StackWalker.getInstance(WALKER_OPTIONS).getCallerClass(), message); }
/** * Provide extension annotations supported by this provider (e.g. {@code javax.annotation.security.RolesAllowed}). * Annotations will be collected according to framework in use. For JAX-RS, annotations from application class, resource * class and resource methods will be collected. * * @return Collection of annotations this provider expects. * @see EndpointConfig#annotations(EndpointConfig.AnnotationScope...) * @see EndpointConfig#combineAnnotations(Class, EndpointConfig.AnnotationScope...) */ default Collection<Class<? extends Annotation>> supportedAnnotations() { return CollectionsHelper.setOf(); }
@Override public Collection<Class<? extends Annotation>> supportedAnnotations() { //Order of the annotations matters because of annotation handling. return CollectionsHelper.listOf(RolesAllowed.class, Roles.class, RolesContainer.class, PermitAll.class, DenyAll.class); }
/** * Add a warning message to the list of messages. * * @param message message of the warning * @return updated collector */ public Collector warn(String message) { return warn(StackWalker.getInstance(WALKER_OPTIONS).getCallerClass(), message); }
/** * Add a message to the list of messages with source automatically added. * * @param message text message of the message * @param severity indicates severity of added message * @return updated collector */ public Collector message(final String message, final Severity severity) { return message(StackWalker.getInstance(WALKER_OPTIONS).getCallerClass(), message, severity); }
/** * Gets the {@code Class} object of the caller who invoked the method * that invoked {@code getCallerClass}. * * @return {@code Class} object of the caller's caller invoking this method. */ public Class<?> getCallerClass() { Class<?>[] classContext = new MySecurityManager().getClassContext0(); return classContext[3]; }
/** * Add a fatal error to the list of messages. * * @param source source of the error * @param message message of the error * @return updated collector */ public Collector fatal(Object source, String message) { return message(source, message, Severity.FATAL); }
/** * Create a new message collector. * * @return message collector to add messages to */ public static Collector collector() { return new Collector(); }
/** * Check if these messages are a valid result, throws exception if not. * * @throws ErrorMessagesException in case there is at least one {@link Severity#FATAL} severity message */ public void checkValid() throws ErrorMessagesException { if (hasFatal) { throw new ErrorMessagesException(this); } }
/** * Static factory method to create a new {@code OptionalHelper} instance. * @param <T> the type of the underly optional value * @param optional the optional to wrap * @return the created {@code OptionalHelper} instance */ public static <T> OptionalHelper<T> from(Optional<T> optional){ return new OptionalHelper<>(optional); }
private Errors(Collector collector) { this.addAll(collector.errors); this.hasFatal = collector.hasFatal; this.hasWarning = collector.hasWarning; this.hasHint = collector.hasHint; }
@Override default T get() { return build(); } }
@Override public String toString() { return "Mapper for " + type.getTypeName() + " is not defined"; } }
/** * Keys expected in configuration. This may be used in integrations that can * be fully configured through a file (e.g. integration with web server). * This is a configuration of a specific resource access (e.g. GET on /my/resource) and * is to be used by this provider to evaluate security. * * @return name of the configuration key or empty (default) * @see EndpointConfig#config(String) */ default Collection<String> supportedConfigKeys() { return CollectionsHelper.setOf(); }
/** * Add a warning message to the list of messages. * * @param source source of the warning * @param message message of the warning * @return updated collector */ public Collector warn(Object source, String message) { return message(source, message, Severity.WARN); }
/** * Class of the configuration type. * The provider may use a POJO implementing a {@link ProviderConfig} to * configure it. When configuring security, you user can provide an instance * of such a class to configure that provider. * * @return class of the type or empty (default) * @see EndpointConfig#instance(Class) */ default Collection<Class<? extends ProviderConfig>> supportedCustomObjects() { return CollectionsHelper.setOf(); }
/** * Add a hint message to the list of messages. * * @param source source of the hint * @param message message of the hint * @return updated collector */ public Collector hint(Object source, String message) { return message(source, message, Severity.HINT); }
/** * Get set of roles the user is in. * * @return roles of this user (or empty if not supported). */ default Collection<String> roles() { return CollectionsHelper.setOf(); } }