dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #38223
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19518: add/edit oauth2 clients, wip
------------------------------------------------------------
revno: 19518
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-06-25 13:26:15 +0700
message:
add/edit oauth2 clients, wip
added:
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetOAuth2ClientAction.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/oAuth2client.vm
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/oauth2/OAuth2Client.java
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/oauth2Clients.js
dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemOAuth2Clients.vm
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/oauth2/OAuth2Client.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/oauth2/OAuth2Client.java 2015-06-24 05:47:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/oauth2/OAuth2Client.java 2015-06-25 06:26:15 +0000
@@ -36,6 +36,9 @@
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.MergeStrategy;
+import org.hisp.dhis.schema.PropertyType;
+import org.hisp.dhis.schema.annotation.Property;
+import org.hisp.dhis.schema.annotation.PropertyRange;
import java.util.ArrayList;
import java.util.List;
@@ -74,6 +77,7 @@
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @Property( PropertyType.IDENTIFIER )
public String getCid()
{
return cid;
@@ -86,6 +90,7 @@
@JsonProperty
@JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+ @PropertyRange( min = 36, max = 36 )
public String getSecret()
{
return secret;
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetOAuth2ClientAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetOAuth2ClientAction.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetOAuth2ClientAction.java 2015-06-25 06:26:15 +0000
@@ -0,0 +1,86 @@
+package org.hisp.dhis.settings.action.system;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import com.opensymphony.xwork2.Action;
+import org.hisp.dhis.oauth2.OAuth2Client;
+import org.hisp.dhis.oauth2.OAuth2ClientService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class GetOAuth2ClientAction implements Action
+{
+ // -------------------------------------------------------------------------
+ // Dependencies
+ // -------------------------------------------------------------------------
+
+ @Autowired
+ private OAuth2ClientService clientService;
+
+ // -------------------------------------------------------------------------
+ // Input & Output
+ // -------------------------------------------------------------------------
+
+ private String id;
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public void setId( String id )
+ {
+ this.id = id;
+ }
+
+ private OAuth2Client client;
+
+ public OAuth2Client getClient()
+ {
+ return client;
+ }
+
+ // -------------------------------------------------------------------------
+ // Action implementation
+ // -------------------------------------------------------------------------
+
+ @Override
+ public String execute() throws Exception
+ {
+ if ( !StringUtils.isEmpty( id ) )
+ {
+ client = clientService.getOAuth2Client( id );
+ }
+
+ return SUCCESS;
+ }
+}
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml 2015-06-25 03:36:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/META-INF/dhis/beans.xml 2015-06-25 06:26:15 +0000
@@ -127,6 +127,9 @@
<!-- OAuth2 -->
<bean id="org.hisp.dhis.settings.action.system.GetOAuth2ClientsAction"
- class="org.hisp.dhis.settings.action.system.GetOAuth2ClientsAction" />
+ class="org.hisp.dhis.settings.action.system.GetOAuth2ClientsAction" scope="prototype" />
+
+ <bean id="org.hisp.dhis.settings.action.system.GetOAuth2ClientAction"
+ class="org.hisp.dhis.settings.action.system.GetOAuth2ClientAction" scope="prototype" />
</beans>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2015-06-25 03:36:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/org/hisp/dhis/settings/i18n_module.properties 2015-06-25 06:26:15 +0000
@@ -131,4 +131,9 @@
for_example=For example
allow_assigning_object_to_related_objects_during_add_or_update=Allow assigning object to related objects during add or update
delete_oauth2_client=Are you sure you want to remove this OAuth2 client?
-oauth2_client_management=OAuth2 Management
\ No newline at end of file
+oauth2_client_management=OAuth2 Management
+create_new_oauth2_client=Create new OAuth2 Client
+edit_oauth2_client=Edit OAuth2 Client
+name=Name
+client_id=Client ID
+client_secret=Client Secret
\ No newline at end of file
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml 2015-06-25 03:36:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/resources/struts.xml 2015-06-25 06:26:15 +0000
@@ -186,5 +186,12 @@
<param name="requiredAuthorities">F_OAUTH2_CLIENT_MANAGE</param>
</action>
+ <action name="getOAuth2Client" class="org.hisp.dhis.settings.action.system.GetOAuth2ClientAction">
+ <result name="success" type="velocity">/main.vm</result>
+ <param name="page">/dhis-web-maintenance-settings/oAuth2Client.vm</param>
+ <param name="menu">/dhis-web-maintenance-settings/settingsMenu.vm</param>
+ <param name="requiredAuthorities">F_OAUTH2_CLIENT_MANAGE</param>
+ </action>
+
</package>
</struts>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/oauth2Clients.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/oauth2Clients.js 2015-06-25 04:16:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/javascripts/oauth2Clients.js 2015-06-25 06:26:15 +0000
@@ -1,5 +1,56 @@
+var OAuth2Service = {
+ save: function(o, id) {
+ if( !id ) {
+ return $.ajax({
+ url: '../api/oAuth2Clients/' + id,
+ type: 'PUT',
+ contentType: 'application/json',
+ data: JSON.stringify(o)
+ });
+ } else {
+ return $.ajax({
+ url: '../api/oAuth2Clients',
+ type: 'POST',
+ contentType: 'application/json',
+ data: JSON.stringify(o)
+ });
+ }
+ },
+ load: function(id) {
+ return $.ajax({
+ url: '../api/oAuth2Clients/' + id
+ })
+ },
+ fromJson: function(o) {
+ $('#name').val(o.name);
+ $('#clientId').val(o.cid);
+ $('#clientSecret').val(o.secret);
+ },
+ toJson: function() {
+ var o = {};
+
+ o.name = $('#name').val();
+ o.cid = $('#clientId').val();
+ o.secret = $('#clientSecret').val();
+
+ return o;
+ },
+ getUuid: function() {
+ var def = $.Deferred();
+
+ $.ajax({
+ url: '../api/system/uuid',
+ dataType: 'json'
+ }).done(function(o) {
+ def.resolve(o.codes[0]);
+ });
+
+ return def.promise();
+ }
+};
+
function updateO2Client(context) {
- console.log(context);
+ location.href = 'getOAuth2Client.action?id=' + context.uid;
}
function deleteO2Client(context) {
@@ -11,4 +62,4 @@
location.reload();
});
}
-}
\ No newline at end of file
+}
=== added file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/oAuth2client.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/oAuth2client.vm 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/oAuth2client.vm 2015-06-25 06:26:15 +0000
@@ -0,0 +1,70 @@
+<style>
+ input[disabled] {
+ background-color : #ececec;
+ }
+
+ #clientForm > table {
+ padding-bottom : 10px;
+ }
+</style>
+<script src="javascripts/oauth2Clients.js"></script>
+<script>
+ $(function() {
+ #if( $id )
+ OAuth2Service.load("$id").done(function(data) {
+ OAuth2Service.fromJson(data);
+ $('input').removeAttr('disabled');
+ }).fail(function() {
+ // we should never really get here, but redirect back to oauth2 client list if id was invalid
+ location.href = "systemOAuth2Clients.action";
+ });
+ #else
+ OAuth2Service.getUuid().then(function(uuid) {
+ $('#clientSecret').val(uuid);
+ })
+ #end
+
+ $('#clientForm').submit(function(e) {
+ var o = OAuth2Service.toJson();
+
+ OAuth2Service.save(o, "$!id").then(function() {
+ location.href = "systemOAuth2Clients.action";
+ });
+
+ e.preventDefault();
+ })
+ });
+</script>
+
+#if( $id )
+<h3>$i18n.getString( "edit_oauth2_client" )</h3>
+#else
+<h3>$i18n.getString( "create_new_oauth2_client" )</h3>
+#end
+
+<form id="clientForm" class="inputForm">
+ <table>
+ <tr>
+ <th colspan="2">$i18n.getString( "details" )</th>
+ </tr>
+ <tr>
+ <td><label for="name">$i18n.getString( "name" )</label></td>
+ <td><input type="text" id="name" name="name" value="" #if($id)disabled#end></td>
+ </tr>
+ <tr>
+ <td><label for="name">$i18n.getString( "client_id" )</label></td>
+ <td><input type="text" id="clientId" name="clientId" value="" #if($id)disabled#end></td>
+ </tr>
+ <tr>
+ <td><label for="name">$i18n.getString( "client_secret" )</label></td>
+ <td><input type="text" id="clientSecret" name="clientSecret" value="" #if($id)disabled#end></td>
+ </tr>
+ </table>
+
+ #if( $id )
+ <input id="submit" type="submit" value="$i18n.getString( 'save' )" style="width:10em"/>
+ #else
+ <input id="submit" type="submit" value="$i18n.getString( 'add' )" style="width:10em"/>
+ #end
+ <input type="button" value="$i18n.getString( 'cancel' )" onclick="dhis2.commons.redirectCurrentPage( 'systemOAuth2Clients.action' )" style="width:10em"/>
+</form>
=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemOAuth2Clients.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemOAuth2Clients.vm 2015-06-25 03:36:52 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/webapp/dhis-web-maintenance-settings/systemOAuth2Clients.vm 2015-06-25 06:26:15 +0000
@@ -23,6 +23,11 @@
<table class="mainPageTable">
<tr>
+ <td style="text-align:right">
+ <input type="button" value="$i18n.getString( 'add_new' )" onclick="window.location.href='getOAuth2Client.action'" style="width:80px"/>
+ </td>
+ </tr>
+ <tr>
<td style="vertical-align:top">
<table class="listTable" id="listTable">
<col/>