Skip to content

Commit

Permalink
Merge pull request wildfly#6481 from emmartins/WFLY-3587
Browse files Browse the repository at this point in the history
WFLY-3587: removes the need for infinispan module when creating security...
  • Loading branch information
bstansberry committed Jul 11, 2014
2 parents 7f00984 + 7bae1f6 commit df2a5c9
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import javax.security.auth.login.Configuration;
import javax.transaction.TransactionManager;

import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.as.clustering.infinispan.subsystem.EmbeddedCacheManagerService;
import org.jboss.as.controller.AbstractAddStepHandler;
import org.jboss.as.controller.OperationContext;
Expand All @@ -84,13 +83,13 @@
import org.jboss.as.security.service.JaasConfigurationService;
import org.jboss.as.security.service.SecurityDomainService;
import org.jboss.as.security.service.SecurityManagementService;
import org.jboss.as.txn.service.TransactionManagerService;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.Property;
import org.jboss.msc.inject.InjectionException;
import org.jboss.msc.inject.Injector;
import org.jboss.msc.service.ServiceBuilder;
import org.jboss.msc.service.ServiceController;
import org.jboss.msc.service.ServiceName;
import org.jboss.msc.service.ServiceTarget;
import org.jboss.security.ISecurityManagement;
import org.jboss.security.JBossJSSESecurityDomain;
Expand Down Expand Up @@ -180,12 +179,12 @@ public void uninject() {
securityDomainService.getSecurityManagementInjector())
.addDependency(JaasConfigurationService.SERVICE_NAME, Configuration.class,
securityDomainService.getConfigurationInjector())
.addDependency(ServiceBuilder.DependencyType.OPTIONAL, TransactionManagerService.SERVICE_NAME, TransactionManager.class,
.addDependency(ServiceBuilder.DependencyType.OPTIONAL, ServiceName.JBOSS.append("txn", "TransactionManager"), TransactionManager.class,
transactionManagerInjector);

if ("infinispan".equals(cacheType)) {
builder.addDependency(EmbeddedCacheManagerService.getServiceName(CACHE_CONTAINER_NAME),
EmbeddedCacheManager.class, securityDomainService.getCacheManagerInjector());
Object.class, securityDomainService.getCacheManagerInjector());
}

