← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19506: add redirectUris/grantTypes directly to OAuth2Client

 

------------------------------------------------------------
revno: 19506
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-06-24 12:11:33 +0700
message:
  add redirectUris/grantTypes directly to OAuth2Client
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/oauth2/OAuth2Client.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OAuth2ClientSchemaDescriptor.java
  dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/oauth2.hibernate/OAuth2Client.hbm.xml


--
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-10 08:13:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/oauth2/OAuth2Client.java	2015-06-24 05:11:33 +0000
@@ -29,11 +29,16 @@
  */
 
 import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import org.hisp.dhis.common.BaseIdentifiableObject;
 import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.common.MergeStrategy;
 
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Objects;
 import java.util.UUID;
 
@@ -47,6 +52,10 @@
 
     private String secret = UUID.randomUUID().toString();
 
+    private List<String> redirectUris = new ArrayList<>();
+
+    private List<String> grantTypes = new ArrayList<>();
+
     public OAuth2Client()
     {
     }
@@ -75,10 +84,36 @@
         this.secret = secret;
     }
 
+    @JsonProperty
+    @JacksonXmlElementWrapper( localName = "redirectUris", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "redirectUri", namespace = DxfNamespaces.DXF_2_0 )
+    public List<String> getRedirectUris()
+    {
+        return redirectUris;
+    }
+
+    public void setRedirectUris( List<String> redirectUris )
+    {
+        this.redirectUris = redirectUris;
+    }
+
+    @JsonProperty
+    @JacksonXmlElementWrapper( localName = "grantTypes", namespace = DxfNamespaces.DXF_2_0 )
+    @JacksonXmlProperty( localName = "grantType", namespace = DxfNamespaces.DXF_2_0 )
+    public List<String> getGrantTypes()
+    {
+        return grantTypes;
+    }
+
+    public void setGrantTypes( List<String> grantTypes )
+    {
+        this.grantTypes = grantTypes;
+    }
+
     @Override
     public int hashCode()
     {
-        return 31 * super.hashCode() + Objects.hash( cid, secret );
+        return 31 * super.hashCode() + Objects.hash( cid, secret, redirectUris, grantTypes );
     }
 
     @Override
@@ -100,6 +135,36 @@
         final OAuth2Client other = (OAuth2Client) obj;
 
         return Objects.equals( this.cid, other.cid )
-            && Objects.equals( this.secret, other.secret );
+            && Objects.equals( this.secret, other.secret )
+            && Objects.equals( this.redirectUris, other.redirectUris )
+            && Objects.equals( this.grantTypes, other.grantTypes );
+    }
+
+    @Override
+    public void mergeWith( IdentifiableObject other, MergeStrategy strategy )
+    {
+        super.mergeWith( other, strategy );
+
+        if ( other.getClass().isInstance( this ) )
+        {
+            OAuth2Client oAuth2Client = (OAuth2Client) other;
+
+            if ( strategy.isReplace() )
+            {
+                cid = oAuth2Client.getCid();
+                secret = oAuth2Client.getSecret();
+            }
+            else if ( strategy.isMerge() )
+            {
+                cid = oAuth2Client.getCid() == null ? cid : oAuth2Client.getCid();
+                secret = oAuth2Client.getSecret() == null ? secret : oAuth2Client.getSecret();
+            }
+
+            redirectUris.clear();
+            grantTypes.clear();
+
+            redirectUris.addAll( oAuth2Client.getRedirectUris() );
+            grantTypes.addAll( oAuth2Client.getGrantTypes() );
+        }
     }
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OAuth2ClientSchemaDescriptor.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OAuth2ClientSchemaDescriptor.java	2015-06-21 12:44:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/descriptors/OAuth2ClientSchemaDescriptor.java	2015-06-24 05:11:33 +0000
@@ -53,7 +53,6 @@
     {
         Schema schema = new Schema( OAuth2Client.class, SINGULAR, PLURAL );
         schema.setRelativeApiEndpoint( API_ENDPOINT );
-        schema.setMetadata( false );
         schema.setOrder( 1030 );
 
         schema.getAuthorities().add( new Authority( AuthorityType.READ, Lists.newArrayList( "F_OAUTH2_CLIENT_MANAGE" ) ) );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/oauth2.hibernate/OAuth2Client.hbm.xml'
--- dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/oauth2.hibernate/OAuth2Client.hbm.xml	2015-06-11 04:19:07 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/oauth2.hibernate/OAuth2Client.hbm.xml	2015-06-24 05:11:33 +0000
@@ -21,5 +21,19 @@
 
     <property name="secret" column="secret" not-null="true" unique="false" length="512" />
 
+    <list name="redirectUris" table="oauth2clientredirecturis" cascade="all-delete-orphan">
+      <cache usage="read-write" />
+      <key column="oauth2clientid" foreign-key="fk_oauth2clientredirecturis_oauth2clientid" />
+      <list-index column="sort_order" base="0" />
+      <element type="string" column="redirecturi" />
+    </list>
+
+    <list name="grantTypes" table="oauth2clientgranttypes" cascade="all-delete-orphan">
+      <cache usage="read-write" />
+      <key column="oauth2clientid" foreign-key="fk_oauth2clientgranttypes_oauth2clientid" />
+      <list-index column="sort_order" base="0" />
+      <element type="string" column="granttype" />
+    </list>
+
   </class>
 </hibernate-mapping>