All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mcollovati.vertx.vaadin.connect.auth.VaadinConnectAccessChecker Maven / Gradle / Ivy

/*
 * The MIT License
 * Copyright © 2016-2020 Marco Collovati ([email protected])
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package com.github.mcollovati.vertx.vaadin.connect.auth;

import java.lang.reflect.Method;
import jakarta.annotation.security.DenyAll;
import jakarta.annotation.security.PermitAll;
import jakarta.annotation.security.RolesAllowed;

import com.vaadin.flow.server.auth.AnonymousAllowed;

/**
 * Component used for checking role-based ACL in Vaadin Endpoints.
 * 

* For each request that is trying to access the method in the corresponding * Vaadin Connect Endpoint, the permission check is carried on. *

* It looks for {@link AnonymousAllowed} {@link PermitAll}, {@link DenyAll} and * {@link RolesAllowed} annotations in endpoint methods and classes containing * these methods (no super classes' annotations are taken into account). *

* Method-level annotation override Class-level ones. *

* In the next example, since the class is denied to all, method1 is not * accessible to anyone, method2 can be executed by any authorized used, method3 * is only allowed to the accounts having the ROLE_USER authority and method4 is * available for every user, including anonymous ones that don't provide any * token in their requests. * *

 * @Endpoint
 * @DenyAll
 * public class DemoEndpoint {
 *
 *     public void method1() {
 *     }
 *
 *     @PermitAll
 *     public void method2() {
 *     }
 *
 *     @RolesAllowed("ROLE_USER")
 *     public void method3() {
 *     }
 *
 *     @AnonymousAllowed
 *     public void method4() {
 *     }
 * }
 * 
* * @param request type */ public interface VaadinConnectAccessChecker { /** * Check that the endpoint is accessible for the current user. * * @param method the Vaadin endpoint method to check ACL * @param request the request that triggers the method invocation * @return an error String with an issue description, if any validation * issues occur, {@code null} otherwise */ String check(Method method, REQUEST request); }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy