Search in sources :

Example 31 with GemFireSecurityException

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;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireException(org.apache.geode.GemFireException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireConfigException(org.apache.geode.GemFireConfigException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException)

Example 32 with GemFireSecurityException

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;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) CancelException(org.apache.geode.CancelException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireException(org.apache.geode.GemFireException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) GemFireConfigException(org.apache.geode.GemFireConfigException) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException)

Example 33 with GemFireSecurityException

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;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) ShiroPrincipal(org.apache.geode.internal.security.shiro.ShiroPrincipal) Subject(org.apache.shiro.subject.Subject)

Example 34 with GemFireSecurityException

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;
}
Also used : GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException)

Example 35 with GemFireSecurityException

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;
}
Also used : DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) EvictionAttributesImpl(org.apache.geode.internal.cache.EvictionAttributesImpl) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Pool(org.apache.geode.cache.client.Pool)

Aggregations

GemFireSecurityException (org.apache.geode.security.GemFireSecurityException)39 IOException (java.io.IOException)18 GemFireConfigException (org.apache.geode.GemFireConfigException)13 CancelException (org.apache.geode.CancelException)9 LocalRegion (org.apache.geode.internal.cache.LocalRegion)8 Part (org.apache.geode.internal.cache.tier.sockets.Part)8 AuthenticationRequiredException (org.apache.geode.security.AuthenticationRequiredException)8 GatewayConfigurationException (org.apache.geode.cache.GatewayConfigurationException)7 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)7 ServerRefusedConnectionException (org.apache.geode.cache.client.ServerRefusedConnectionException)7 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)7 CacheServerStats (org.apache.geode.internal.cache.tier.sockets.CacheServerStats)7 AuthenticationFailedException (org.apache.geode.security.AuthenticationFailedException)7 EOFException (java.io.EOFException)6 ByteBuffer (java.nio.ByteBuffer)6 Properties (java.util.Properties)6 InternalGemFireException (org.apache.geode.InternalGemFireException)5 EventID (org.apache.geode.internal.cache.EventID)5 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)5 CachedRegionHelper (org.apache.geode.internal.cache.tier.CachedRegionHelper)5