Skip to content

Commit

Permalink
MULE-14446: OAuth Module exports internal classes (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
elrodro83 authored Jan 16, 2018
1 parent f097eec commit 3c0af49
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 54 deletions.
8 changes: 2 additions & 6 deletions src/main/java/org/mule/extension/oauth2/OAuthExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,10 @@

import org.mule.extension.http.api.request.authentication.HttpRequestAuthentication;
import org.mule.extension.http.api.request.proxy.HttpProxyConfig;
import org.mule.extension.oauth2.api.authorizationcode.DefaultAuthorizationCodeGrantType;
import org.mule.extension.oauth2.api.clientcredentials.ClientCredentialsGrantType;
import org.mule.extension.oauth2.api.exception.OAuthClientErrors;
import org.mule.extension.oauth2.internal.OAuthOperations;
import org.mule.extension.oauth2.internal.authorizationcode.DefaultAuthorizationCodeGrantType;
import org.mule.extension.oauth2.internal.authorizationcode.state.ConfigOAuthContext;
import org.mule.extension.oauth2.internal.clientcredentials.ClientCredentialsGrantType;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.runtime.extension.api.annotation.Export;
import org.mule.runtime.extension.api.annotation.Extension;
import org.mule.runtime.extension.api.annotation.Import;
import org.mule.runtime.extension.api.annotation.Operations;
Expand All @@ -35,7 +32,6 @@
subTypes = {DefaultAuthorizationCodeGrantType.class, ClientCredentialsGrantType.class})
@ErrorTypes(OAuthClientErrors.class)
@Xml(prefix = "oauth")
@Export(classes = {TokenManagerConfig.class, ConfigOAuthContext.class})
public class OAuthExtension {

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.extension.oauth2.internal.authorizationcode;
package org.mule.extension.oauth2.api.authorizationcode;

import static java.lang.Thread.currentThread;
import static org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded;
import static org.mule.runtime.http.api.HttpHeaders.Names.AUTHORIZATION;
import static org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID;

import org.mule.api.annotation.NoExtend;
import org.mule.api.annotation.NoInstantiate;
import org.mule.extension.http.api.HttpResponseAttributes;
import org.mule.extension.oauth2.internal.AbstractGrantType;
import org.mule.extension.oauth2.internal.authorizationcode.state.ConfigOAuthContext;
Expand Down Expand Up @@ -49,6 +51,8 @@
* authentication code and retrieve the access token
*/
@Alias("authorization-code-grant-type")
@NoExtend
@NoInstantiate
public class DefaultAuthorizationCodeGrantType extends AbstractGrantType {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/

/**
* Classes in this package are not meant to be part of the Java API for this module, but the DSL definitions generated from this
* are API. The way to enforce the API for the DSL is backwards compatible is by enforcing the compatibility of the Java API.
* <p>
* Classes here are not meant to be used directly by a user.
*/
package org.mule.extension.oauth2.api.authorizationcode;
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.extension.oauth2.internal.clientcredentials;
package org.mule.extension.oauth2.api.clientcredentials;

import static java.lang.Thread.currentThread;
import static org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded;
import static org.mule.runtime.http.api.HttpHeaders.Names.AUTHORIZATION;

import org.mule.api.annotation.NoExtend;
import org.mule.api.annotation.NoInstantiate;
import org.mule.extension.http.api.HttpResponseAttributes;
import org.mule.extension.oauth2.internal.AbstractGrantType;
import org.mule.extension.oauth2.internal.store.SimpleObjectStoreToMapAdapter;
Expand All @@ -28,6 +30,8 @@
/**
* Authorization element for client credentials oauth grant type
*/
@NoExtend
@NoInstantiate
public class ClientCredentialsGrantType extends AbstractGrantType {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/

/**
* Classes in this package are not meant to be part of the Java API for this module, but the DSL definitions generated from this
* are API. The way to enforce the API for the DSL is backwards compatible is by enforcing the compatibility of the Java API.
* <p>
* Classes here are not meant to be used directly by a user.
*/
package org.mule.extension.oauth2.api.clientcredentials;
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/
package org.mule.extension.oauth2.internal.tokenmanager;
package org.mule.extension.oauth2.api.tokenmanager;

import org.mule.api.annotation.NoExtend;
import org.mule.api.annotation.NoInstantiate;
import org.mule.extension.oauth2.internal.authorizationcode.state.ConfigOAuthContext;
import org.mule.runtime.api.lifecycle.Disposable;
import org.mule.runtime.api.lifecycle.Initialisable;
Expand Down Expand Up @@ -33,6 +35,8 @@
*/
@Alias("token-manager-config")
@TypeDsl(allowTopLevelDefinition = true)
@NoExtend
@NoInstantiate
public class TokenManagerConfig implements Initialisable, Disposable, MuleContextAware {

public static AtomicInteger defaultTokenManagerConfigIndex = new AtomicInteger(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com
* The software in this package is published under the terms of the CPAL v1.0
* license, a copy of which has been included with this distribution in the
* LICENSE.txt file.
*/

/**
* Classes in this package are not meant to be part of the Java API for this module, but the SDK exports them when dealing with
* this extension even though there are no way to generate instances of this types from expressions.
* <p>
* Classes here are not meant to be used directly by a user.
*/
package org.mule.extension.oauth2.api.tokenmanager;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

import org.mule.extension.http.api.request.authentication.HttpRequestAuthentication;
import org.mule.extension.http.api.request.proxy.HttpProxyConfig;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.runtime.api.exception.MuleException;
import org.mule.runtime.api.lifecycle.InitialisationException;
import org.mule.runtime.api.lifecycle.Lifecycle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
package org.mule.extension.oauth2.internal;

import static java.util.Objects.requireNonNull;
import static org.mule.runtime.api.meta.ExpressionSupport.NOT_SUPPORTED;
import static org.mule.runtime.extension.api.annotation.param.MediaType.TEXT_PLAIN;
import static org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;

import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.runtime.extension.api.annotation.Expression;
import org.mule.runtime.extension.api.annotation.metadata.OutputResolver;
import org.mule.runtime.extension.api.annotation.param.MediaType;
import org.mule.runtime.extension.api.annotation.param.Optional;
Expand All @@ -24,11 +27,11 @@ public class OAuthOperations {

/**
* Clears the oauth context for a token manager and a resource owner id.
*
*
* @param tokenManager The token manager which holds the credentials to invalidate.
* @param resourceOwnerId The resource owner id to invalidate. This attribute is only allowed for authorization code grant type.
*/
public void invalidateOauthContext(TokenManagerConfig tokenManager,
public void invalidateOauthContext(@Expression(NOT_SUPPORTED) TokenManagerConfig tokenManager,
@Optional(defaultValue = DEFAULT_RESOURCE_OWNER_ID) String resourceOwnerId) {
validateResourceOwnerId(resourceOwnerId);
tokenManager.getConfigOAuthContext().clearContextForResourceOwner(resourceOwnerId);
Expand All @@ -42,7 +45,7 @@ public void invalidateOauthContext(TokenManagerConfig tokenManager,
* @return access token of the oauth context retrieved by the token request.
*/
@MediaType(value = TEXT_PLAIN, strict = false)
public String retrieveAccessToken(TokenManagerConfig tokenManager,
public String retrieveAccessToken(@Expression(NOT_SUPPORTED) TokenManagerConfig tokenManager,
@Optional(defaultValue = DEFAULT_RESOURCE_OWNER_ID) String resourceOwnerId) {
validateResourceOwnerId(resourceOwnerId);
return getContextForResourceOwner(tokenManager, resourceOwnerId).getAccessToken();
Expand All @@ -56,7 +59,7 @@ public String retrieveAccessToken(TokenManagerConfig tokenManager,
* @return refresh token of the oauth context retrieved by the token request.
*/
@MediaType(value = TEXT_PLAIN, strict = false)
public String retrieveRefreshToken(TokenManagerConfig tokenManager,
public String retrieveRefreshToken(@Expression(NOT_SUPPORTED) TokenManagerConfig tokenManager,
@Optional(defaultValue = DEFAULT_RESOURCE_OWNER_ID) String resourceOwnerId) {
return getContextForResourceOwner(tokenManager, resourceOwnerId).getRefreshToken();
}
Expand All @@ -69,7 +72,7 @@ public String retrieveRefreshToken(TokenManagerConfig tokenManager,
* @return the expiration of the oauth context retrieved by the token request.
*/
@MediaType(value = TEXT_PLAIN, strict = false)
public String retrieveExpiresIn(TokenManagerConfig tokenManager,
public String retrieveExpiresIn(@Expression(NOT_SUPPORTED) TokenManagerConfig tokenManager,
@Optional(defaultValue = DEFAULT_RESOURCE_OWNER_ID) String resourceOwnerId) {
return getContextForResourceOwner(tokenManager, resourceOwnerId).getExpiresIn();
}
Expand All @@ -82,7 +85,7 @@ public String retrieveExpiresIn(TokenManagerConfig tokenManager,
* @return state of the oauth context retrieved by the token request.
*/
@MediaType(value = TEXT_PLAIN, strict = false)
public String retrieveState(TokenManagerConfig tokenManager,
public String retrieveState(@Expression(NOT_SUPPORTED) TokenManagerConfig tokenManager,
@Optional(defaultValue = DEFAULT_RESOURCE_OWNER_ID) String resourceOwnerId) {
return getContextForResourceOwner(tokenManager, resourceOwnerId).getState();
}
Expand All @@ -97,7 +100,7 @@ public String retrieveState(TokenManagerConfig tokenManager,
* @see AbstractGrantType#parameterExtractors
*/
@OutputResolver(output = TokenResponseParameterOutputResolver.class)
public Object retrieveCustomTokenResponseParam(TokenManagerConfig tokenManager,
public Object retrieveCustomTokenResponseParam(@Expression(NOT_SUPPORTED) TokenManagerConfig tokenManager,
@Optional(defaultValue = DEFAULT_RESOURCE_OWNER_ID) String resourceOwnerId,
String key) {
return getContextForResourceOwner(tokenManager, resourceOwnerId).getTokenResponseParameters().get(key);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
package org.mule.extension.oauth2.internal;

import static org.mule.metadata.api.model.MetadataFormat.JAVA;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;

import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.metadata.api.builder.BaseTypeBuilder;
import org.mule.metadata.api.model.AnyType;
import org.mule.metadata.api.model.MetadataType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import static org.mule.service.oauth.internal.OAuthConstants.REFRESH_TOKEN_PARAMETER;
import static org.mule.service.oauth.internal.OAuthConstants.SCOPE_PARAMETER;

import org.mule.extension.oauth2.internal.authorizationcode.state.ConfigOAuthContext;
import org.mule.functional.junit4.MuleArtifactFunctionalTestCase;
import org.mule.runtime.api.metadata.MediaType;
import org.mule.tck.junit4.rule.DynamicPort;
import org.mule.tck.junit4.rule.SystemProperty;
import org.mule.test.runner.ArtifactClassLoaderRunnerConfig;

import org.junit.Rule;

Expand All @@ -52,6 +54,7 @@

import java.io.UnsupportedEncodingException;

@ArtifactClassLoaderRunnerConfig(exportPluginClasses = {ConfigOAuthContext.class})
public abstract class AbstractOAuthAuthorizationTestCase extends MuleArtifactFunctionalTestCase {

public static final int REQUEST_TIMEOUT = 5000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import static org.mule.service.oauth.internal.OAuthConstants.GRANT_TYPE_REFRESH_TOKEN;
import static org.mule.service.oauth.internal.OAuthConstants.REFRESH_TOKEN_PARAMETER;

import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.internal.authorizationcode.state.ConfigOAuthContext;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.runtime.core.api.event.CoreEvent;
import org.mule.runtime.oauth.api.state.DefaultResourceOwnerOAuthContext;
import org.mule.tck.junit4.rule.SystemProperty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import static org.apache.http.client.fluent.Request.Get;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig.defaultTokenManagerConfigIndex;
import static org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig.getTokenManagerConfigByName;
import static org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig.defaultTokenManagerConfigIndex;
import static org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig.getTokenManagerConfigByName;
import static org.mule.runtime.http.api.utils.HttpEncoderDecoderUtils.appendQueryParam;
import static org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID;
import static org.mule.service.oauth.internal.OAuthConstants.ACCESS_TOKEN_PARAMETER;
Expand All @@ -20,7 +20,7 @@
import static org.mule.service.oauth.internal.OAuthConstants.REFRESH_TOKEN_PARAMETER;
import static org.mule.service.oauth.internal.OAuthConstants.STATE_PARAMETER;

import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.runtime.api.metadata.MediaType;
import org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext;
import org.mule.tck.junit4.rule.DynamicPort;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.nullValue;
import static org.junit.Assert.assertThat;
import static org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig.defaultTokenManagerConfigIndex;
import static org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig.getTokenManagerConfigByName;
import static org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig.defaultTokenManagerConfigIndex;
import static org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig.getTokenManagerConfigByName;
import static org.mule.runtime.http.api.HttpConstants.HttpStatus.BAD_REQUEST;
import static org.mule.runtime.http.api.HttpConstants.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.mule.runtime.http.api.utils.HttpEncoderDecoderUtils.appendQueryParam;
Expand All @@ -26,7 +26,7 @@
import static org.mule.service.oauth.internal.OAuthConstants.STATE_PARAMETER;
import static org.mule.tck.MuleTestUtils.testWithSystemProperty;

import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext;
import org.mule.tck.junit4.rule.DynamicPort;
import org.mule.tck.processor.FlowAssert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
import static org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig.defaultTokenManagerConfigIndex;
import static org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig.getTokenManagerConfigByName;
import static org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig.defaultTokenManagerConfigIndex;
import static org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig.getTokenManagerConfigByName;
import static org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID;
import static org.mule.service.oauth.internal.OAuthConstants.CODE_PARAMETER;

import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext;

import org.apache.http.client.fluent.Request;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import static org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID;

import org.mule.extension.http.api.request.validator.ResponseValidatorTypedException;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.functional.api.exception.ExpectedError;

import org.junit.Rule;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import static org.mule.runtime.http.api.HttpConstants.HttpStatus.INTERNAL_SERVER_ERROR;

import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.internal.authorizationcode.state.ConfigOAuthContext;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.runtime.oauth.api.state.DefaultResourceOwnerOAuthContext;
import org.mule.tck.junit4.rule.SystemProperty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import static org.junit.Assert.assertThat;
import static org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID;

import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext;

import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
import static org.mule.runtime.core.api.lifecycle.LifecycleUtils.initialiseIfNeeded;
import static org.mule.runtime.oauth.api.state.ResourceOwnerOAuthContext.DEFAULT_RESOURCE_OWNER_ID;

import org.mule.extension.oauth2.api.tokenmanager.TokenManagerConfig;
import org.mule.extension.oauth2.internal.authorizationcode.state.ConfigOAuthContext;
import org.mule.extension.oauth2.internal.tokenmanager.TokenManagerConfig;
import org.mule.runtime.oauth.api.state.DefaultResourceOwnerOAuthContext;
import org.mule.test.oauth2.AbstractOAuthAuthorizationTestCase;

Expand Down

0 comments on commit 3c0af49

Please sign in to comment.