package com.perforce.workshop.tjuricek.p4oauth; import com.perforce.p4java.server.IOptionsServer; import com.perforce.workshop.tjuricek.p4oauth.config.P4OAuthConfig; import com.perforce.workshop.tjuricek.p4oauth.config.UrlFactory; import com.perforce.workshop.tjuricek.p4oauth.controllers.AuthorizationStartGet; import com.perforce.workshop.tjuricek.p4oauth.controllers.LoginGet; import com.perforce.workshop.tjuricek.p4oauth.jetty.OAuthHandler; import com.perforce.workshop.tjuricek.p4oauth.jetty.OptionsServerReleaseHandler; import com.perforce.workshop.tjuricek.p4oauth.services.CodeService; import com.perforce.workshop.tjuricek.p4oauth.storage.AuthorizationCodeStore; import com.perforce.workshop.tjuricek.p4oauth.storage.IOptionsServerSupplier; import com.perforce.workshop.tjuricek.p4oauth.util.HttpServletRequestHelper; import com.perforce.workshop.tjuricek.p4oauth.util.ThreadMemoizingSupplier; import com.perforce.workshop.tjuricek.p4oauth.controllers.AuthorizationFinishPost; import com.perforce.workshop.tjuricek.p4oauth.jetty.ServerRunnable; import com.perforce.workshop.tjuricek.p4oauth.storage.WhitelistStore; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.function.Function; /** * The main startup method for the class. */ public class P4OAuth { /** * @param args Only parameter should be the config file, which is optional */ public static void main(String[] args) { List<String> params = new ArrayList<String>(); Collections.addAll(params, args); if (params.stream().anyMatch(p -> p.startsWith("-h") || "--help".equals(p))) { System.err.println("Usage: P4OAuth [P4OAuth.yml]"); System.err.println(""); System.err.println("Starts up the P4OAuth server. When running, you can access"); System.err.println("help documentation at the default HTTP port."); System.exit(0); } String configPath = params.isEmpty() ? null : params.get(0); P4OAuthConfig config = P4OAuthConfig.load(configPath); if (config == null) { System.err.println("Configuration failed to load, halting"); System.exit(1); } // Component initialization. Most of the "components" in the system // are actually single object instances that are defined here. // (Note: if you need cleanup, this is the "last line" of defense that // should happen). WhitelistStore whitelistStore = new WhitelistStore(config); UrlFactory urlFactory = new UrlFactory(config); AuthorizationCodeStore authorizationCodeStore = new AuthorizationCodeStore(config); IOptionsServerSupplier serverSupplier = new IOptionsServerSupplier(config); ThreadMemoizingSupplier<IOptionsServer> threadCacheSupplier = new ThreadMemoizingSupplier<>(serverSupplier); CodeService codeService = new CodeService(() -> whitelistStore, threadCacheSupplier, () -> authorizationCodeStore); Function<HttpServletRequest, HttpServletRequestHelper> requestHelperFunction = (r) -> new HttpServletRequestHelper(r, config); AuthorizationStartGet authorizationStartGet = new AuthorizationStartGet(requestHelperFunction, () -> codeService, () -> urlFactory); LoginGet loginGet = new LoginGet(config, requestHelperFunction); AuthorizationFinishPost authorizationFinishPost = new AuthorizationFinishPost(requestHelperFunction, () -> codeService, () -> urlFactory); OAuthHandler oAuthHandler = new OAuthHandler(() -> authorizationStartGet, () -> loginGet, () -> authorizationFinishPost); OptionsServerReleaseHandler releaseHandler = new OptionsServerReleaseHandler(threadCacheSupplier); ServerRunnable server = new ServerRunnable(config, () -> oAuthHandler, () -> releaseHandler); // This currently will block and run the server, unless shutdown or // it fails server.run(); if (server.isFailed()) { System.exit(2); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#4 | 9182 | tjuricek | 0.1.2 Added a password grant workflow | ||
#3 | 9180 | tjuricek |
0.1.1 Adding mechanism for fetching the p4 token given the bearer token on an Authorization header. This is probably secure since we can't use these tokens except for the restricted hosts. |
||
#2 | 9157 | tjuricek | Added basic "authorization code" workflow test. | ||
#1 | 9095 | tjuricek | Added some basic test data and renamed "workspace" to "workshop" in package name | ||
//guest/tjuricek/p4oauth/src/main/java/com/perforce/workspace/tjuricek/p4oauth/P4OAuth.java | |||||
#1 | 9089 | tjuricek |
Moving some code that worked via some manual validation to the workshop. This just implements a basic code authorization grant scheme. Automated tests are forthcoming, awating some gradle plugin work that should sit outside of this project. |