Search in sources :

Example 1 with RouteRole

use of io.javalin.core.security.RouteRole in project javalin by tipsy.

the class Javalin method addHandler.

/**
 * Adds a request handler for the specified handlerType and path to the instance.
 * Requires an access manager to be set on the instance.
 * This is the method that all the verb-methods (get/post/put/etc) call.
 *
 * @see AccessManager
 * @see <a href="https://javalin.io/documentation#handlers">Handlers in docs</a>
 */
public Javalin addHandler(@NotNull HandlerType handlerType, @NotNull String path, @NotNull Handler handler, @NotNull RouteRole... roles) {
    Set<RouteRole> roleSet = new HashSet<>(Arrays.asList(roles));
    javalinServlet.addHandler(handlerType, path, handler, roleSet);
    eventManager.fireHandlerAddedEvent(new HandlerMetaInfo(handlerType, Util.prefixContextPath(javalinServlet.getConfig().contextPath, path), handler, roleSet));
    return this;
}
Also used : RouteRole(io.javalin.core.security.RouteRole) WsHandlerMetaInfo(io.javalin.core.event.WsHandlerMetaInfo) HandlerMetaInfo(io.javalin.core.event.HandlerMetaInfo) HashSet(java.util.HashSet)

Example 2 with RouteRole

use of io.javalin.core.security.RouteRole in project javalin by tipsy.

the class Javalin method addWsHandler.

/**
 * Adds a specific WebSocket handler for the given path to the instance.
 * Requires an access manager to be set on the instance.
 */
private Javalin addWsHandler(@NotNull WsHandlerType handlerType, @NotNull String path, @NotNull Consumer<WsConfig> wsConfig, @NotNull RouteRole... roles) {
    Set<RouteRole> roleSet = new HashSet<>(Arrays.asList(roles));
    javalinJettyServlet.addHandler(handlerType, path, wsConfig, roleSet);
    eventManager.fireWsHandlerAddedEvent(new WsHandlerMetaInfo(handlerType, Util.prefixContextPath(javalinServlet.getConfig().contextPath, path), wsConfig, roleSet));
    return this;
}
Also used : RouteRole(io.javalin.core.security.RouteRole) WsHandlerMetaInfo(io.javalin.core.event.WsHandlerMetaInfo) HashSet(java.util.HashSet)

Example 3 with RouteRole

use of io.javalin.core.security.RouteRole in project cwms-radar-api by USACE.

the class ApiServlet method configureRoutes.

protected void configureRoutes() {
    RouteRole[] requiredRoles = { new Role(CWMS_USERS_ROLE) };
    get("/", ctx -> ctx.result("Welcome to the CWMS REST API").contentType(Formats.PLAIN));
    radarCrud("/location/category/{category-id}", new LocationCategoryController(metrics), requiredRoles);
    radarCrud("/location/group/{group-id}", new LocationGroupController(metrics), requiredRoles);
    radarCrud("/locations/{location_code}", new LocationController(metrics), requiredRoles);
    radarCrud("/offices/{office}", new OfficeController(metrics), requiredRoles);
    radarCrud("/units/{unit_name}", new UnitsController(metrics), requiredRoles);
    radarCrud("/parameters/{param_name}", new ParametersController(metrics), requiredRoles);
    radarCrud("/timezones/{zone}", new TimeZoneController(metrics), requiredRoles);
    radarCrud("/levels/{location}", new LevelsController(metrics), requiredRoles);
    TimeSeriesController tsController = new TimeSeriesController(metrics);
    get("/timeseries/recent/{group-id}", tsController::getRecent);
    radarCrud("/timeseries/category/{category-id}", new TimeSeriesCategoryController(metrics), requiredRoles);
    radarCrud("/timeseries/group/{group-id}", new TimeSeriesGroupController(metrics), requiredRoles);
    radarCrud("/timeseries/{timeseries}", tsController, requiredRoles);
    radarCrud("/ratings/{rating}", new RatingController(metrics), requiredRoles);
    radarCrud("/catalog/{dataSet}", new CatalogController(metrics), requiredRoles);
    radarCrud("/basins/{basin-id}", new BasinController(metrics), requiredRoles);
    radarCrud("/blobs/{blob-id}", new BlobController(metrics), requiredRoles);
    radarCrud("/clobs/{clob-id}", new ClobController(metrics), requiredRoles);
    radarCrud("/pools/{pool-id}", new PoolController(metrics), requiredRoles);
}
Also used : BlobController(cwms.radar.api.BlobController) LevelsController(cwms.radar.api.LevelsController) CatalogController(cwms.radar.api.CatalogController) PoolController(cwms.radar.api.PoolController) LocationController(cwms.radar.api.LocationController) TimeZoneController(cwms.radar.api.TimeZoneController) LocationGroupController(cwms.radar.api.LocationGroupController) TimeSeriesCategoryController(cwms.radar.api.TimeSeriesCategoryController) ClobController(cwms.radar.api.ClobController) RouteRole(io.javalin.core.security.RouteRole) RouteRole(io.javalin.core.security.RouteRole) Role(cwms.radar.security.Role) UnitsController(cwms.radar.api.UnitsController) OfficeController(cwms.radar.api.OfficeController) LocationCategoryController(cwms.radar.api.LocationCategoryController) UnitsController(cwms.radar.api.UnitsController) TimeSeriesGroupController(cwms.radar.api.TimeSeriesGroupController) RatingController(cwms.radar.api.RatingController) ParametersController(cwms.radar.api.ParametersController) BasinController(cwms.radar.api.BasinController) TimeSeriesController(cwms.radar.api.TimeSeriesController)

