StravaClient stravaClient = new StravaClient(AppConfig.getString("strava.client_id"), AppConfig.getString("strava.client_secret"));
stravaClient.setAuthorizationGenerator(profile -> profile.addRole("Strava"));
Clients clients = new Clients("http://localhost:4567/callback", stravaClient);
Config config = new Config(clients);
config.setHttpActionAdapter(new DefaultHttpActionAdapter());
config.addAuthorizer("strava", new RequireAnyRoleAuthorizer("Strava"));
CallbackRoute callback = new CallbackRoute(config, null, true, false);
get("/callback", callback);
post("/callback", callback);
get("/logout", new ApplicationLogoutRoute(config, "/"));
SecurityFilter admin = new SecurityFilter(config, "StravaClient", "strava", "", true);
before("/secure", admin);
AtomicInteger secretCount = new AtomicInteger(0);
post("/secure", (req, res) -> secretCount.incrementAndGet());
get("/secure", (req, res) -> secretCount.get());When making a post or get request to /secure a redirect is issued but the post/get is still called:
I think the reason for this is that the DefaultHTTPAdapter does not halt on redirect but I am not sure whether this should be the responsibility of the HTTPAdapter anyway and not of the securityfilter/securitylogic.
I am just using sparkjava so I have no idea what the behavior is in the other modules.
logger.debug("requires HTTP action: {}", code);
if (code == HttpConstants.UNAUTHORIZED) {
halt(HttpConstants.UNAUTHORIZED, "authentication required");
} else if (code == HttpConstants.FORBIDDEN) {
halt(HttpConstants.FORBIDDEN, "forbidden");
} else if (code == HttpConstants.OK) {
halt(HttpConstants.OK, context.getBody());
} else if (code == HttpConstants.TEMP_REDIRECT) {
context.getSparkResponse().redirect(context.getLocation());
}