Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #351 from josejulio/bugs/1542125-2
Browse files Browse the repository at this point in the history
Bug 1542125 - Allow the server to start even if we don't have the req…
  • Loading branch information
josejulio committed Sep 20, 2018
2 parents 8146a89 + ef7aec3 commit 176395b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Expand Up @@ -69,6 +69,7 @@
import org.rhq.enterprise.server.rest.domain.GroupRest;
import org.rhq.enterprise.server.rest.domain.ResourceWithType;
import org.rhq.enterprise.server.rest.domain.UserRest;
import org.rhq.enterprise.server.util.LookupUtil;

/**
* Class that deals with user specific stuff
Expand Down Expand Up @@ -98,14 +99,15 @@ public class UserHandlerBean extends AbstractRestBean {
@EJB
private ResourceManagerLocal resourceManager;

@javax.annotation.Resource( name = "ISPNsecurity", mappedName = "java:jboss/infinispan/security")
private CacheContainer cacheContainer;
protected org.infinispan.Cache<CacheKey, Object> authCache;

@PostConstruct
public void start() {
super.start();
this.authCache = this.cacheContainer.getCache("RHQRESTSecurityDomain");
CacheContainer cacheContainer = LookupUtil.getSecurityCacheContainer();
if (cacheContainer != null) {
this.authCache = cacheContainer.getCache("RHQRESTSecurityDomain");
}
}

@GZIP
Expand Down Expand Up @@ -308,6 +310,9 @@ public Response getUserDetails(@ApiParam(value = "Login of the user")
@Path("logout")
@ApiOperation(value = "Force a REST logout by clearing the user cache")
public void logout() {
if (this.authCache == null) {
throw new RuntimeException("RHQRESTSecurityDomain cache or java:jboss/infinispan/security cache container not found");
}
SimplePrincipal principal = new SimplePrincipal(caller.getName());
log.debug("Forcing REST logout of user: [" + principal + "]");
Object cachedValue = this.authCache.remove(principal);
Expand Down
Expand Up @@ -29,6 +29,7 @@
import javax.sql.DataSource;
import javax.transaction.TransactionManager;

import org.infinispan.manager.CacheContainer;
import org.jetbrains.annotations.NotNull;

import org.jboss.mx.util.MBeanProxyExt;
Expand Down Expand Up @@ -282,6 +283,19 @@ public static EntityManager getEntityManager() {
}
}

public static CacheContainer getSecurityCacheContainer() {
try {
InitialContext context = new InitialContext();
CacheContainer cacheContainer = (CacheContainer) context.lookup("java:jboss/infinispan/security");
context.close();
return cacheContainer;
} catch (NamingException e) {
return null;
} catch (Exception e) {
throw new RuntimeException("Failed to get the CacheContainer", e);
}
}

public static CachedConditionProducerBean getActiveConditionProducer() {
return lookupLocal(CachedConditionProducerBean.class);
}
Expand Down

0 comments on commit 176395b

Please sign in to comment.