private void preLoad(Runtime runtime) { int serverPort = app.config().getIntProperty("server.port", 8080); runtime.setServerUrl("http://localhost:" + serverPort + app.getContextPath()); }
@Override public void onAppBooting(App app, ServletContext sc) throws Exception { if(!Classes.isPresent("org.h2.server.web.WebApp")) { log.info("H2 jar not found, db console disabled"); return; } H2ConsoleServlet.config = app.config(); ServletRegistration.Dynamic dynamic; try { dynamic = sc.addServlet("h2-console-servlet", H2ConsoleServlet.class); }catch (IllegalStateException e) { log.warn("Can't add h2-console-servlet, " + e.getMessage(), e); return; } app.ignoredPaths().add(path); dynamic.addMapping(path + "/*"); dynamic.setLoadOnStartup(1); SecurityConfigurator sec = app.factory().getBean(SecurityConfigurator.class); sec.ignore(path); sec.ignore(path + "/**/*"); }
public void configure() { if(!endpoints.isEmpty()) { endpoints.forEach(r -> app.routes().remove(r)); } Map<String, Object> map = ConfigUtils.extractMap(app.config(), CONF_PREFIX); if(null == map || map.isEmpty()) { return; } config = Converts.convert(map, OAuth2ServerConfig.class); if(!config.isEnabled()) { return; } //clients config.getClients().forEach((id, c) -> { c.setId(id); validator.validate(CONF_PREFIX + ".clients." + id, c); }); //url int port = app.config().getIntProperty("server.port", 8080); String contextPath = app.config().getProperty("server.context-path", ""); this.url = (config.isSsl() ? "https:" : "http") + "://localhost:" + port + contextPath; //gen key pair if(null == keyPair) { keyPair = RSA.generateKeyPair(); signer = new RsaSigner(keyPair.getPrivateKey()); verifier = new RsaVerifier(keyPair.getPublicKey()); } //create endpoint createEndpoints(app.routes()); }
redirectPath = Servlets.getRequestPathFromUri(redirectUri); }else{ redirectPath = Servlets.getRequestPathFromUri(redirectUri, app.getContextPath()); app.routes().get(redirectPath, (req, resp) -> handleAuthzServerLoginResponse(req, resp)); logoutPath = Servlets.getRequestPathFromUri(logoutUri); }else{ logoutPath = Servlets.getRequestPathFromUri(logoutUri, app.getContextPath()); app.routes().get(logoutPath,(req,resp) -> handleAuthzServerLogoutNotification(req, resp));
@Override public void postAppStart(App app) throws Throwable { app.setAttribute("oauth2.skipTokenAuthenticateUrl",new String[]{osc.getAuthzEndpointPath()}); } }
return State.CONTINUE; Object o = app.getAttribute("oauth2.skipTokenAuthenticateUrl"); if(o instanceof String[]){ String[] skips = (String[]) o;
protected void doConfiguration(App app, ApiConfigurator c) { if(null == c.config().getFailureHandler()) { c.setFailureHandler(app.factory().getBean(ApiFailureHandler.class)); } //todo : oauth //todo : cors commonResponses.forEach(c::putCommonResponse); }
@Override public void postAppStart(App app) throws Throwable { for(Route route : app.routes()) { processRoute(route); } }
void accept(ApiImpl latest) { if(!app.routes().exists(this)) { app.routes().add(this); } latest.getProtocols().forEach((name, p) -> { if(!protocols.containsKey(name)) { ProtocolRoutes routes = new ProtocolRoutes(name, p.getPathTemplate()); protocols.put(name, routes); app.routes().add(routes); } }); this.latest = latest; }
@Override public boolean isOperationExists(RestdContext context, RouteBuilder r) { if(doCheckOperationExists(context, r, app.routes(), false)) { return true; } Routes routes = context.getApiConfig().getContainerRoutes(); if(routes != app.routes() && doCheckOperationExists(context, r, routes, true)) { return true; } return false; }
protected void resolveAppRoutes(App app, ApiConfigurator c) { String basePath = c.config().getBasePath(); for(Route route : app.routes()) { String pathTemplate = route.getPathTemplate().getTemplate(); if(pathTemplate.equals(basePath) || pathTemplate.startsWith(basePath)) { resolveResourceType(app, c, route); c.addRoute(route); } } }
@Override public void destroyDynaApi(DynaApi api) { ApiConfig config = api.getConfig(); if(log.isDebugEnabled()) { log.debug("Routes before destroying api '{}': \n\n{}\n", api.getName(), routesPrinter.print(app.routes())); } config.getApiRoutes().forEach(ar -> { if(ar.isDynamic()) { app.routes().remove(ar.getRoute()); } }); if(log.isDebugEnabled()) { log.debug("Routes after destroying api '{}': \n\n{}\n", api.getName(), routesPrinter.print(app.routes())); } apis.remove(api); }
protected Api doNewApi(ApiConfigurator configurator, boolean dynamic) { configurator.setContainerRoutes(app.routes()); if(null != configs) { ApiConfig c = configurator.config(); if(c.getOAuthConfig() == null){ configurator.setOAuthConfig(oauthConfig); }else{ configurator.setOAuthConfig(new OAuthConfigImpl().updateFrom(oauthConfig)); } configs.getCommonModels().forEach(model -> { if(null != c.getModelConfigByClassName(model.getClassName())) { return; } if(null != c.getModelConfig(model.getName())) { return; } configurator.addModelConfig(model); }); configs.getCommonParams().forEach(param -> { if(null != c.getParam(param.getClassName(),param.getName())) { return; } configurator.addParam(param); }); } return new DefaultApi(this::doCreate, configurator, dynamic); }