From 278e00335b2cf3ab310b6404a6009e184755f11b Mon Sep 17 00:00:00 2001 From: Stephane Carrez Date: Sat, 10 Jun 2023 17:23:32 +0200 Subject: [PATCH] Feature #42: add support to configure the authenticate methods - Add configuration step to select the authenticate methods which are enabled - Add configuration method to generate the configuration according to what auth method is allowed - Update the labels and navigation configuration --- .../awa-setup/bundles/setup.properties | 21 ++- awa/plugins/awa-setup/config/setup.xml | 8 + .../awa-setup/src/awa-setup-applications.adb | 56 ++++++- .../awa-setup/src/awa-setup-applications.ads | 7 + .../web/WEB-INF/layouts/setup-steps.xhtml | 5 +- awa/plugins/awa-setup/web/css/setup.css | 20 ++- .../web/setup/forms/auth-response.xhtml | 33 ++++ .../awa-setup/web/setup/forms/auth.xhtml | 93 +++++++++++ .../awa-setup/web/setup/forms/oauth.xhtml | 154 +++++++++++++----- .../web/setup/forms/settings-response.xhtml | 8 +- .../awa-setup/web/setup/forms/settings.xhtml | 6 +- awa/plugins/awa-setup/web/setup/install.xhtml | 4 +- 12 files changed, 363 insertions(+), 52 deletions(-) create mode 100644 awa/plugins/awa-setup/web/setup/forms/auth-response.xhtml create mode 100644 awa/plugins/awa-setup/web/setup/forms/auth.xhtml diff --git a/awa/plugins/awa-setup/bundles/setup.properties b/awa/plugins/awa-setup/bundles/setup.properties index 378a78dd1..c1e21b81b 100644 --- a/awa/plugins/awa-setup/bundles/setup.properties +++ b/awa/plugins/awa-setup/bundles/setup.properties @@ -36,7 +36,9 @@ setup_app_mail_from=Contact mail setup_application_title=Application settings setup_install_title=Installation setup_configure_title=Install {0} -setup_oauth_message=Step 3: OAuth configuration +setup_auth_message=Step 3: Authenticate configuration +setup_auth_methods=Authenticate methods +setup_oauth_message=Step 4: OAuth configuration setup_facebook_auth_title=Facebook authentication setup_facebook_client_id=Facebook application ID setup_facebook_secret=Facebook secret @@ -44,8 +46,23 @@ setup_callback_url=Callback URL setup_google_auth_title=Google+ authentication setup_google_client_id=Google+ application ID setup_google_secret=Google+ secret +setup_github_auth_title=GitHub authentication +setup_github_client_id=GitHub application ID +setup_github_secret=GitHub secret +setup_gitlab_auth_title=GitLab authentication +setup_gitlab_client_id=GitLab application ID +setup_gitlab_secret=GitLab secret +setup_yahoo_auth_title=Yahoo! authentication +setup_yahoo_client_id=Yahoo! application ID +setup_yahoo_secret=Yahoo! secret +setup_twitter_auth_title=Twitter authentication +setup_twitter_client_id=Twitter application ID +setup_twitter_secret=Twitter secret +setup_oauth_client_id_placeholder=Enter the client id +setup_oauth_secret_placeholder=Enter the secret setup_database_step_label=Database setup_settings_step_label=Settings +setup_auth_step_label=Auth setup_oauth_step_label=OAuth setup_finish_message=Installation finished setup_finish_button=Start application @@ -57,3 +74,5 @@ setup_dynamo_missing_error=Maybe the 'dynamo' command is missing or cannot be ex setup_database_port_error=The database server port number is invalid. setup_database_host_error=The database server hostname is invalid. setup_previous_label=Previous +setup_next_label=Next +setup_next_tooltip=Next configuration \ No newline at end of file diff --git a/awa/plugins/awa-setup/config/setup.xml b/awa/plugins/awa-setup/config/setup.xml index e1a52482e..57ac0e631 100644 --- a/awa/plugins/awa-setup/config/setup.xml +++ b/awa/plugins/awa-setup/config/setup.xml @@ -122,6 +122,14 @@ + + /setup/forms/auth.xhtml + + success + /setup/forms/auth-response.xhtml + + + /setup/forms/oauth.xhtml diff --git a/awa/plugins/awa-setup/src/awa-setup-applications.adb b/awa/plugins/awa-setup/src/awa-setup-applications.adb index 8be4f0444..e08b5760d 100644 --- a/awa/plugins/awa-setup/src/awa-setup-applications.adb +++ b/awa/plugins/awa-setup/src/awa-setup-applications.adb @@ -57,6 +57,11 @@ package body AWA.Setup.Applications is Method => Configure_Database, Name => "configure_database"); + package Configure_Authentication_Binding is + new ASF.Events.Faces.Actions.Action_Method.Bind (Bean => Application, + Method => Configure_Authentication, + Name => "configure_authentication"); + -- The application base URL. package P_Base_URL is new ASF.Applications.Main.Configs.Parameter ("app_url_base", @@ -70,13 +75,17 @@ package body AWA.Setup.Applications is := (Save_Binding.Proxy'Access, Start_Binding.Proxy'Access, Finish_Binding.Proxy'Access, - Configure_Binding.Proxy'Access); + Configure_Binding.Proxy'Access, + Configure_Authentication_Binding.Proxy'Access); function Get_Schema_Path (Model_Dir : in String; Model : in String; Config : in ADO.Sessions.Sources.Data_Source) return String; function Get_Model_Directory (From : in Application) return String; function Get_Model_Name (From : in Application) return String; + procedure Append_Config (Into : in out Unbounded_String; + Tag : in String; + Enable : in Boolean); function Get_Schema_Path (Model_Dir : in String; Model : in String; @@ -200,6 +209,16 @@ package body AWA.Setup.Applications is end if; end Set_Value; + function Get_Boolean (From : in Application; + Name : in String) return Boolean is + begin + if From.Changed.Exists (Name) then + return UBO.To_Boolean (From.Changed.Get_Value (Name)); + else + return UBO.To_Boolean (From.Config.Get_Value (Name)); + end if; + end Get_Boolean; + -- ------------------------------ -- Get the database connection string to be used by the application. -- ------------------------------ @@ -360,6 +379,41 @@ package body AWA.Setup.Applications is end if; end Configure_Database; + procedure Append_Config (Into : in out Unbounded_String; + Tag : in String; + Enable : in Boolean) is + begin + if Enable then + if Length (Into) > 0 then + Append (Into, ","); + end if; + Append (Into, Tag); + end if; + end Append_Config; + + procedure Configure_Authentication (From : in out Application; + Outcome : in out Ada.Strings.Unbounded.Unbounded_String) is + Email : constant Boolean := From.Get_Boolean ("app_login_email"); + Google : constant Boolean := From.Get_Boolean ("app_login_google"); + Github : constant Boolean := From.Get_Boolean ("app_login_github"); + Gitlab : constant Boolean := From.Get_Boolean ("app_login_gitlab"); + Twitter : constant Boolean := From.Get_Boolean ("app_login_twitter"); + Yahoo : constant Boolean := From.Get_Boolean ("app_login_yahoo"); + Facebook : constant Boolean := From.Get_Boolean ("app_login_facebook"); + Openid : constant Boolean := Google or Github or Gitlab or Twitter or Facebook or Yahoo; + Methods : Unbounded_String; + begin + Append_Config (Methods, "email", Email); + Append_Config (Methods, "google", Google); + Append_Config (Methods, "github", Github); + Append_Config (Methods, "gitlab", Gitlab); + Append_Config (Methods, "twitter", Twitter); + Append_Config (Methods, "facebook", Facebook); + Append_Config (Methods, "yahoo", Yahoo); + From.Changed.Set_Value ("app_login_methods", UBO.To_Object (Methods)); + From.Changed.Set_Value ("app_login_openid", UBO.To_Object (Openid)); + end Configure_Authentication; + -- ------------------------------ -- Save the configuration. -- ------------------------------ diff --git a/awa/plugins/awa-setup/src/awa-setup-applications.ads b/awa/plugins/awa-setup/src/awa-setup-applications.ads index 8420f1744..a15248e59 100644 --- a/awa/plugins/awa-setup/src/awa-setup-applications.ads +++ b/awa/plugins/awa-setup/src/awa-setup-applications.ads @@ -137,6 +137,10 @@ package AWA.Setup.Applications is procedure Configure_Database (From : in out Application; Outcome : in out Ada.Strings.Unbounded.Unbounded_String); + -- Configure the authentication methods. + procedure Configure_Authentication (From : in out Application; + Outcome : in out Ada.Strings.Unbounded.Unbounded_String); + -- Validate the database configuration parameters. procedure Validate (From : in out Application); @@ -176,4 +180,7 @@ package AWA.Setup.Applications is Config : in String; URI : in String); + function Get_Boolean (From : in Application; + Name : in String) return Boolean; + end AWA.Setup.Applications; diff --git a/awa/plugins/awa-setup/web/WEB-INF/layouts/setup-steps.xhtml b/awa/plugins/awa-setup/web/WEB-INF/layouts/setup-steps.xhtml index a7e74ef83..ccc3d5863 100644 --- a/awa/plugins/awa-setup/web/WEB-INF/layouts/setup-steps.xhtml +++ b/awa/plugins/awa-setup/web/WEB-INF/layouts/setup-steps.xhtml @@ -5,10 +5,13 @@
  • #{setupMsg.setup_settings_step_label}
  • +
  • + #{setupMsg.setup_auth_step_label} +
  • #{setupMsg.setup_oauth_step_label}
  • #{setupMsg.setup_finish_step_label}
  • - \ No newline at end of file + diff --git a/awa/plugins/awa-setup/web/css/setup.css b/awa/plugins/awa-setup/web/css/setup.css index a3a77213c..2c359f616 100644 --- a/awa/plugins/awa-setup/web/css/setup.css +++ b/awa/plugins/awa-setup/web/css/setup.css @@ -33,6 +33,7 @@ h2 { } .setup-database #setup-step-database, .setup-settings #setup-step-settings, +.setup-auth #setup-step-auth, .setup-oauth #setup-step-oauth, .setup-finish #setup-step-finish { background: #fff; @@ -54,6 +55,10 @@ h2 { .setup-description { margin: 1em; } +.list-description { + margin: 1em; + padding-left: 1em; +} #callback input { float: left; width: 75%; @@ -69,4 +74,17 @@ h2 { background: #eee; margin: 0.5em; padding: 1%; -} \ No newline at end of file +} +.setup-checkbox { + float: left; + width: 100%; + margin-left: 1em; +} +.setup-checkbox dt { + float: left; + width: 80%; +} +.setup-checkbox dd { + float: left; + width: 15%; +} diff --git a/awa/plugins/awa-setup/web/setup/forms/auth-response.xhtml b/awa/plugins/awa-setup/web/setup/forms/auth-response.xhtml new file mode 100644 index 000000000..949c27084 --- /dev/null +++ b/awa/plugins/awa-setup/web/setup/forms/auth-response.xhtml @@ -0,0 +1,33 @@ + + +[ + { "action": "removeClass", "id": "#setup-steps", "data": "setup-auth" }, + + + { "action": "get", "url": "#{contextPath}/setup/forms/oauth.html" }, + { "action": "addClass", "id": "#setup-steps", "data": "setup-oauth" } + + + { "action": "get", "url": "#{contextPath}/setup/forms/finish.html" }, + { "action": "addClass", "id": "#setup-steps", "data": "setup-finish" } + + +] + diff --git a/awa/plugins/awa-setup/web/setup/forms/auth.xhtml b/awa/plugins/awa-setup/web/setup/forms/auth.xhtml new file mode 100644 index 000000000..5a4adb21d --- /dev/null +++ b/awa/plugins/awa-setup/web/setup/forms/auth.xhtml @@ -0,0 +1,93 @@ + + + +

    + #{setupMsg.setup_auth_message} +

    +
    +

    + You can choose whether users can register themselves through the web interface. + If you disable the user registration, you can register manually by using the + user command. +

    +
    +
    +
    + +
    +
    +
    +

    + #{setupMsg.setup_auth_methods} +

    +
    +

    + Choose the authenticate methods which are allowed for users to login. +

    +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    + +
    +
    + +
    +
    + +
    +
      + +
    • + +
    • +
    +
    +
    diff --git a/awa/plugins/awa-setup/web/setup/forms/oauth.xhtml b/awa/plugins/awa-setup/web/setup/forms/oauth.xhtml index f1be5a130..ec272a169 100644 --- a/awa/plugins/awa-setup/web/setup/forms/oauth.xhtml +++ b/awa/plugins/awa-setup/web/setup/forms/oauth.xhtml @@ -15,6 +15,7 @@ - limitations under the License. --> @@ -27,32 +28,33 @@ The OAuth configuration form allows you to configure the Google+, Facebook, GitHub, Gitlab, Yahoo!, Twitter authentication. If you want to use this authentication method you must have created an application in : -

    +

    - You can skip this step if you don't want to use Google+ or Facebook authentication. + If you do not have the application client id and client secret and don't want to use + the authentication provider, you should disable it in the previous step.

    @@ -68,46 +70,118 @@ #{contextPath}/auth/verify -

    + +

    #{setupMsg.setup_facebook_auth_title} -

    -
    +

    +
    -
    -

    + + + +

    #{setupMsg.setup_google_auth_title} -

    -
    +

    +
    - - -
    + + + +

    + #{setupMsg.setup_github_auth_title} +

    +
    + + + + +
    +
    + +

    + #{setupMsg.setup_gitlab_auth_title} +

    +
    + + + + +
    +
    + +

    + #{setupMsg.setup_twitter_auth_title} +

    +
    + + + + +
    +
    + +

    + #{setupMsg.setup_yahoo_auth_title} +

    +
    + + + + +
    +
    • - + action="#{setup.save}" title="#{setupMsg.setup_next_tooltip}"/>
    diff --git a/awa/plugins/awa-setup/web/setup/forms/settings-response.xhtml b/awa/plugins/awa-setup/web/setup/forms/settings-response.xhtml index 41c9491f3..6756c6f21 100644 --- a/awa/plugins/awa-setup/web/setup/forms/settings-response.xhtml +++ b/awa/plugins/awa-setup/web/setup/forms/settings-response.xhtml @@ -1,5 +1,5 @@