| 
									
										
										
										
											2021-08-20 10:58:07 -07:00
										 |  |  | package auth.sso;
 | 
					
						
							| 
									
										
										
										
											2021-08-20 07:42:18 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-20 10:58:07 -07:00
										 |  |  | import static auth.AuthUtils.*;
 | 
					
						
							|  |  |  | import static auth.ConfigUtil.*;
 | 
					
						
							| 
									
										
										
										
											2021-08-20 07:42:18 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Class responsible for extracting and validating top-level SSO related configurations.
 | 
					
						
							|  |  |  |  */
 | 
					
						
							|  |  |  | public class SsoConfigs {
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Required configs
 | 
					
						
							|  |  |  |    */
 | 
					
						
							|  |  |  |   private static final String AUTH_BASE_URL_CONFIG_PATH = "auth.baseUrl";
 | 
					
						
							|  |  |  |   private static final String AUTH_BASE_CALLBACK_PATH_CONFIG_PATH = "auth.baseCallbackPath";
 | 
					
						
							|  |  |  |   private static final String AUTH_SUCCESS_REDIRECT_PATH_CONFIG_PATH = "auth.successRedirectPath";
 | 
					
						
							|  |  |  |   public static final String OIDC_ENABLED_CONFIG_PATH = "auth.oidc.enabled";
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /**
 | 
					
						
							|  |  |  |    * Default values
 | 
					
						
							|  |  |  |    */
 | 
					
						
							|  |  |  |   private static final String DEFAULT_BASE_CALLBACK_PATH = "/callback";
 | 
					
						
							|  |  |  |   private static final String DEFAULT_SUCCESS_REDIRECT_PATH = "/";
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   private final String _authBaseUrl;
 | 
					
						
							|  |  |  |   private final String _authBaseCallbackPath;
 | 
					
						
							|  |  |  |   private final String _authSuccessRedirectPath;
 | 
					
						
							|  |  |  |   private final Integer _sessionTtlInHours;
 | 
					
						
							|  |  |  |   private final Boolean _oidcEnabled;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public SsoConfigs(final com.typesafe.config.Config configs) {
 | 
					
						
							|  |  |  |     _authBaseUrl = getRequired(configs, AUTH_BASE_URL_CONFIG_PATH);
 | 
					
						
							|  |  |  |     _authBaseCallbackPath = getOptional(
 | 
					
						
							|  |  |  |         configs,
 | 
					
						
							|  |  |  |         AUTH_BASE_CALLBACK_PATH_CONFIG_PATH,
 | 
					
						
							|  |  |  |         DEFAULT_BASE_CALLBACK_PATH);
 | 
					
						
							|  |  |  |     _authSuccessRedirectPath = getOptional(
 | 
					
						
							|  |  |  |         configs,
 | 
					
						
							|  |  |  |         AUTH_SUCCESS_REDIRECT_PATH_CONFIG_PATH,
 | 
					
						
							|  |  |  |         DEFAULT_SUCCESS_REDIRECT_PATH);
 | 
					
						
							|  |  |  |     _sessionTtlInHours = Integer.parseInt(getOptional(
 | 
					
						
							|  |  |  |         configs,
 | 
					
						
							|  |  |  |         SESSION_TTL_CONFIG_PATH,
 | 
					
						
							|  |  |  |         DEFAULT_SESSION_TTL_HOURS.toString()));
 | 
					
						
							|  |  |  |     _oidcEnabled =  configs.hasPath(OIDC_ENABLED_CONFIG_PATH)
 | 
					
						
							|  |  |  |         && Boolean.TRUE.equals(
 | 
					
						
							|  |  |  |         Boolean.parseBoolean(configs.getString(OIDC_ENABLED_CONFIG_PATH)));
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public String getAuthBaseUrl() {
 | 
					
						
							|  |  |  |     return _authBaseUrl;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public String getAuthBaseCallbackPath() {
 | 
					
						
							|  |  |  |     return _authBaseCallbackPath;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public String getAuthSuccessRedirectPath() {
 | 
					
						
							|  |  |  |     return _authSuccessRedirectPath;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public Integer getSessionTtlInHours() {
 | 
					
						
							|  |  |  |     return _sessionTtlInHours;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   public Boolean isOidcEnabled() {
 | 
					
						
							|  |  |  |     return _oidcEnabled;
 | 
					
						
							|  |  |  |   }
 | 
					
						
							|  |  |  | }
 |