use of org.apache.geode.security.GemFireSecurityException in project geode by apache.
the class QueueManagerImpl method createNewPrimary.
/**
* Create a new primary server from a non-redundant server.
*
* Add any failed servers to the excludedServers set.
*/
private QueueConnectionImpl createNewPrimary(Set excludedServers) {
QueueConnectionImpl primary = null;
while (primary == null && pool.getPoolOrCacheCancelInProgress() == null) {
List servers = findQueueServers(excludedServers, 1, false, printPrimaryNotFoundError, LocalizedStrings.QueueManagerImpl_COULD_NOT_FIND_SERVER_TO_CREATE_PRIMARY_CLIENT_QUEUE);
// printed above
printPrimaryNotFoundError = false;
if (servers == null || servers.isEmpty()) {
break;
}
Connection connection = null;
try {
connection = factory.createClientToServerConnection((ServerLocation) servers.get(0), true);
} catch (GemFireSecurityException e) {
throw e;
} catch (Exception e) {
if (logger.isDebugEnabled()) {
logger.debug("SubscriptionManagerImpl - error creating a connection to server {}", servers.get(0));
}
}
if (connection != null) {
primary = initializeQueueConnection(connection, true, queueConnections.getFailedUpdater());
}
excludedServers.addAll(servers);
}
if (primary != null && sentClientReady && primary.sendClientReady()) {
readyForEventsAfterFailover(primary);
}
return primary;
}
use of org.apache.geode.security.GemFireSecurityException in project geode by apache.
the class QueueManagerImpl method recoverRedundancy.
/**
* Make sure that we have enough backup servers.
*
* Add any servers we fail to connect to to the excluded servers list.
*/
protected boolean recoverRedundancy(Set excludedServers, boolean recoverInterest) {
if (pool.getPoolOrCacheCancelInProgress() != null) {
return true;
}
int additionalBackups;
while (pool.getPoolOrCacheCancelInProgress() == null && ((additionalBackups = redundancyLevel - getCurrentRedundancy()) > 0 || redundancyLevel == -1)) {
if (redundancyLevel != -1 && printRecoveringRedundant) {
logger.info(LocalizedMessage.create(LocalizedStrings.QueueManagerImpl_SUBSCRIPTION_MANAGER_REDUNDANCY_SATISFIER_REDUNDANT_ENDPOINT_HAS_BEEN_LOST_ATTEMPTIMG_TO_RECOVER));
printRecoveringRedundant = false;
}
List servers = findQueueServers(excludedServers, redundancyLevel == -1 ? -1 : additionalBackups, false, (redundancyLevel == -1 ? false : printRedundancyNotSatisfiedError), LocalizedStrings.QueueManagerImpl_COULD_NOT_FIND_SERVER_TO_CREATE_REDUNDANT_CLIENT_QUEUE);
if (servers == null || servers.isEmpty()) {
if (redundancyLevel != -1) {
if (printRedundancyNotSatisfiedError) {
logger.info(LocalizedMessage.create(LocalizedStrings.QueueManagerImpl_REDUNDANCY_LEVEL_0_IS_NOT_SATISFIED_BUT_THERE_ARE_NO_MORE_SERVERS_AVAILABLE_REDUNDANCY_IS_CURRENTLY_1, new Object[] { redundancyLevel, getCurrentRedundancy() }));
}
}
// printed above
printRedundancyNotSatisfiedError = false;
return false;
}
excludedServers.addAll(servers);
final boolean isDebugEnabled = logger.isDebugEnabled();
for (Iterator itr = servers.iterator(); itr.hasNext(); ) {
ServerLocation server = (ServerLocation) itr.next();
Connection connection = null;
try {
connection = factory.createClientToServerConnection(server, true);
} catch (GemFireSecurityException e) {
throw e;
} catch (Exception e) {
if (isDebugEnabled) {
logger.debug("SubscriptionManager - Error connecting to server: ()", server, e);
}
}
if (connection == null) {
continue;
}
QueueConnectionImpl queueConnection = initializeQueueConnection(connection, false, null);
if (queueConnection != null) {
boolean isFirstNewConnection = false;
synchronized (lock) {
if (recoverInterest && queueConnections.getPrimary() == null && queueConnections.getBackups().isEmpty()) {
// we lost our queue at some point. We Need to recover
// interest. This server will be made primary after this method
// finishes
// because whoever killed the primary when this method started
// should
// have scheduled a task to recover the primary.
isFirstNewConnection = true;
// TODO - Actually, we need a better check than the above. There's
// still a chance
// that we haven't realized that the primary has died but it is
// already gone. We should
// get some information from the queue server about whether it was
// able to copy the
// queue from another server and decide if we need to recover our
// interest based on
// that information.
}
}
boolean promotionFailed = false;
if (isFirstNewConnection) {
if (!promoteBackupCnxToPrimary(queueConnection)) {
promotionFailed = true;
}
}
if (!promotionFailed) {
if (addToConnectionList(queueConnection, isFirstNewConnection)) {
// redundancy satisfied
printRedundancyNotSatisfiedError = true;
printRecoveringRedundant = true;
if (logger.isDebugEnabled()) {
logger.debug("SubscriptionManager redundancy satisfier - created a queue on server {}", queueConnection.getEndpoint());
}
// redundant server.
if (recoverInterest) {
recoverInterest(queueConnection, isFirstNewConnection);
}
}
}
}
}
}
return true;
}
use of org.apache.geode.security.GemFireSecurityException in project geode by apache.
the class IntegratedSecurityService method getSubject.
/**
* It first looks the shiro subject in AccessControlContext since JMX will use multiple threads to
* process operations from the same client, then it looks into Shiro's thead context.
*
* @return the shiro subject, null if security is not enabled
*/
public Subject getSubject() {
if (!isIntegratedSecurity()) {
return null;
}
Subject currentUser = null;
// First try get the principal out of AccessControlContext instead of Shiro's Thread context
// since threads can be shared between JMX clients.
javax.security.auth.Subject jmxSubject = javax.security.auth.Subject.getSubject(AccessController.getContext());
if (jmxSubject != null) {
Set<ShiroPrincipal> principals = jmxSubject.getPrincipals(ShiroPrincipal.class);
if (principals.size() > 0) {
ShiroPrincipal principal = principals.iterator().next();
currentUser = principal.getSubject();
ThreadContext.bind(currentUser);
return currentUser;
}
}
// in other cases like rest call, client operations, we get it from the current thread
currentUser = SecurityUtils.getSubject();
if (currentUser == null || currentUser.getPrincipal() == null) {
throw new GemFireSecurityException("Error: Anonymous User");
}
return currentUser;
}
use of org.apache.geode.security.GemFireSecurityException in project geode by apache.
the class SecurityService method getObjectOfTypeFromClassName.
/**
* this method would never return null, it either throws an exception or returns an object
*/
public static <T> T getObjectOfTypeFromClassName(String className, Class<T> expectedClazz) {
Class actualClass = null;
try {
actualClass = ClassLoadUtil.classFromName(className);
} catch (Exception ex) {
throw new GemFireSecurityException("Instance could not be obtained, " + ex.toString(), ex);
}
if (!expectedClazz.isAssignableFrom(actualClass)) {
throw new GemFireSecurityException("Instance could not be obtained. Expecting a " + expectedClazz.getName() + " class.");
}
T actualObject = null;
try {
actualObject = (T) actualClass.newInstance();
} catch (Exception e) {
throw new GemFireSecurityException("Instance could not be obtained. Error instantiating " + actualClass.getName(), e);
}
return actualObject;
}
use of org.apache.geode.security.GemFireSecurityException in project geode by apache.
the class DynamicRegionFactory method createDynamicRegionImpl.
private Region createDynamicRegionImpl(String parentRegionName, String newRegionName, boolean addEntry) throws CacheException {
Region parentRegion = this.cache.getRegion(parentRegionName);
if (parentRegion == null) {
String errMsg = LocalizedStrings.DynamicRegionFactory_ERROR__COULD_NOT_FIND_A_REGION_NAMED___0_.toLocalizedString(parentRegionName);
RegionDestroyedException e = new RegionDestroyedException(errMsg, parentRegionName);
this.cache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_ERROR__COULD_NOT_FIND_A_REGION_NAMED___0_, parentRegionName, e);
throw e;
}
// Create RegionAttributes by inheriting from the parent
RegionAttributes rra = parentRegion.getAttributes();
AttributesFactory af = new AttributesFactory(rra);
EvictionAttributes ev = rra.getEvictionAttributes();
if (ev != null && ev.getAlgorithm().isLRU()) {
EvictionAttributes rev = new EvictionAttributesImpl((EvictionAttributesImpl) ev);
af.setEvictionAttributes(rev);
}
// regions
if (newRegionName.endsWith("_PRTEST_")) {
af.setPartitionAttributes(new PartitionAttributesFactory().create());
}
RegionAttributes newRegionAttributes = af.create();
Region newRegion;
try {
newRegion = parentRegion.createSubregion(newRegionName, newRegionAttributes);
this.cache.getLoggerI18n().fine("Created dynamic region " + newRegion);
} catch (RegionExistsException ex) {
// a race condition exists that can cause this so just fine log it
this.cache.getLoggerI18n().fine("DynamicRegion " + newRegionName + " in parent " + parentRegionName + " already existed");
newRegion = ex.getRegion();
}
if (addEntry) {
DynamicRegionAttributes dra = new DynamicRegionAttributes();
dra.name = newRegionName;
dra.rootRegionName = parentRegion.getFullPath();
if (this.cache.getLoggerI18n().fineEnabled()) {
this.cache.getLoggerI18n().fine("Putting entry into dynamic region list at key: " + newRegion.getFullPath());
}
this.dynamicRegionList.put(newRegion.getFullPath(), dra);
}
if (this.config.getRegisterInterest()) {
ServerRegionProxy proxy = ((LocalRegion) newRegion).getServerProxy();
if (proxy != null) {
if (((Pool) proxy.getPool()).getSubscriptionEnabled()) {
try {
newRegion.registerInterest("ALL_KEYS");
} catch (GemFireSecurityException ex) {
// Ignore security exceptions here
this.cache.getSecurityLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_EXCEPTION_WHEN_REGISTERING_INTEREST_FOR_ALL_KEYS_IN_DYNAMIC_REGION_0_1, new Object[] { newRegion.getFullPath(), ex });
}
}
}
}
if (regionCreateSleepMillis > 0) {
try {
Thread.sleep(regionCreateSleepMillis);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
}
}
if (this.cache.getLoggerI18n().fineEnabled()) {
this.cache.getLoggerI18n().fine("Created Dynamic Region " + newRegion.getFullPath());
}
return newRegion;
}
Aggregations