diff --git a/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicies.java b/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicies.java deleted file mode 100644 index 44ec638f5d..0000000000 --- a/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicies.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * 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"); - } -} diff --git a/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicy.java b/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicy.java index a4dd2459ce..e28dfc89bc 100644 --- a/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicy.java +++ b/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicy.java @@ -16,15 +16,10 @@ package com.stormpath.sdk.oauth; import com.stormpath.sdk.application.Application; -import com.stormpath.sdk.oauth.openidconnect.Scope; -import com.stormpath.sdk.oauth.openidconnect.ScopeList; import com.stormpath.sdk.resource.Resource; -import com.stormpath.sdk.resource.ResourceException; import com.stormpath.sdk.resource.Saveable; import com.stormpath.sdk.tenant.Tenant; -import java.util.Map; - /** * An OAuthPolicy resource is used to configure different aspects of the OAuth tokens associated * with an {@link Application Application} @@ -47,14 +42,6 @@ public interface OAuthPolicy extends Resource, Saveable { */ String getRefreshTokenTtl(); - /** - * 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(); - /** * The href corresponding to the Endpoint for Access Tokens created for the parent {@link Application Application} * @@ -84,80 +71,6 @@ public interface OAuthPolicy extends Resource, Saveable { */ OAuthPolicy setRefreshTokenTtl(String refreshTokenTtl); - /** - * 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}. - * @return the newly created {@link Scope}. - * - * @since 1.6.0 - */ - Scope createScope(Scope scope) throws ResourceException; - - /** - * Returns a paginated list of all the scopes that belong to the oAuthPolicy. - * - * @return a paginated list of all the oAuthPolicy's scopes. - * - * @since 1.6.0 - */ - ScopeList getScopes(); - - /** - * 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. - * - * @since 1.6.0 - */ - Map getAccessTokenAttributeMap(); - - /** - * 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 - */ - OAuthPolicy setAccessTokenAttributeMap(Map accessTokenAttributeMap); - - /** - * 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. - * - * @since 1.6.0 - */ - Map getIdTokenAttributeMap(); - - /** - * 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 - */ - OAuthPolicy setIdTokenAttributeMap(Map idTokenAttributeMap); - /** * Returns the {@link Application Application} associated to this {@link OAuthPolicy OAuthPolicy} * diff --git a/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicyOptions.java b/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicyOptions.java deleted file mode 100644 index 97b3c74fe9..0000000000 --- a/api/src/main/java/com/stormpath/sdk/oauth/OAuthPolicyOptions.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 extends Options { - - /** - * Ensures that when retrieving an OAuthPolicy, the OAuthPolicy's assigned {@link OAuthPolicy#getScopes()} scopes} - * are also retrieved in the same request. This enhances performance by leveraging a single request - * to retrieve multiple related resources you know you will use. - * - * @return this instance for method chaining. - */ - T withScopes(); - - /** - * Ensures that when retrieving an OAuthPolicy, the OAuthPolicy's assigned {@link OAuthPolicy#getScopes()} scopes} - * are also retrieved in the same request. This enhances performance by leveraging a single request - * to retrieve multiple related resources you know you will use. - * - * @param limit defines the maximum quantity of items to be retrieved when expanding this Collection Resource. Min:1, Max: 100. The default value is 25. - * @return this instance for method chaining. - */ - T withScopes(int limit); - - /** - * Ensures that when retrieving an OAuthPolicy, the OAuthPolicy's assigned {@link OAuthPolicy#getScopes()} scopes} - * are also retrieved in the same request. This enhances performance by leveraging a single request - * to retrieve multiple related resources you know you will use. - * - * @param limit defines the maximum quantity of items to be retrieved when expanding this Collection Resource. Min:1, Max: 100. The default value is 25. - * @param offset the zero-based starting index in the entire collection of the first item to return. Default is 0 - * @return this instance for method chaining. - */ - T withScopes(int limit, int offset); -} diff --git a/api/src/main/java/com/stormpath/sdk/oauth/openidconnect/Scope.java b/api/src/main/java/com/stormpath/sdk/oauth/openidconnect/Scope.java deleted file mode 100644 index 745bea5151..0000000000 --- a/api/src/main/java/com/stormpath/sdk/oauth/openidconnect/Scope.java +++ /dev/null @@ -1,108 +0,0 @@ -/* -* 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.openidconnect; - -import com.stormpath.sdk.oauth.OAuthPolicy; -import com.stormpath.sdk.resource.Auditable; -import com.stormpath.sdk.resource.Deletable; -import com.stormpath.sdk.resource.Resource; -import com.stormpath.sdk.resource.Saveable; - -import java.util.Map; - -/** - * A Scope resource is used to configure different openid connect scopes - * with an {@link OAuthPolicy OAuthPolicy} - * - * @since 1.6.0 - */ -public interface Scope extends Resource, Saveable, Deletable, Auditable { - /** - * Returns the scope's name. - * - * @return the scope's name. - */ - String getName(); - - /** - * Sets the scope's name. - * @param name the scope's name. - * - * @return this instance for method chaining. - */ - Scope setName(String name); - - /** - * Returns the scope's friendly name. - * - * @return the scope's friendly name. - */ - String getFriendlyName(); - - /** - * Sets the scope's friendly name. - * - * @param name the scope's friendly name. - * @return this instance for method chaining. - */ - Scope setFriendlyName(String name); - - /** - * Returns the scope's description. - * - * @return the scope's description. - */ - String getDescription(); - - /** - * Sets the scope's description. - * @param description the scope's description. - * - * @return this instance for method chaining. - */ - Scope setDescription(String description); - - - /** - * Returns the scope's attribute mappings. - * - * @return the scope's attribute mappings. - */ - Map getAttributeMappings(); - - /** - * Sets the scope's attribute mappings. - * @param attributeMappings the scope's attribute mappings. - * - * @return this instance for method chaining. - */ - Scope setAttributeMappings(Map attributeMappings); - - /** - * Returns the {@link OAuthPolicy} associated with this scope. - * - * @return the {@link OAuthPolicy} associated with this scope. - */ - OAuthPolicy getOAuthPolicy(); - - /** - * Sets the {@link OAuthPolicy} associated with this scope. - * @param oAuthPolicy the {@link OAuthPolicy} associated with this scope. - * - * @return this instance for method chaining. - */ - Scope setOAuthPolicy(OAuthPolicy oAuthPolicy); -} diff --git a/api/src/main/java/com/stormpath/sdk/oauth/openidconnect/ScopeList.java b/api/src/main/java/com/stormpath/sdk/oauth/openidconnect/ScopeList.java deleted file mode 100644 index 7ae2825848..0000000000 --- a/api/src/main/java/com/stormpath/sdk/oauth/openidconnect/ScopeList.java +++ /dev/null @@ -1,26 +0,0 @@ -/* -* 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.openidconnect; - -import com.stormpath.sdk.resource.CollectionResource; - -/** - * A {@link CollectionResource} containing {@link Scope} instances. - * - * @since 1.6.0 - */ -public interface ScopeList extends CollectionResource { -} diff --git a/changelog.md b/changelog.md index e822236775..2351a4f93d 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,11 @@ ## Change Log ## +### 1.5.5 ## + +* Refactored the /oauth/revoke endpoint to remove cookies + +See [1.5.5 closed issues](https://github.com/stormpath/stormpath-sdk-java/issues?q=milestone%3A1.5.5+is%3Aclosed) + ### 1.5.4 ## * Fixed a bug whereby Account with MCF password is not properly created via Directory when the RegistrationWorkflow is specified diff --git a/extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/application/OAuthPolicyIT.groovy b/extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/application/OAuthPolicyIT.groovy deleted file mode 100644 index 6ab380c443..0000000000 --- a/extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/application/OAuthPolicyIT.groovy +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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.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 - */ -class OAuthPolicyIT extends ClientIT { - - @Test - void testPolicyCreatedForNewApplication() { - def app = createTempApp() - - OAuthPolicy oauthPolicy = app.getOAuthPolicy() - assertNotNull oauthPolicy - assertNotNull oauthPolicy.href - assertEquals oauthPolicy.getApplication().getHref(), app.href - } - - @Test - void testNewlyCreatedPolicyGotDefaultScopes(){ - def app = createTempApp() - - OAuthPolicy oauthPolicy = app.getOAuthPolicy() - assertNotNull oauthPolicy - assertNotNull oauthPolicy.href - assertEquals oauthPolicy.getApplication().getHref(), app.href - - def oAuthPolicyScopesEndPoint = oauthPolicy.href + "/scopes" - def scopes = client.getResource(oAuthPolicyScopesEndPoint, ScopeList.class) - assertEquals scopes.asList().size(), 3 - - assertNotNull scopes.asList().get(0).href - assertNotNull scopes.asList().get(1).href - assertNotNull scopes.asList().get(2).href - - for(def currentDefaultScope : scopes.asList()){ - assertNotNull(currentDefaultScope.name) - assertNotNull(currentDefaultScope.friendlyName) - assertNotNull(currentDefaultScope.description) - assertNotNull(currentDefaultScope.attributeMappings) - assertFalse(currentDefaultScope.attributeMappings.isEmpty()) - } - } - - @Test - void testPolicyExpandOnScopes(){ - def app = createTempApp() - def policyHref = app.getOAuthPolicy().href - - OAuthPolicyOptions options = OAuthPolicies.options().withScopes() - - assertNotNull options - assertEquals options.expansions.size(), 1 - - options = OAuthPolicies.options().withScopes(10) - - 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 - void testDeleteOAuthPolicyDeletesScopes(){ - // todo: openid connect uncomment the snippet below once cascading deletes are supported in SDK - // Cascading deletes are not supported in SDK for now - // Following issue will address it: https://github.com/stormpath/stormpath-sdk-java/issues/985 - //getDeletedResourceError(identityProvider.href, SamlIdentityProvider) - } - - // todo - currently failing against production @mrafiei - @Test(enabled = false) - void testRetrieveAndUpdateOAuthPolicy() { - def app = createTempApp() - - OAuthPolicy oauthPolicy = app.getOAuthPolicy() - assertNotNull oauthPolicy - assertEquals oauthPolicy.getApplication().getHref(), app.href - assertNotNull oauthPolicy.getTokenEndpoint() - assertNotNull oauthPolicy.getRevocationEndpoint() - assertNotNull oauthPolicy.getScopes() - assertNotNull oauthPolicy.getAccessTokenAttributeMap() - assertNotNull oauthPolicy.getIdTokenAttributeMap() - - ScopeList scopeList = client.getResource(oauthPolicy.getScopes().getHref(), ScopeList.class) - assertEquals scopeList.asList().size(), 3 - - Scope scope = client.instantiate(Scope.class) - scope.setName("testScope").setFriendlyName("friendly testing").setDescription("some description").setAttributeMappings(["name":"mapped_name"]) - scope = oauthPolicy.createScope(scope) - assertEquals scope.getOAuthPolicy().href, oauthPolicy.href - - scopeList = client.getResource(oauthPolicy.getScopes().getHref(), ScopeList.class) - assertEquals scopeList.asList().size(), 4 - - oauthPolicy.setAccessTokenTtl("P8D") - oauthPolicy.setRefreshTokenTtl("P2D") - oauthPolicy.setIdTokenTtl("P5D") - oauthPolicy.setAccessTokenAttributeMap(["atk1":"atv1"]) - oauthPolicy.setIdTokenAttributeMap(["itk1":"itv1", "itk2":"itv2"]) - oauthPolicy.save() - - oauthPolicy = app.getOAuthPolicy() - assertEquals oauthPolicy.getAccessTokenTtl(), "P8D" - assertEquals oauthPolicy.getRefreshTokenTtl(), "P2D" - assertEquals oauthPolicy.getIdTokenTtl(), "P5D" - assertEquals oauthPolicy.getAccessTokenAttributeMap(), ["atk1":"atv1"] - assertEquals oauthPolicy.getIdTokenAttributeMap(), ["itk1":"itv1", "itk2":"itv2"] - assertEquals oauthPolicy.getApplication().getHref(), app.href - - oauthPolicy.setAccessTokenAttributeMap(["atk1":"atv1", "atk2":"atv2"]) - oauthPolicy.setIdTokenAttributeMap(["itk1":"itv1"]) - oauthPolicy.save() - - oauthPolicy = app.getOAuthPolicy() - assertEquals oauthPolicy.getAccessTokenAttributeMap(), ["atk1":"atv1", "atk2":"atv2"] - assertEquals oauthPolicy.getIdTokenAttributeMap(), ["itk1":"itv1"] - } - - @Test - void testUpdateScopesUpdatesPolicyCollection(){ - def app = createTempApp() - - OAuthPolicy oauthPolicy = app.getOAuthPolicy() - assertNotNull oauthPolicy - assertEquals oauthPolicy.getApplication().getHref(), app.href - assertNotNull oauthPolicy.getScopes() - - def oAuthPolicyScopesEndPoint = oauthPolicy.href + "/scopes" - def scopes = client.getResource(oAuthPolicyScopesEndPoint, ScopeList.class) - - def items = scopes.asList() - - assertEquals(items.size, 3) - assertNotNull(items[0].href) - assertNotNull(items[1].href) - assertNotNull(items[2].href) - - items[0].setName("updatedName1") - items[1].setName("updatedName2") - items[2].setName("updatedName3") - - items[0].save() - items[1].save() - items[2].save() - - scopes = client.getResource(oAuthPolicyScopesEndPoint, ScopeList.class) - - items = scopes.asList() - - assertEquals(items.size, 3) - assertNotNull(items[0].href) - assertNotNull(items[1].href) - assertNotNull(items[2].href) - assertEquals(items[0].name, "updatedName1") - 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) - } -} diff --git a/extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/openidconnect/ScopeIT.groovy b/extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/openidconnect/ScopeIT.groovy deleted file mode 100644 index 6bf94fa352..0000000000 --- a/extensions/httpclient/src/test/groovy/com/stormpath/sdk/impl/openidconnect/ScopeIT.groovy +++ /dev/null @@ -1,185 +0,0 @@ -/* - * 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.openidconnect - -import com.stormpath.sdk.client.ClientIT -import com.stormpath.sdk.oauth.OAuthPolicy -import com.stormpath.sdk.oauth.openidconnect.Scope -import com.stormpath.sdk.oauth.openidconnect.ScopeList -import com.stormpath.sdk.resource.ResourceException -import org.testng.annotations.Test - -import static org.testng.Assert.assertEquals -import static org.testng.Assert.assertNotNull -import static org.testng.Assert.assertNull -import static org.testng.Assert.assertTrue - -/** - * @since 1.6.0 - */ -class ScopeIT extends ClientIT { - - @Test - void testGetPolicyScopes() { - - def app = createTempApp() - - OAuthPolicy oauthPolicy = app.getOAuthPolicy() - assertNotNull oauthPolicy - - ScopeList scopeList = client.getResource(oauthPolicy.getScopes().getHref(), ScopeList.class) - assertEquals app.getOAuthPolicy().scopes.href, scopeList.href - assertEquals scopeList.asList().size(), 3 - } - - @Test - void testCreateScope() { - def app = createTempApp() - assertNotNull app.getOAuthPolicy().href - assertNotNull app.getOAuthPolicy().scopes.href - - OAuthPolicy oAuthPolicy = app.getOAuthPolicy() - assertNotNull oAuthPolicy.href - - def oAuthPolicyScopesEndPoint = oAuthPolicy.href + "/scopes" - def scopeList = client.getResource(oAuthPolicyScopesEndPoint, ScopeList.class) - assertNotNull scopeList.href - - Scope scope = client.instantiate(Scope.class) - scope.setDescription("description") - - Throwable e = null - try{ - oAuthPolicy.createScope(scope) - } - catch(ResourceException re){ - e = re - assertEquals(re.status, 400) - assertEquals(re.getCode(), 2000) - } - assertTrue(e instanceof ResourceException) - - scope.setName("name").setAttributeMappings(["attribute1":"value1"]) - scope = oAuthPolicy.createScope(scope) - scope = client.getResource(scope.href, Scope.class) - - assertNotNull(scope.href) - assertNotNull(scope.name) - assertNull(scope.friendlyName) - assertNotNull(scope.description) - assertNotNull(scope.attributeMappings) - assertNotNull(scope.createdAt) - assertNotNull(scope.modifiedAt) - assertNotNull(scope.getOAuthPolicy()) - assertNotNull(scope.getOAuthPolicy().href) - } - - // todo - currently failing against production @mrafiei - @Test(enabled = false) - void testUpdateScope() { - def app = createTempApp() - assertNotNull app.getOAuthPolicy().href - assertNotNull app.getOAuthPolicy().scopes.href - - OAuthPolicy oAuthPolicy = app.getOAuthPolicy() - assertNotNull oAuthPolicy.href - - Scope scope = client.instantiate(Scope.class) - scope.setName("myScopeName").setAttributeMappings(["attribute1":"value1"]) - scope.setDescription("myScopeDescription") - - scope = oAuthPolicy.createScope(scope) - scope = client.getResource(scope.href, Scope.class) - - assertNotNull(scope.href) - assertEquals scope.name, "myScopeName" - assertNull(scope.friendlyName) - assertEquals scope.description, "myScopeDescription" - assertNotNull(scope.attributeMappings) - assertEquals scope.attributeMappings, ["attribute1":"value1"] - assertNotNull(scope.createdAt) - assertNotNull(scope.modifiedAt) - assertNotNull(scope.getOAuthPolicy()) - assertNotNull(scope.getOAuthPolicy().href) - - scope.setFriendlyName("myFriendlyName") - scope.setAttributeMappings(["attribute1":"value1", "attribute2":"value2"]) - scope.save() - scope = client.getResource(scope.href, Scope.class) - - assertNotNull(scope.href) - assertNotNull(scope.name) - assertEquals scope.friendlyName, "myFriendlyName" - assertNotNull(scope.description) - assertEquals scope.attributeMappings, ["attribute1":"value1", "attribute2":"value2"] - assertNotNull(scope.createdAt) - assertNotNull(scope.modifiedAt) - assertNotNull(scope.getOAuthPolicy()) - assertNotNull(scope.getOAuthPolicy().href) - - scope.setAttributeMappings(["attribute1":"value1"]) - scope.save() - scope = client.getResource(scope.href, Scope.class) - - assertNotNull(scope.href) - assertNotNull(scope.name) - assertEquals scope.friendlyName, "myFriendlyName" - assertNotNull(scope.description) - assertEquals scope.attributeMappings, ["attribute1":"value1"] - assertNotNull(scope.createdAt) - assertNotNull(scope.modifiedAt) - assertNotNull(scope.getOAuthPolicy()) - assertNotNull(scope.getOAuthPolicy().href) - } - - @Test - void testDeleteScope() { - def app = createTempApp() - assertNotNull app.getOAuthPolicy().href - assertNotNull app.getOAuthPolicy().scopes.href - - OAuthPolicy oAuthPolicy = app.getOAuthPolicy() - assertNotNull oAuthPolicy.href - - Scope scope = client.instantiate(Scope.class) - scope.setName("myScopeName").setAttributeMappings(["attribute1":"value1"]) - scope.setDescription("myScopeDescription") - - oAuthPolicy.createScope(scope) - - def oAuthPolicyScopesEndPoint = oAuthPolicy.href + "/scopes" - - def scopes = client.getResource(oAuthPolicyScopesEndPoint, ScopeList.class) - assertEquals scopes.size, 4 - - scope.delete() - - Throwable e = null - try{ - client.getResource(scope.href, Scope.class) - } - catch(ResourceException re){ - e = re - assertEquals(re.status, 404) - assertEquals(re.getCode(), 404) - } - assertTrue(e instanceof ResourceException) - - scopes = client.getResource(oAuthPolicyScopesEndPoint, ScopeList.class) - assertEquals scopes.size, 3 - } - -} diff --git a/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/config/filter/RevokeTokenFilterFactory.java b/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/config/filter/RevokeTokenFilterFactory.java index abdb803cf1..b0fe6052a3 100644 --- a/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/config/filter/RevokeTokenFilterFactory.java +++ b/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/config/filter/RevokeTokenFilterFactory.java @@ -33,5 +33,6 @@ protected RevokeTokenController newController() { @Override protected void configure(RevokeTokenController controller, Config config) throws Exception { controller.setApplicationResolver(config.getApplicationResolver()); + controller.setAuthenticationResultSaver(config.getAuthenticationResultSaver()); } } diff --git a/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/RevokeTokenController.java b/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/RevokeTokenController.java index 1ee3bacc3b..7c5006c168 100644 --- a/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/RevokeTokenController.java +++ b/extensions/servlet/src/main/java/com/stormpath/sdk/servlet/mvc/RevokeTokenController.java @@ -16,6 +16,7 @@ package com.stormpath.sdk.servlet.mvc; import com.stormpath.sdk.application.Application; +import com.stormpath.sdk.authc.AuthenticationResult; import com.stormpath.sdk.http.HttpMethod; import com.stormpath.sdk.impl.error.DefaultError; import com.stormpath.sdk.lang.Strings; @@ -28,6 +29,7 @@ import com.stormpath.sdk.servlet.filter.oauth.OAuthErrorCode; import com.stormpath.sdk.servlet.filter.oauth.OAuthException; import com.stormpath.sdk.servlet.http.MediaType; +import com.stormpath.sdk.servlet.http.Saver; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,6 +48,8 @@ public class RevokeTokenController extends AbstractController { private final static String TOKEN = "token"; private final static String TOKEN_TYPE_HINT = "token_type_hint"; + private Saver authenticationResultSaver; + public void init() { } @@ -54,6 +58,10 @@ public boolean isNotAllowedIfAuthenticated() { return false; } + public void setAuthenticationResultSaver(Saver authenticationResultSaver) { + this.authenticationResultSaver = authenticationResultSaver; + } + @Override public ViewModel handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { String method = request.getMethod(); @@ -96,6 +104,8 @@ protected ViewModel doPost(HttpServletRequest request, HttpServletResponse respo this.revoke(getApplication(request), builder.setToken(token).build()); + authenticationResultSaver.set(request, response, null); + response.setStatus(HttpServletResponse.SC_OK); response.setHeader("Content-Length", "0"); diff --git a/extensions/spring/stormpath-spring-webmvc/src/main/java/com/stormpath/spring/config/AbstractStormpathWebMvcConfiguration.java b/extensions/spring/stormpath-spring-webmvc/src/main/java/com/stormpath/spring/config/AbstractStormpathWebMvcConfiguration.java index 0301be0c74..12f2e59400 100644 --- a/extensions/spring/stormpath-spring-webmvc/src/main/java/com/stormpath/spring/config/AbstractStormpathWebMvcConfiguration.java +++ b/extensions/spring/stormpath-spring-webmvc/src/main/java/com/stormpath/spring/config/AbstractStormpathWebMvcConfiguration.java @@ -1225,6 +1225,7 @@ public RevokeTokenControllerConfig stormpathRevokeTokenConfig() { public Controller stormpathRevokeTokenController() { RevokeTokenController c = new RevokeTokenController(); c.setApplicationResolver(stormpathApplicationResolver()); + c.setAuthenticationResultSaver(stormpathAuthenticationResultSaver()); return init(c); } diff --git a/impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicy.java b/impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicy.java index 4bec6c57c1..386055ada6 100644 --- a/impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicy.java +++ b/impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicy.java @@ -17,12 +17,12 @@ import com.stormpath.sdk.application.Application; import com.stormpath.sdk.impl.ds.InternalDataStore; -import com.stormpath.sdk.impl.resource.*; +import com.stormpath.sdk.impl.resource.AbstractInstanceResource; +import com.stormpath.sdk.impl.resource.Property; +import com.stormpath.sdk.impl.resource.ResourceReference; +import com.stormpath.sdk.impl.resource.StringProperty; import com.stormpath.sdk.lang.Assert; import com.stormpath.sdk.oauth.OAuthPolicy; -import com.stormpath.sdk.oauth.openidconnect.Scope; -import com.stormpath.sdk.oauth.openidconnect.ScopeList; -import com.stormpath.sdk.resource.ResourceException; import com.stormpath.sdk.tenant.Tenant; import java.util.Map; @@ -35,23 +35,16 @@ public class DefaultOAuthPolicy extends AbstractInstanceResource implements OAut // SIMPLE PROPERTIES static final StringProperty ACCESS_TOKEN_TTL = new StringProperty("accessTokenTtl"); static final StringProperty REFRESH_TOKEN_TTL = new StringProperty("refreshTokenTtl"); - static final StringProperty ID_TOKEN_TTL = new StringProperty("idTokenTtl"); static final StringProperty TOKEN_ENDPOINT = new StringProperty("tokenEndpoint"); static final StringProperty REVOCATION_ENDPOINT = new StringProperty("revocationEndpoint"); - static final CollectionReference SCOPES = - new CollectionReference<>("scopes", ScopeList.class, Scope.class); - - static final MapProperty ACCESS_TOKEN_ATTRIBUTE_MAPPINGS = new MapProperty("accessTokenAttributeMappings"); - static final MapProperty ID_TOKEN_ATTRIBUTE_MAPPINGS = new MapProperty("idTokenAttributeMappings"); - // INSTANCE RESOURCE REFERENCES: static final ResourceReference APPLICATION = new ResourceReference("application", Application.class); static final ResourceReference TENANT = new ResourceReference("tenant", Tenant.class); private static final Map PROPERTY_DESCRIPTORS = createPropertyDescriptorMap( - ACCESS_TOKEN_TTL, REFRESH_TOKEN_TTL, ID_TOKEN_TTL, TOKEN_ENDPOINT, SCOPES, ACCESS_TOKEN_ATTRIBUTE_MAPPINGS, ID_TOKEN_ATTRIBUTE_MAPPINGS, APPLICATION, TENANT); + ACCESS_TOKEN_TTL, REFRESH_TOKEN_TTL, TOKEN_ENDPOINT, APPLICATION, TENANT); @Override public Map getPropertyDescriptors() { @@ -76,9 +69,6 @@ public String getRefreshTokenTtl() { return getString(REFRESH_TOKEN_TTL); } - @Override - public String getIdTokenTtl() { return getString(ID_TOKEN_TTL); } - @Override public String getTokenEndpoint() { return getString(TOKEN_ENDPOINT); @@ -103,46 +93,6 @@ public OAuthPolicy setRefreshTokenTtl(String refreshTokenTtl) { return this; } - @Override - public OAuthPolicy setIdTokenTtl(String idTokenTtl) { - Assert.notNull(idTokenTtl, "idTokenTtl cannot be null."); - setProperty(ID_TOKEN_TTL, idTokenTtl); - return this; - } - - @Override - public Scope createScope(Scope scope) throws ResourceException { - Assert.notNull(scope, "Scope instance cannot be null."); - return getDataStore().create(getScopes().getHref(), scope); - } - - @Override - public ScopeList getScopes() { - return getResourceProperty(SCOPES); - } - - @Override - public Map getAccessTokenAttributeMap() { - return getMap(ACCESS_TOKEN_ATTRIBUTE_MAPPINGS); - } - - @Override - public OAuthPolicy setAccessTokenAttributeMap(Map accessTokenAttributeMap) { - setProperty(ACCESS_TOKEN_ATTRIBUTE_MAPPINGS, accessTokenAttributeMap); - return this; - } - - @Override - public Map getIdTokenAttributeMap() { - return getMap(ID_TOKEN_ATTRIBUTE_MAPPINGS); - } - - @Override - public OAuthPolicy setIdTokenAttributeMap(Map idTokenAttributeMap) { - setProperty(ID_TOKEN_ATTRIBUTE_MAPPINGS, idTokenAttributeMap); - return this; - } - @Override public Application getApplication() { return getResourceProperty(APPLICATION); diff --git a/impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicyOptions.java b/impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicyOptions.java deleted file mode 100644 index a54acfd031..0000000000 --- a/impl/src/main/java/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicyOptions.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 implements 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); - } -} diff --git a/impl/src/main/java/com/stormpath/sdk/impl/oauth/openidconnect/DefaultScope.java b/impl/src/main/java/com/stormpath/sdk/impl/oauth/openidconnect/DefaultScope.java deleted file mode 100644 index 31af164e66..0000000000 --- a/impl/src/main/java/com/stormpath/sdk/impl/oauth/openidconnect/DefaultScope.java +++ /dev/null @@ -1,124 +0,0 @@ -/* -* 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.openidconnect; - -import com.stormpath.sdk.impl.ds.InternalDataStore; -import com.stormpath.sdk.impl.resource.*; -import com.stormpath.sdk.oauth.OAuthPolicy; -import com.stormpath.sdk.oauth.openidconnect.Scope; - -import java.util.Date; -import java.util.Map; - -/** - * @since 1.6.0 - */ -public class DefaultScope extends AbstractInstanceResource implements Scope { - - static final StringProperty NAME = new StringProperty("name"); - static final StringProperty FRIENDLY_NAME = new StringProperty("friendlyName"); - static final StringProperty DESCRIPTION = new StringProperty("description"); - static final MapProperty ATTRIBUTE_MAPPINGS = new MapProperty("attributeMappings"); - public static final DateProperty CREATED_AT = new DateProperty("createdAt"); - public static final DateProperty MODIFIED_AT = new DateProperty("modifiedAt"); - - static final ResourceReference O_AUTH_POLICY = new ResourceReference<>("oAuthPolicy", OAuthPolicy.class); - - static final Map PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(NAME, FRIENDLY_NAME, DESCRIPTION, ATTRIBUTE_MAPPINGS, O_AUTH_POLICY, CREATED_AT, MODIFIED_AT); - - public DefaultScope(InternalDataStore dataStore) { - super(dataStore); - } - - public DefaultScope(InternalDataStore dataStore, Map properties) { - super(dataStore, properties); - } - - @Override - public Map getPropertyDescriptors() { - return PROPERTY_DESCRIPTORS; - } - - @Override - public String getName() { - return getString(NAME); - } - - @Override - public Scope setName(String name) { - setProperty(NAME, name); - return this; - } - - @Override - public String getFriendlyName() { - return getString(FRIENDLY_NAME); - } - - @Override - public Scope setFriendlyName(String friendlyName) { - setProperty(FRIENDLY_NAME, friendlyName); - return this; - } - - @Override - public String getDescription() { - return getString(DESCRIPTION); - } - - @Override - public Scope setDescription(String description) { - setProperty(DESCRIPTION, description); - return this; - } - - @Override - public Map getAttributeMappings() { - return getMap(ATTRIBUTE_MAPPINGS); - } - - @Override - public Scope setAttributeMappings(Map attributeMappings) { - setProperty(ATTRIBUTE_MAPPINGS, attributeMappings); - return this; - } - - @Override - public OAuthPolicy getOAuthPolicy() { - return getResourceProperty(O_AUTH_POLICY); - } - - @Override - public Scope setOAuthPolicy(OAuthPolicy oAuthPolicy) { - setMaterializableResourceProperty(O_AUTH_POLICY, oAuthPolicy); - return this; - } - - @Override - public void delete() { - getDataStore().delete(this); - } - - @Override - public Date getCreatedAt() { - return getDateProperty(CREATED_AT); - } - - @Override - public Date getModifiedAt() { - return getDateProperty(MODIFIED_AT); - } -} diff --git a/impl/src/main/java/com/stormpath/sdk/impl/oauth/openidconnect/DefaultScopeList.java b/impl/src/main/java/com/stormpath/sdk/impl/oauth/openidconnect/DefaultScopeList.java deleted file mode 100644 index 79b5150cb1..0000000000 --- a/impl/src/main/java/com/stormpath/sdk/impl/oauth/openidconnect/DefaultScopeList.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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.openidconnect; - -import com.stormpath.sdk.impl.ds.InternalDataStore; -import com.stormpath.sdk.impl.resource.AbstractCollectionResource; -import com.stormpath.sdk.impl.resource.ArrayProperty; -import com.stormpath.sdk.impl.resource.Property; -import com.stormpath.sdk.oauth.openidconnect.Scope; -import com.stormpath.sdk.oauth.openidconnect.ScopeList; - -import java.util.Map; - -/** - * @since 1.6.0 - */ -public class DefaultScopeList extends AbstractCollectionResource implements ScopeList { - - private static final ArrayProperty ITEMS = new ArrayProperty<>("items", Scope.class); - - private static final Map PROPERTY_DESCRIPTORS = createPropertyDescriptorMap(OFFSET, LIMIT, ITEMS); - - public DefaultScopeList(InternalDataStore dataStore) { - super(dataStore); - } - - public DefaultScopeList(InternalDataStore dataStore, Map properties) { - super(dataStore, properties); - } - - public DefaultScopeList(InternalDataStore dataStore, Map properties, Map queryParams) { - super(dataStore, properties, queryParams); - } - - @Override - protected Class getItemType() { - return Scope.class; - } - - @Override - public Map getPropertyDescriptors() { - return PROPERTY_DESCRIPTORS; - } -} diff --git a/impl/src/test/groovy/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicyTest.groovy b/impl/src/test/groovy/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicyTest.groovy index 786afe5635..2c0e1df531 100644 --- a/impl/src/test/groovy/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicyTest.groovy +++ b/impl/src/test/groovy/com/stormpath/sdk/impl/oauth/DefaultOAuthPolicyTest.groovy @@ -40,7 +40,7 @@ class DefaultOAuthPolicyTest { OAuthPolicy passwordPolicy = new DefaultOAuthPolicy(createStrictMock(InternalDataStore)) def propertyDescriptors = passwordPolicy.getPropertyDescriptors() - assertEquals(propertyDescriptors.size(), 9) + assertEquals(propertyDescriptors.size(), 5) assertTrue(propertyDescriptors.get("accessTokenTtl") instanceof StringProperty) assertTrue(propertyDescriptors.get("refreshTokenTtl") instanceof StringProperty)