Example 4 with RouteRole

use of io.javalin.core.security.RouteRole in project cwms-radar-api by USACE.

the class CwmsAccessManager method getRoles.

public Set<RouteRole> getRoles(Context ctx) {
    Set<RouteRole> retval = new LinkedHashSet<>();
    if (ctx != null) {
        Principal principal = ctx.req.getUserPrincipal();
        Set<RouteRole> specifiedRoles = getRoles(principal);
        if (!specifiedRoles.isEmpty()) {
            retval.addAll(specifiedRoles);
        }
    }
    return retval;
}
Also used : RouteRole(io.javalin.core.security.RouteRole) LinkedHashSet(java.util.LinkedHashSet) Principal(java.security.Principal) CwmsUserPrincipal(cwms.auth.CwmsUserPrincipal)

Example 5 with RouteRole

use of io.javalin.core.security.RouteRole in project cwms-radar-api by USACE.

the class CwmsAccessManager method getRoles.

private Set<RouteRole> getRoles(Principal principal) {
    Set<RouteRole> retval = new LinkedHashSet<>();
    if (principal != null) {
        List<String> roleNames;
        try {
            CwmsUserPrincipal cup = (CwmsUserPrincipal) principal;
            roleNames = cup.getRoles();
        } catch (ClassCastException e) {
            // The object is created by cwms_aaa with the cwms_aaa classloader.
            // It's a CwmsUserPrincipal but it's not our CwmsUserPrincipal.
            roleNames = callGetRolesReflectively(principal);
        }
        if (roleNames != null) {
            roleNames.stream().map(CwmsAccessManager::buildRole).forEach(retval::add);
        }
        logger.info("Principal had roles: " + retval);
    }
    return retval;
}
Also used : RouteRole(io.javalin.core.security.RouteRole) LinkedHashSet(java.util.LinkedHashSet) CwmsUserPrincipal(cwms.auth.CwmsUserPrincipal)

Aggregations

RouteRole (io.javalin.core.security.RouteRole)5 CwmsUserPrincipal (cwms.auth.CwmsUserPrincipal)2 WsHandlerMetaInfo (io.javalin.core.event.WsHandlerMetaInfo)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 BasinController (cwms.radar.api.BasinController)1 BlobController (cwms.radar.api.BlobController)1 CatalogController (cwms.radar.api.CatalogController)1 ClobController (cwms.radar.api.ClobController)1 LevelsController (cwms.radar.api.LevelsController)1 LocationCategoryController (cwms.radar.api.LocationCategoryController)1 LocationController (cwms.radar.api.LocationController)1 LocationGroupController (cwms.radar.api.LocationGroupController)1 OfficeController (cwms.radar.api.OfficeController)1 ParametersController (cwms.radar.api.ParametersController)1 PoolController (cwms.radar.api.PoolController)1 RatingController (cwms.radar.api.RatingController)1 TimeSeriesCategoryController (cwms.radar.api.TimeSeriesCategoryController)1 TimeSeriesController (cwms.radar.api.TimeSeriesController)1 TimeSeriesGroupController (cwms.radar.api.TimeSeriesGroupController)1