Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
penid-connect-new-OAuthPolicy-fields Review Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mrafiei committed Feb 7, 2017
1 parent aaf6ab2 commit 85797f0
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 13 deletions.
28 changes: 28 additions & 0 deletions api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicies.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2013 Stormpath, Inc.
*
* 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.
*/
package com.stormpath.sdk.oauth;

import com.stormpath.sdk.lang.Classes;

/**
* @since 1.6.0
*/
public final class OAuthPolicies {

public static OAuthPolicyOptions options() {
return (OAuthPolicyOptions) Classes.newInstance("com.stormpath.sdk.impl.oauth.DefaultOAuthPolicyOptions");
}
}
12 changes: 11 additions & 1 deletion api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicy.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public interface OAuthPolicy extends Resource, Saveable {
* Returns the Time To Live for the id tokens created for the parent {@link Application Application} expressed in a period of time format, for example: PT1H.
*
* @return the String representation of the Time To Live for the id tokens created for the parent {@link Application Application}
* @since 1.6.0
*/
String getIdTokenTtl();

Expand Down Expand Up @@ -87,14 +88,15 @@ public interface OAuthPolicy extends Resource, Saveable {
* Sets the Time To Live for the id tokens created for the parent {@link Application Application} expressed in a period of time format, for example: PT1H.
*
* @return this instance for method chaining.
* @since 1.6.0
*/
OAuthPolicy setIdTokenTtl(String idTokenTtl);

/**
* Creates a new {@link Scope} assigned to this oauthPolicy in the Stormpath server and returns the created resource.
* The scope is used for openid connect flows.
*
* @param scope {@link Scope} pojo to hold necessary data to send to the back- end to create a {@link Scope}.
* @param scope {@link Scope} pojo to hold necessary data to send to the back-end to create a {@link Scope}.
* @return the newly created {@link Scope}.
*
* @since 1.6.0
Expand All @@ -112,6 +114,8 @@ public interface OAuthPolicy extends Resource, Saveable {

/**
* Returns access token attribute mappings.
* Open Id provider (OP) would enter any custom mappings used for their internal purposes in this map.
* Authorization server would then add all these mappings as part of the access token upon its generation.
*
* @return access token attribute mappings.
*
Expand All @@ -123,6 +127,8 @@ public interface OAuthPolicy extends Resource, Saveable {
* Sets access token attribute mappings to be inserted into access tokens.
*
* @param accessTokenAttributeMap access token attribute mappings to be inserted into access tokens
* Open Id provider (OP) would enter any custom mappings used for their internal purposes in this map.
* Authorization server would then add all these mappings as part of the access token upon its generation.
* @return this instance for method chaining.
*
* @since 1.6.0
Expand All @@ -131,6 +137,8 @@ public interface OAuthPolicy extends Resource, Saveable {

/**
* Returns id token attribute mappings.
* Open Id provider (OP) would enter any custom mappings used for their internal purposes in this map.
* Authorization server would then add all these mappings as part of the id token upon its generation.
*
* @return id token attribute mappings.
*
Expand All @@ -142,6 +150,8 @@ public interface OAuthPolicy extends Resource, Saveable {
* Sets id token attribute mappings to be inserted into id tokens.
*
* @param idTokenAttributeMap id token attribute mappings to be inserted into id tokens
* Open Id provider (OP) would enter any custom mappings used for their internal purposes in this map.
* Authorization server would then add all these mappings as part of the id token upon its generation.
* @return this instance for method chaining.
*
* @since 1.6.0
Expand Down
30 changes: 30 additions & 0 deletions api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicyOptions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2017 Stormpath, Inc.
*
* 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.
*/
package com.stormpath.sdk.oauth;

import com.stormpath.sdk.query.Options;

/**
* @since 1.6.0
*/
public interface OAuthPolicyOptions<T> extends Options {

T withScopes();

T withScopes(int limit);

T withScopes(int limit, int offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* A Scope resource is used to configure different openid connect scopes
* with an {@link OAuthPolicy OAuthPolicy}
*
* @since 1.0.RC7
* @since 1.6.0
*/
public interface Scope extends Resource, Saveable, Deletable, Auditable {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,21 @@
package com.stormpath.sdk.impl.application

import com.stormpath.sdk.client.ClientIT
import com.stormpath.sdk.impl.resource.AbstractResource
import com.stormpath.sdk.oauth.OAuthPolicies
import com.stormpath.sdk.oauth.OAuthPolicy
import com.stormpath.sdk.oauth.OAuthPolicyOptions
import com.stormpath.sdk.oauth.openidconnect.Scope
import com.stormpath.sdk.oauth.openidconnect.ScopeList
import org.testng.annotations.Test

import java.lang.reflect.Field

import static org.testng.Assert.assertEquals
import static org.testng.Assert.assertNotNull
import static org.testng.Assert.assertFalse
import static org.testng.Assert.assertTrue

/**
* @since 1.6.0
*/
Expand Down Expand Up @@ -68,19 +75,30 @@ class OAuthPolicyIT extends ClientIT {
@Test
void testPolicyExpandOnScopes(){
def app = createTempApp()
def policyHref = app.getOAuthPolicy().href+"?expand=scopes"
def policyHref = app.getOAuthPolicy().href

def oauthPolicy = client.getResource(policyHref, OAuthPolicy.class)
assertNotNull oauthPolicy
assertNotNull oauthPolicy.href
OAuthPolicyOptions options = OAuthPolicies.options().withScopes()

assertNotNull options
assertEquals options.expansions.size(), 1

options = OAuthPolicies.options().withScopes(10)

assertEquals(oauthPolicy.scopes.size, 3)
assertNotNull(oauthPolicy.scopes.asList().get(0).href)
assertNotNull(oauthPolicy.scopes.asList().get(0).name)
assertNotNull(oauthPolicy.scopes.asList().get(1).href)
assertNotNull(oauthPolicy.scopes.asList().get(1).name)
assertNotNull(oauthPolicy.scopes.asList().get(2).href)
assertNotNull(oauthPolicy.scopes.asList().get(2).name)
assertNotNull options
assertEquals options.expansions.size(), 1

options = OAuthPolicies.options().withScopes(10,0)

assertNotNull options
assertEquals options.expansions.size(), 1

def retrieved = client.getResource(policyHref, OAuthPolicy.class, options)
Map policyProperties = getValue(AbstractResource, retrieved, "properties")
def scopes = policyProperties.get("scopes").size()
assertTrue scopes == 5
assertTrue policyProperties.get("scopes").items.get(0).name != null
assertTrue policyProperties.get("scopes").items.get(1).name != null
assertTrue policyProperties.get("scopes").items.get(2).name != null
}

@Test
Expand Down Expand Up @@ -178,4 +196,10 @@ class OAuthPolicyIT extends ClientIT {
assertEquals(items[1].name, "updatedName2")
assertEquals(items[2].name, "updatedName3")
}

private Object getValue(Class clazz, Object object, String fieldName) {
Field field = clazz.getDeclaredField(fieldName)
field.setAccessible(true)
return field.get(object)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2017 Stormpath, Inc.
*
* 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.
*/
package com.stormpath.sdk.impl.oauth;

import com.stormpath.sdk.impl.query.DefaultOptions;
import com.stormpath.sdk.oauth.OAuthPolicyOptions;

/**
* @since 1.6.0
*/
public class DefaultOAuthPolicyOptions extends DefaultOptions<OAuthPolicyOptions> implements OAuthPolicyOptions<OAuthPolicyOptions>{
@Override
public OAuthPolicyOptions withScopes() {
return expand(DefaultOAuthPolicy.SCOPES);
}

@Override
public OAuthPolicyOptions withScopes(int limit) {
return expand(DefaultOAuthPolicy.SCOPES, limit);
}

@Override
public OAuthPolicyOptions withScopes(int limit, int offset) {
return expand(DefaultOAuthPolicy.SCOPES, limit, offset);
}
}

0 comments on commit 85797f0

Please sign in to comment.