Skip to content

Commit

Permalink
Feature #42: add support to configure the authenticate methods
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
stcarrez committed Jun 10, 2023
1 parent bc5646c commit 278e003
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 52 deletions.
21 changes: 20 additions & 1 deletion awa/plugins/awa-setup/bundles/setup.properties
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,33 @@ 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
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
Expand All @@ -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
8 changes: 8 additions & 0 deletions awa/plugins/awa-setup/config/setup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/setup/forms/auth.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/setup/forms/auth-response.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

<navigation-rule>
<from-view-id>/setup/forms/oauth.xhtml</from-view-id>
<navigation-case>
Expand Down
56 changes: 55 additions & 1 deletion awa/plugins/awa-setup/src/awa-setup-applications.adb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;
Expand Down Expand Up @@ -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.
-- ------------------------------
Expand Down Expand Up @@ -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.
-- ------------------------------
Expand Down
7 changes: 7 additions & 0 deletions awa/plugins/awa-setup/src/awa-setup-applications.ads
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
5 changes: 4 additions & 1 deletion awa/plugins/awa-setup/web/WEB-INF/layouts/setup-steps.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
<li id="setup-step-settings">
#{setupMsg.setup_settings_step_label}
</li>
<li id="setup-step-auth">
#{setupMsg.setup_auth_step_label}
</li>
<li id="setup-step-oauth">
#{setupMsg.setup_oauth_step_label}
</li>
<li id="setup-step-finish">
#{setupMsg.setup_finish_step_label}
</li>
</ul>
</ul>
20 changes: 19 additions & 1 deletion awa/plugins/awa-setup/web/css/setup.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -54,6 +55,10 @@ h2 {
.setup-description {
margin: 1em;
}
.list-description {
margin: 1em;
padding-left: 1em;
}
#callback input {
float: left;
width: 75%;
Expand All @@ -69,4 +74,17 @@ h2 {
background: #eee;
margin: 0.5em;
padding: 1%;
}
}
.setup-checkbox {
float: left;
width: 100%;
margin-left: 1em;
}
.setup-checkbox dt {
float: left;
width: 80%;
}
.setup-checkbox dd {
float: left;
width: 15%;
}
33 changes: 33 additions & 0 deletions awa/plugins/awa-setup/web/setup/forms/auth-response.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<!-- Response sent after the Auth step
- Copyright (C) 2023 Stephane Carrez
- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<f:view contentType="application/json"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:f="http://java.sun.com/jsf/core">
[
{ "action": "removeClass", "id": "#setup-steps", "data": "setup-auth" },
<c:choose>
<c:when test="#{setup.app_login_openid}">
{ "action": "get", "url": "#{contextPath}/setup/forms/oauth.html" },
{ "action": "addClass", "id": "#setup-steps", "data": "setup-oauth" }
</c:when>
<c:otherwise>
{ "action": "get", "url": "#{contextPath}/setup/forms/finish.html" },
{ "action": "addClass", "id": "#setup-steps", "data": "setup-finish" }
</c:otherwise>
</c:choose>
]
</f:view>
93 changes: 93 additions & 0 deletions awa/plugins/awa-setup/web/setup/forms/auth.xhtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<!-- Form to configure the authenticate methods
- Copyright (C) 2023 Stephane Carrez
- Written by Stephane Carrez (Stephane.Carrez@gmail.com)
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-->
<f:view contentType="text/html; charset=UTF-8"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:w="http://code.google.com/p/ada-asf/widget"
xmlns:h="http://java.sun.com/jsf/html">
<h:form id='setup-auth'>
<h2>
#{setupMsg.setup_auth_message}
</h2>
<div>
<p class="setup-description">
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
<i>user</i> command.
</p>
<dl class="setup-checkbox">
<dt><label for='login-register'>Allow users to register</label> <h:message for='login-register'/></dt>
<dd>
<h:selectBooleanCheckbox id="login-register" value="#{setup.app_login_register}"/>
</dd>
</dl>
</div>
<h2>
#{setupMsg.setup_auth_methods}
</h2>
<div>
<p class="setup-description">
Choose the authenticate methods which are allowed for users to login.
</p>
<dl class="setup-checkbox">

<dt><label for='login-email'>Email login</label> <h:message for='login-email'/></dt>
<dd>
<h:selectBooleanCheckbox id="login-email" value="#{setup.app_login_email}"/>
</dd>

<dt><label for='login-google'>Google+ login</label> <h:message for='login-google'/></dt>
<dd>
<h:selectBooleanCheckbox id="login-google" value="#{setup.app_login_google}"/>
</dd>

<dt><label for='login-github'>GitHub login</label> <h:message for='login-github'/></dt>
<dd>
<h:selectBooleanCheckbox id="login-github" value="#{setup.app_login_github}"/>
</dd>

<dt><label for='login-gitlab'>GitLab login</label> <h:message for='login-gitlab'/></dt>
<dd>
<h:selectBooleanCheckbox id="login-gitlab" value="#{setup.app_login_gitlab}"/>
</dd>

<dt><label for='login-facebook'>Facebook login</label> <h:message for='login-facebook'/></dt>
<dd>
<h:selectBooleanCheckbox id="login-facebook" value="#{setup.app_login_facebook}"/>
</dd>

<dt><label for='login-facebook'>Twitter login</label> <h:message for='login-twitter'/></dt>
<dd>
<h:selectBooleanCheckbox id="login-twitter" value="#{setup.app_login_twitter}"/>
</dd>
</dl>

</div>
<ul class='awa-buttons'>
<li class="previous">
<input type="submit" value="#{setupMsg.setup_previous_label}"
class="ui-button ui-state-default ui-corner-all"
onclick="return previous_step('settings');"/>
</li>
<li>
<h:commandButton id='setup-auth-button' value='#{setupMsg.setup_next_label}'
styleClass="ui-button ui-state-default ui-corner-all"
action="#{setup.configure_authentication}"
title="#{setupMsg.setup_next_tooltip}"/>
</li>
</ul>
</h:form>
</f:view>
Loading

0 comments on commit 278e003

Please sign in to comment.