if (verificationHandler != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.security.plugins;

import org.jboss.security.authentication.JBossCachedAuthenticationManager.DomainInfo;

import java.security.Principal;
import java.util.concurrent.ConcurrentMap;

/**
* Factory that creates default {@code ConcurrentMap}s for authentication cache.
*
* @author Eduardo Martins
*/
public interface AuthenticationCacheFactory {

/**
* Returns a cache implementation
*
* @return cache implementation
*/
ConcurrentMap<Principal, DomainInfo> getCache();
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*
* @author <a href="mailto:[email protected]">Marcus Moyses</a>
*/
public class DefaultAuthenticationCacheFactory {
public class DefaultAuthenticationCacheFactory implements AuthenticationCacheFactory {

/**
* Returns a default cache implementation
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2014, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/

package org.jboss.as.security.plugins;

import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.security.authentication.JBossCachedAuthenticationManager.DomainInfo;

import java.security.Principal;
import java.util.concurrent.ConcurrentMap;

/**
* Factory that creates ISPN {@code ConcurrentMap}s for authentication cache.
*
* @author Eduardo Martins
*/
public class InfinispanAuthenticationCacheFactory implements AuthenticationCacheFactory {

private final EmbeddedCacheManager cacheManager;
private final String securityDomain;

/**
*
* @param cacheManager
* @param securityDomain
*/
public InfinispanAuthenticationCacheFactory(Object cacheManager, String securityDomain) {
this.cacheManager = (EmbeddedCacheManager) cacheManager;
this.securityDomain = securityDomain;
}

/**
* Returns a default cache implementation
*
* @return cache implementation
*/
public ConcurrentMap<Principal, DomainInfo> getCache() {
// TODO override global settings with security domain specific
ConfigurationBuilder builder = new ConfigurationBuilder();
Configuration baseCfg = cacheManager.getCacheConfiguration("auth-cache");
if (baseCfg != null) {
builder.read(baseCfg);
}
cacheManager.defineConfiguration(securityDomain, builder.build());
return cacheManager.getCache(securityDomain);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@

package org.jboss.as.security.plugins;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.security.Principal;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.security.auth.callback.CallbackHandler;

import org.infinispan.Cache;
import org.infinispan.configuration.cache.Configuration;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.as.security.logging.SecurityLogger;
import org.jboss.modules.ModuleLoader;
import org.jboss.security.AuthenticationManager;
Expand All @@ -48,6 +34,15 @@
import org.jboss.security.identitytrust.IdentityTrustManager;
import org.jboss.security.mapping.MappingManager;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.security.auth.callback.CallbackHandler;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.security.Principal;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
* JNDI based implementation of {@code ISecurityManagement}
*
Expand Down Expand Up @@ -276,34 +271,13 @@ private Object lookUpJNDI(String contextName) {
* @return an instance of {@code SecurityDomainContext}
* @throws Exception if an error occurs during creation
*/
public SecurityDomainContext createSecurityDomainContext(String securityDomain, Object cacheFactory) throws Exception {
log.debugf("Creating SDC for domain=" + securityDomain);
public SecurityDomainContext createSecurityDomainContext(String securityDomain, AuthenticationCacheFactory cacheFactory) throws Exception {
log.debugf("Creating SDC for domain = %s", securityDomain);
AuthenticationManager am = createAuthenticationManager(securityDomain);
// create authentication cache
if (cacheFactory instanceof EmbeddedCacheManager) {
EmbeddedCacheManager cacheManager = EmbeddedCacheManager.class.cast(cacheFactory);
@SuppressWarnings("rawtypes")
Cache cache = null;
if (cacheManager != null) {
// TODO override global settings with security domain specific
ConfigurationBuilder builder = new ConfigurationBuilder();
Configuration baseCfg = cacheManager.getCacheConfiguration("auth-cache");
if (baseCfg != null) {
builder.read(baseCfg);
}
cacheManager.defineConfiguration(securityDomain, builder.build());
cache = cacheManager.getCache(securityDomain);
}
if (cache != null && am instanceof CacheableManager) {
@SuppressWarnings({ "unchecked", "rawtypes" })
CacheableManager<Map, Principal> cm = (CacheableManager<Map, Principal>) am;
cm.setCache(cache);
}
} else if (cacheFactory instanceof DefaultAuthenticationCacheFactory) {
DefaultAuthenticationCacheFactory cacheManager = DefaultAuthenticationCacheFactory.class.cast(cacheFactory);
@SuppressWarnings("rawtypes")
Map cache = cacheManager.getCache();
if (cache != null && am instanceof CacheableManager) {
if (cacheFactory != null && am instanceof CacheableManager) {
// create authentication cache
final Map<Principal, ?> cache = cacheFactory.getCache();
if (cache != null) {
@SuppressWarnings({ "unchecked", "rawtypes" })
CacheableManager<Map, Principal> cm = (CacheableManager<Map, Principal>) am;
cm.setCache(cache);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@

import javax.security.auth.login.Configuration;

import org.infinispan.manager.EmbeddedCacheManager;
import org.jboss.as.security.SecurityExtension;
import org.jboss.as.security.logging.SecurityLogger;
import org.jboss.as.security.plugins.AuthenticationCacheFactory;
import org.jboss.as.security.plugins.DefaultAuthenticationCacheFactory;
import org.jboss.as.security.plugins.InfinispanAuthenticationCacheFactory;
import org.jboss.as.security.plugins.JNDIBasedSecurityManagement;
import org.jboss.as.security.plugins.SecurityDomainContext;
import org.jboss.msc.inject.Injector;
Expand Down Expand Up @@ -57,7 +58,7 @@ public class SecurityDomainService implements Service<SecurityDomainContext> {

private final InjectedValue<Configuration> configurationValue = new InjectedValue<Configuration>();

private final InjectedValue<EmbeddedCacheManager> cacheManagerValue = new InjectedValue<EmbeddedCacheManager>();
private final InjectedValue<Object> cacheManagerValue = new InjectedValue<>();

private final String name;

Expand Down Expand Up @@ -87,9 +88,9 @@ public void start(StartContext context) throws StartException {
applicationPolicyRegistration.addApplicationPolicy(applicationPolicy.getName(), applicationPolicy);
}
final JNDIBasedSecurityManagement securityManagement = (JNDIBasedSecurityManagement) securityManagementValue.getValue();
Object cacheFactory = null;
AuthenticationCacheFactory cacheFactory = null;
if ("infinispan".equals(cacheType)) {
cacheFactory = cacheManagerValue.getValue();
cacheFactory = new InfinispanAuthenticationCacheFactory(cacheManagerValue.getValue(), name);
} else if ("default".equals(cacheType)) {
cacheFactory = new DefaultAuthenticationCacheFactory();
}
Expand Down Expand Up @@ -150,7 +151,7 @@ public Injector<Configuration> getConfigurationInjector() {
*
* @return target
*/
public Injector<EmbeddedCacheManager> getCacheManagerInjector() {
public Injector<Object> getCacheManagerInjector() {
return cacheManagerValue;
}

Expand Down

0 comments on commit df2a5c9

Please sign in to comment.