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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations