openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1778935 - in /openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2: configuration/ provider/
Date Sun, 15 Jan 2017 18:21:15 GMT
Author: rmannibucau
Date: Sun Jan 15 18:21:14 2017
New Revision: 1778935

URL: http://svn.apache.org/viewvc?rev=1778935&view=rev
Log:
reverting cookie default which was not intentional and adding few jcache config for oauth2
module

Added:
    openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/JCacheConfigurer.java
      - copied, changed from r1778650, openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java
    openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheDataProvider.java
      - copied, changed from r1777903, openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java
Modified:
    openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java
    openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Options.java
    openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java

Copied: openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/JCacheConfigurer.java
(from r1778650, openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java)
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/JCacheConfigurer.java?p2=openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/JCacheConfigurer.java&p1=openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java&r1=1778650&r2=1778935&rev=1778935&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/JCacheConfigurer.java
Sun Jan 15 18:21:14 2017
@@ -18,301 +18,122 @@
  */
 package org.apache.meecrowave.oauth2.configuration;
 
-import org.apache.catalina.realm.GenericPrincipal;
 import org.apache.cxf.Bus;
-import org.apache.cxf.interceptor.security.AuthenticationException;
-import org.apache.cxf.jaxrs.ext.MessageContext;
-import org.apache.cxf.message.Message;
-import org.apache.cxf.phase.PhaseInterceptorChain;
-import org.apache.cxf.rs.security.jose.jwe.JweDecryptionProvider;
-import org.apache.cxf.rs.security.jose.jws.JwsSignatureVerifier;
-import org.apache.cxf.rs.security.jose.jws.JwsUtils;
-import org.apache.cxf.rs.security.oauth2.common.OAuthRedirectionState;
-import org.apache.cxf.rs.security.oauth2.common.UserSubject;
-import org.apache.cxf.rs.security.oauth2.grants.AbstractGrantHandler;
-import org.apache.cxf.rs.security.oauth2.grants.clientcred.ClientCredentialsGrantHandler;
-import org.apache.cxf.rs.security.oauth2.grants.code.AuthorizationCodeGrantHandler;
-import org.apache.cxf.rs.security.oauth2.grants.code.DefaultEncryptingCodeDataProvider;
-import org.apache.cxf.rs.security.oauth2.grants.code.JPACodeDataProvider;
-import org.apache.cxf.rs.security.oauth2.grants.jwt.JwtBearerGrantHandler;
-import org.apache.cxf.rs.security.oauth2.grants.owner.JAASResourceOwnerLoginHandler;
-import org.apache.cxf.rs.security.oauth2.grants.owner.ResourceOwnerGrantHandler;
-import org.apache.cxf.rs.security.oauth2.grants.owner.ResourceOwnerLoginHandler;
-import org.apache.cxf.rs.security.oauth2.grants.refresh.RefreshTokenGrantHandler;
-import org.apache.cxf.rs.security.oauth2.provider.AbstractOAuthDataProvider;
-import org.apache.cxf.rs.security.oauth2.provider.AccessTokenGrantHandler;
-import org.apache.cxf.rs.security.oauth2.provider.DefaultEHCacheOAuthDataProvider;
-import org.apache.cxf.rs.security.oauth2.provider.DefaultEncryptingOAuthDataProvider;
+import org.apache.cxf.rs.security.oauth2.common.Client;
+import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken;
+import org.apache.cxf.rs.security.oauth2.grants.code.JCacheCodeDataProvider;
+import org.apache.cxf.rs.security.oauth2.grants.code.ServerAuthorizationCodeGrant;
 import org.apache.cxf.rs.security.oauth2.provider.JCacheOAuthDataProvider;
-import org.apache.cxf.rs.security.oauth2.provider.JPAOAuthDataProvider;
-import org.apache.cxf.rs.security.oauth2.provider.JoseSessionTokenProvider;
-import org.apache.cxf.rs.security.oauth2.provider.OAuthDataProvider;
-import org.apache.cxf.rs.security.oauth2.services.AbstractTokenService;
-import org.apache.cxf.rs.security.oauth2.services.RedirectionBasedGrantService;
-import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
-import org.apache.meecrowave.Meecrowave;
-import org.apache.meecrowave.oauth2.data.RefreshTokenEnabledProvider;
-import org.apache.meecrowave.oauth2.provider.JCacheCodeDataProvider;
-import org.apache.meecrowave.oauth2.resource.OAuth2TokenService;
+import org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken;
 
-import javax.annotation.PostConstruct;
-import javax.crypto.spec.SecretKeySpec;
+import javax.annotation.PreDestroy;
+import javax.cache.CacheException;
+import javax.cache.CacheManager;
+import javax.cache.Caching;
+import javax.cache.configuration.FactoryBuilder;
+import javax.cache.configuration.MutableConfiguration;
+import javax.cache.integration.CacheLoader;
+import javax.cache.integration.CacheWriter;
+import javax.cache.spi.CachingProvider;
 import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
 import javax.inject.Inject;
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
-import java.io.StringReader;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.nio.charset.StandardCharsets;
-import java.security.Principal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.function.Consumer;
-
-import static java.util.Arrays.asList;
-import static java.util.Collections.emptySet;
-import static java.util.Locale.ENGLISH;
+import java.io.File;
+import java.net.URI;
+import java.util.Set;
+
 import static java.util.Optional.ofNullable;
-import static java.util.stream.Collectors.toMap;
-import static org.apache.cxf.rs.security.oauth2.common.AuthenticationMethod.PASSWORD;
+import static org.apache.cxf.jaxrs.utils.ResourceUtils.getClasspathResourceURL;
 
 @ApplicationScoped
-public class OAuth2Configurer {
-    @Inject
-    private Meecrowave.Builder builder;
-
+public class JCacheConfigurer {
     @Inject
     private Bus bus;
 
     @Inject
-    private HttpServletRequest request;
+    private BeanManager bm;
 
-    private Consumer<OAuth2TokenService> tokenServiceConsumer;
-    private Consumer<RedirectionBasedGrantService> redirectionBasedGrantServiceConsumer;
-    private Consumer<AbstractTokenService> abstractTokenServiceConsumer;
-    private OAuth2Options configuration;
-
-    @PostConstruct // TODO: still some missing configuration for jwt etc to add/wire from
OAuth2Options
-    private void preCompute() {
-        configuration = builder.getExtension(OAuth2Options.class);
-
-        AbstractOAuthDataProvider provider;
-        switch (configuration.getProvider().toLowerCase(ENGLISH)) {
-            case "jpa": {
-                if (!configuration.isAuthorizationCodeSupport()) { // else use code impl
-                    final JPAOAuthDataProvider jpaProvider = new JPAOAuthDataProvider();
-                    jpaProvider.setEntityManagerFactory(JPAAdapter.createEntityManagerFactory(configuration));
-                    provider = jpaProvider;
-                    break;
-                }
-            }
-            case "jpa-code": {
-                final JPACodeDataProvider jpaProvider = new JPACodeDataProvider();
-                jpaProvider.setEntityManagerFactory(JPAAdapter.createEntityManagerFactory(configuration));
-                provider = jpaProvider;
-                break;
-            }
-            case "jcache":
-                if (!configuration.isAuthorizationCodeSupport()) { // else use code impl
-                    try {
-                        provider = new JCacheOAuthDataProvider(configuration.getJcacheConfigUri(),
bus, configuration.isJcacheStoreJwtKeyOnly());
-                    } catch (final Exception e) {
-                        throw new IllegalStateException(e);
-                    }
-                    break;
-                }
-            case "jcache-code":
-                try {
-                    provider = new JCacheCodeDataProvider(configuration.getJcacheConfigUri(),
bus);
-                } catch (final Exception e) {
-                    throw new IllegalStateException(e);
-                }
-                break;
-            case "ehcache": // not sure it makes sense since we have jcache but this one
is cheap to support
-                provider = new DefaultEHCacheOAuthDataProvider(configuration.getJcacheConfigUri(),
bus);
-                break;
-            case "encrypted":
-                if (!configuration.isAuthorizationCodeSupport()) { // else use code impl
-                    provider = new DefaultEncryptingOAuthDataProvider(
-                            new SecretKeySpec(configuration.getEncryptedKey().getBytes(StandardCharsets.UTF_8),
configuration.getEncryptedAlgo()));
-                    break;
-                }
-            case "encrypted-code":
-                provider = new DefaultEncryptingCodeDataProvider(
-                        new SecretKeySpec(configuration.getEncryptedKey().getBytes(StandardCharsets.UTF_8),
configuration.getEncryptedAlgo()));
-                break;
-            default:
-                throw new IllegalArgumentException("Unsupported oauth2 provider: " + configuration.getProvider());
+    private CachingProvider provider;
+    private CacheManager cacheManager;
+
+    public void doSetup(final OAuth2Options options) {
+        if (!options.getProvider().startsWith("jcache")) {
+            return;
         }
 
-        final RefreshTokenGrantHandler refreshTokenGrantHandler = new RefreshTokenGrantHandler();
-        refreshTokenGrantHandler.setDataProvider(provider);
-        refreshTokenGrantHandler.setUseAllClientScopes(configuration.isUseAllClientScopes());
-        refreshTokenGrantHandler.setPartialMatchScopeValidation(configuration.isPartialMatchScopeValidation());
+        provider = Caching.getCachingProvider();
 
-        final ResourceOwnerLoginHandler loginHandler = configuration.isJaas() ? new JAASResourceOwnerLoginHandler()
: (name, password) -> {
+        final File file = new File(options.getJcacheConfigUri());
+        URI configFileURI = file.isFile() ? file.toURI() : null;
+        if (configFileURI == null) {
             try {
-                request.login(name, password);
-                try {
-                    final Principal pcp = request.getUserPrincipal();
-                    final UserSubject userSubject = new UserSubject(
-                            name,
-                            GenericPrincipal.class.isInstance(pcp) ?
-                                    new ArrayList<>(asList(GenericPrincipal.class.cast(pcp).getRoles()))
: Collections.emptyList());
-                    userSubject.setAuthenticationMethod(PASSWORD);
-                    return userSubject;
-                } finally {
-                    request.logout();
-                }
-            } catch (final ServletException e) {
-                throw new AuthenticationException(e.getMessage());
+                configFileURI = getClasspathResourceURL(options.getJcacheConfigUri(), JCacheOAuthDataProvider.class,
bus).toURI();
+            } catch (final Exception ex) {
+                configFileURI = provider.getDefaultURI();
             }
-        };
-
-        final List<AccessTokenGrantHandler> handlers = new ArrayList<>();
-        handlers.add(refreshTokenGrantHandler);
-        handlers.add(new ClientCredentialsGrantHandler());
-        handlers.add(new ResourceOwnerGrantHandler() {{
-            setLoginHandler(loginHandler);
-        }});
-        handlers.add(new AuthorizationCodeGrantHandler());
-        handlers.add(new JwtBearerGrantHandler());
-
-        provider.setUseJwtFormatForAccessTokens(configuration.isUseJwtFormatForAccessTokens());
-        provider.setAccessTokenLifetime(configuration.getAccessTokenLifetime());
-        provider.setRefreshTokenLifetime(configuration.getRefreshTokenLifetime());
-        provider.setRecycleRefreshTokens(configuration.isRecycleRefreshTokens());
-        provider.setSupportPreauthorizedTokens(configuration.isSupportPreauthorizedTokens());
-        ofNullable(configuration.getRequiredScopes()).map(s -> asList(s.split(","))).ifPresent(provider::setRequiredScopes);
-        ofNullable(configuration.getDefaultScopes()).map(s -> asList(s.split(","))).ifPresent(provider::setDefaultScopes);
-        ofNullable(configuration.getInvisibleToClientScopes()).map(s -> asList(s.split(","))).ifPresent(provider::setInvisibleToClientScopes);
-        ofNullable(configuration.getJwtAccessTokenClaimMap()).map(s -> new Properties()
{{
-            try {
-                load(new StringReader(s));
-            } catch (IOException e) {
-                throw new IllegalArgumentException("Bad claim map configuration, use properties
syntax");
-            }
-        }}).ifPresent(m -> provider.setJwtAccessTokenClaimMap(new HashMap<>(Map.class.cast(m))));
-
-        final OAuthDataProvider dataProvider;
-        if (configuration.isRefreshToken()) {
-            dataProvider = new RefreshTokenEnabledProvider(provider);
-            if (provider.getInvisibleToClientScopes() == null) {
-                provider.setInvisibleToClientScopes(new ArrayList<>());
-            }
-            provider.getInvisibleToClientScopes().add(OAuthConstants.REFRESH_TOKEN_SCOPE);
-        } else {
-            dataProvider = provider;
         }
 
-        handlers.stream()
-                .filter(AbstractGrantHandler.class::isInstance)
-                .forEach(h -> {
-                    final AbstractGrantHandler handler = AbstractGrantHandler.class.cast(h);
-                    handler.setDataProvider(dataProvider);
-                    handler.setCanSupportPublicClients(configuration.isCanSupportPublicClients());
-                    handler.setPartialMatchScopeValidation(configuration.isPartialMatchScopeValidation());
-                });
-
-        abstractTokenServiceConsumer = s -> { // this is used @RequestScoped so ensure
it is not slow for no reason
-            s.setCanSupportPublicClients(configuration.isCanSupportPublicClients());
-            s.setBlockUnsecureRequests(configuration.isBlockUnsecureRequests());
-            s.setWriteCustomErrors(configuration.isWriteCustomErrors());
-            s.setWriteOptionalParameters(configuration.isWriteOptionalParameters());
-            s.setDataProvider(dataProvider);
-        };
-        tokenServiceConsumer = s -> { // this is used @RequestScoped so ensure it is not
slow for no reason
-            abstractTokenServiceConsumer.accept(s);
-            s.setGrantHandlers(handlers);
-        };
-
-        final List<String> noConsentScopes = ofNullable(configuration.getScopesRequiringNoConsent())
-                .map(s -> asList(s.split(",")))
-                .orElse(null);
-
-        // we prefix them oauth2.cxf. but otherwise it is the plain cxf config
-        final Map<String, String> contextualProperties = ofNullable(builder.getProperties()).map(Properties::stringPropertyNames).orElse(emptySet()).stream()
-                .filter(s -> s.startsWith("oauth2.cxf.rs.security."))
-                .collect(toMap(s -> s.substring("oauth2.cxf.".length()), s -> builder.getProperties().getProperty(s)));
-
-        final JoseSessionTokenProvider sessionAuthenticityTokenProvider = new JoseSessionTokenProvider()
{
-            // getSessionState() is buggy in cxf 3.1.9 so we fix it there
-            private final Method convertStateStringToState;
-
-            {
-                try {
-                    convertStateStringToState = JoseSessionTokenProvider.class.getDeclaredMethod("convertStateStringToState",
String.class);
-                    if (!convertStateStringToState.isAccessible()) {
-                        convertStateStringToState.setAccessible(true);
-                    }
-                } catch (final NoSuchMethodException e) {
-                    throw new IllegalStateException(e);
-                }
-            }
-
-            @Override
-            public OAuthRedirectionState getSessionState(final MessageContext messageContext,
final String sessionToken,
-                                                         final UserSubject subject) {
-                final JweDecryptionProvider jwe = getInitializedDecryptionProvider();
-                final JwsSignatureVerifier jws = getInitializedSigVerifier();
-                String stateString = jwe.decrypt(sessionToken).getContentText();
-                if (jws != null) {
-                    stateString = JwsUtils.verify(jws, stateString).getDecodedJwsPayload();
-                }
-                try {
-                    return OAuthRedirectionState.class.cast(convertStateStringToState.invoke(this,
stateString));
-                } catch (IllegalAccessException e) {
-                    throw new IllegalStateException(e);
-                } catch (InvocationTargetException e) {
-                    final Throwable cause = e.getCause();
-                    if (RuntimeException.class.isInstance(cause)) {
-                        throw RuntimeException.class.cast(cause);
-                    }
-                    throw new IllegalStateException(cause);
-                }
-
+        cacheManager = provider.getCacheManager(configFileURI, Thread.currentThread().getContextClassLoader());
+        try {
+            cacheManager.createCache(
+                    JCacheOAuthDataProvider.CLIENT_CACHE_KEY,
+                    configure(new MutableConfiguration<String, Client>().setTypes(String.class,
Client.class), options));
+            if (!options.isJcacheStoreJwtKeyOnly()/* && options.isUseJwtFormatForAccessTokens()*/)
{
+                cacheManager.createCache(
+                        JCacheOAuthDataProvider.ACCESS_TOKEN_CACHE_KEY,
+                        configure(new MutableConfiguration<String, ServerAccessToken>().setTypes(String.class,
ServerAccessToken.class), options));
+            } else {
+                cacheManager.createCache(
+                        JCacheOAuthDataProvider.ACCESS_TOKEN_CACHE_KEY,
+                        configure(new MutableConfiguration<String, String>().setTypes(String.class,
String.class), options));
+            }
+            cacheManager.createCache(
+                    JCacheOAuthDataProvider.REFRESH_TOKEN_CACHE_KEY,
+                    configure(new MutableConfiguration<String, RefreshToken>().setTypes(String.class,
RefreshToken.class), options));
+            if (options.isAuthorizationCodeSupport()) {
+                cacheManager.createCache(
+                        JCacheCodeDataProvider.CODE_GRANT_CACHE_KEY,
+                        configure(new MutableConfiguration<String, ServerAuthorizationCodeGrant>().setTypes(String.class,
ServerAuthorizationCodeGrant.class), options));
             }
-        };
-        sessionAuthenticityTokenProvider.setMaxDefaultSessionInterval(configuration.getMaxDefaultSessionInterval());
-        // TODO: other configs
-
-        redirectionBasedGrantServiceConsumer = s -> {
-            s.setDataProvider(dataProvider);
-            s.setBlockUnsecureRequests(configuration.isBlockUnsecureRequests());
-            s.setWriteOptionalParameters(configuration.isWriteOptionalParameters());
-            s.setUseAllClientScopes(configuration.isUseAllClientScopes());
-            s.setPartialMatchScopeValidation(configuration.isPartialMatchScopeValidation());
-            s.setUseRegisteredRedirectUriIfPossible(configuration.isUseRegisteredRedirectUriIfPossible());
-            s.setMaxDefaultSessionInterval(configuration.getMaxDefaultSessionInterval());
-            s.setMatchRedirectUriWithApplicationUri(configuration.isMatchRedirectUriWithApplicationUri());
-            s.setScopesRequiringNoConsent(noConsentScopes);
-            s.setSessionAuthenticityTokenProvider(sessionAuthenticityTokenProvider);
-
-            // TODO: make it even more contextual, client based?
-            final Message currentMessage = PhaseInterceptorChain.getCurrentMessage();
-            contextualProperties.forEach(currentMessage::put);
-        };
-    }
-
-    public void accept(final AbstractTokenService service) {
-        abstractTokenServiceConsumer.accept(service);
+        } catch (final CacheException ce) {
+            // already created
+        }
     }
 
-    public void accept(final OAuth2TokenService service) {
-        tokenServiceConsumer.accept(service);
+    private <T> MutableConfiguration<String, T> configure(final MutableConfiguration<String,
T> configuration, final OAuth2Options opts) {
+        ofNullable(opts.getJcacheLoader())
+                .map(n -> lookup(CacheLoader.class, n))
+                .ifPresent(l -> configuration.setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<CacheLoader<String,
T>>(l)));
+        ofNullable(opts.getJcacheWriter())
+                .map(n -> lookup(CacheWriter.class, n))
+                .ifPresent(w -> configuration.setCacheWriterFactory(new FactoryBuilder.SingletonFactory<CacheWriter<String,
T>>(w)));
+        return configuration
+                .setStoreByValue(opts.isJcacheStoreValue())
+                .setStatisticsEnabled(opts.isJcacheStatistics())
+                .setManagementEnabled(opts.isJcacheJmx());
     }
 
-    public void accept(final RedirectionBasedGrantService service) {
-        redirectionBasedGrantServiceConsumer.accept(service);
+    private <U> U lookup(final Class<U> type, final String name) {
+        final Set<Bean<?>> nameSet = bm.getBeans(name);
+        Bean<?> bean = bm.resolve(nameSet);
+        if (bean == null) {
+            try {
+                final Class<?> beanType = Thread.currentThread().getContextClassLoader().loadClass(name.trim());
+                bean = bm.resolve(bm.getBeans(beanType));
+                if (bean == null) {
+                    return type.cast(beanType.newInstance());
+                }
+            } catch (final ClassNotFoundException | InstantiationException | IllegalAccessException
e) {
+                throw new IllegalArgumentException(e);
+            }
+        }
+        return type.cast(bm.getReference(bean, type, bm.createCreationalContext(null)));
     }
 
-    public OAuth2Options getConfiguration() {
-        return configuration;
+    @PreDestroy
+    private void destroy() {
+        cacheManager.close();
+        provider.close();
     }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java?rev=1778935&r1=1778934&r2=1778935&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Configurer.java
Sun Jan 15 18:21:14 2017
@@ -43,7 +43,6 @@ import org.apache.cxf.rs.security.oauth2
 import org.apache.cxf.rs.security.oauth2.provider.AccessTokenGrantHandler;
 import org.apache.cxf.rs.security.oauth2.provider.DefaultEHCacheOAuthDataProvider;
 import org.apache.cxf.rs.security.oauth2.provider.DefaultEncryptingOAuthDataProvider;
-import org.apache.cxf.rs.security.oauth2.provider.JCacheOAuthDataProvider;
 import org.apache.cxf.rs.security.oauth2.provider.JPAOAuthDataProvider;
 import org.apache.cxf.rs.security.oauth2.provider.JoseSessionTokenProvider;
 import org.apache.cxf.rs.security.oauth2.provider.OAuthDataProvider;
@@ -53,6 +52,7 @@ import org.apache.cxf.rs.security.oauth2
 import org.apache.meecrowave.Meecrowave;
 import org.apache.meecrowave.oauth2.data.RefreshTokenEnabledProvider;
 import org.apache.meecrowave.oauth2.provider.JCacheCodeDataProvider;
+import org.apache.meecrowave.oauth2.provider.JCacheDataProvider;
 import org.apache.meecrowave.oauth2.resource.OAuth2TokenService;
 
 import javax.annotation.PostConstruct;
@@ -93,6 +93,9 @@ public class OAuth2Configurer {
     @Inject
     private HttpServletRequest request;
 
+    @Inject
+    private JCacheConfigurer jCacheConfigurer;
+
     private Consumer<OAuth2TokenService> tokenServiceConsumer;
     private Consumer<RedirectionBasedGrantService> redirectionBasedGrantServiceConsumer;
     private Consumer<AbstractTokenService> abstractTokenServiceConsumer;
@@ -120,16 +123,18 @@ public class OAuth2Configurer {
             }
             case "jcache":
                 if (!configuration.isAuthorizationCodeSupport()) { // else use code impl
+                    jCacheConfigurer.doSetup(configuration);
                     try {
-                        provider = new JCacheOAuthDataProvider(configuration.getJcacheConfigUri(),
bus, configuration.isJcacheStoreJwtKeyOnly());
+                        provider = new JCacheDataProvider(configuration, bus);
                     } catch (final Exception e) {
                         throw new IllegalStateException(e);
                     }
                     break;
                 }
             case "jcache-code":
+                jCacheConfigurer.doSetup(configuration);
                 try {
-                    provider = new JCacheCodeDataProvider(configuration.getJcacheConfigUri(),
bus);
+                    provider = new JCacheCodeDataProvider(configuration, bus);
                 } catch (final Exception e) {
                     throw new IllegalStateException(e);
                 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Options.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Options.java?rev=1778935&r1=1778934&r2=1778935&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Options.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/configuration/OAuth2Options.java
Sun Jan 15 18:21:14 2017
@@ -82,6 +82,21 @@ public class OAuth2Options implements Cl
     @CliOption(name = "oauth2-jcache-config", description = "JCache configuration uri for
the cache manager (jcache or provider)")
     private String jcacheConfigUri = "default-oauth2.jcs";
 
+    @CliOption(name = "oauth2-jcache-store-value", description = "Should JCache store value
or not")
+    private boolean jcacheStoreValue = true;
+
+    @CliOption(name = "oauth2-jcache-statistics", description = "Should JCache statistics
be enabled")
+    private boolean jcacheStatistics = false;
+
+    @CliOption(name = "oauth2-jcache-jmx", description = "Should JCache JMX MBeans be enabled")
+    private boolean jcacheJmx = false;
+
+    @CliOption(name = "oauth2-jcache-loader", description = "The loader bean or class name")
+    private String jcacheLoader;
+
+    @CliOption(name = "oauth2-jcache-writer", description = "The writer bean or class name")
+    private String jcacheWriter;
+
     @CliOption(name = "oauth2-jcache-store-jwt-token-key-only", description = "Should JCache
store jwt token key only (jcache provider)")
     private boolean jcacheStoreJwtKeyOnly;
 
@@ -481,4 +496,44 @@ public class OAuth2Options implements Cl
     public void setTokenSupport(final boolean tokenSupport) {
         this.tokenSupport = tokenSupport;
     }
+
+    public boolean isJcacheStoreValue() {
+        return jcacheStoreValue;
+    }
+
+    public void setJcacheStoreValue(final boolean jcacheStoreValue) {
+        this.jcacheStoreValue = jcacheStoreValue;
+    }
+
+    public String getJcacheLoader() {
+        return jcacheLoader;
+    }
+
+    public void setJcacheLoader(final String jcacheLoader) {
+        this.jcacheLoader = jcacheLoader;
+    }
+
+    public String getJcacheWriter() {
+        return jcacheWriter;
+    }
+
+    public void setJcacheWriter(final String jcacheWriter) {
+        this.jcacheWriter = jcacheWriter;
+    }
+
+    public boolean isJcacheStatistics() {
+        return jcacheStatistics;
+    }
+
+    public void setJcacheStatistics(final boolean jcacheStatistics) {
+        this.jcacheStatistics = jcacheStatistics;
+    }
+
+    public boolean isJcacheJmx() {
+        return jcacheJmx;
+    }
+
+    public void setJcacheJmx(final boolean jcacheJmx) {
+        this.jcacheJmx = jcacheJmx;
+    }
 }

Modified: openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java?rev=1778935&r1=1778934&r2=1778935&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java
Sun Jan 15 18:21:14 2017
@@ -19,12 +19,13 @@
 package org.apache.meecrowave.oauth2.provider;
 
 import org.apache.cxf.Bus;
+import org.apache.meecrowave.oauth2.configuration.OAuth2Options;
 
 import javax.enterprise.inject.Vetoed;
 
 @Vetoed
 public class JCacheCodeDataProvider extends org.apache.cxf.rs.security.oauth2.grants.code.JCacheCodeDataProvider
{
-    public JCacheCodeDataProvider(final String configFileURL, final Bus bus) throws Exception
{
-        super(configFileURL, bus);
+    public JCacheCodeDataProvider(final OAuth2Options configuration, final Bus bus) throws
Exception {
+        super(configuration.getJcacheConfigUri(), bus);
     }
 }

Copied: openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheDataProvider.java
(from r1777903, openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java)
URL: http://svn.apache.org/viewvc/openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheDataProvider.java?p2=openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheDataProvider.java&p1=openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java&r1=1777903&r2=1778935&rev=1778935&view=diff
==============================================================================
--- openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheCodeDataProvider.java
(original)
+++ openwebbeans/meecrowave/trunk/meecrowave-oauth2/src/main/java/org/apache/meecrowave/oauth2/provider/JCacheDataProvider.java
Sun Jan 15 18:21:14 2017
@@ -19,12 +19,14 @@
 package org.apache.meecrowave.oauth2.provider;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.rs.security.oauth2.provider.JCacheOAuthDataProvider;
+import org.apache.meecrowave.oauth2.configuration.OAuth2Options;
 
 import javax.enterprise.inject.Vetoed;
 
 @Vetoed
-public class JCacheCodeDataProvider extends org.apache.cxf.rs.security.oauth2.grants.code.JCacheCodeDataProvider
{
-    public JCacheCodeDataProvider(final String configFileURL, final Bus bus) throws Exception
{
-        super(configFileURL, bus);
+public class JCacheDataProvider extends JCacheOAuthDataProvider {
+    public JCacheDataProvider(final OAuth2Options configuration, final Bus bus) throws Exception
{
+        super(configuration.getJcacheConfigUri(), bus, configuration.isJcacheStoreJwtKeyOnly());
     }
 }



Mime
View raw message