/** * Resolve the method from the given qualified name. Only zero argument methods are supported. */ public static Method methodFromName(String fullyQualifiedMethodName) throws ClassNotFoundException, NoSuchMethodException, SecurityException { int classIndex = fullyQualifiedMethodName.lastIndexOf('.'); if (classIndex <= 0) { throw new ClassNotFoundException( "Static creation function [" + fullyQualifiedMethodName + "] should be fully qualified"); } String className = fullyQualifiedMethodName.substring(0, classIndex); if (checkForPrimType(className) != null) { throw new NoSuchMethodException(className + " cannot be one of the primitive types"); } String methodName = fullyQualifiedMethodName.substring(classIndex + 1); Class<?> result = ClassPathLoader.getLatest().forName(className); return result.getMethod(methodName); }
private void registerFilterClassInMap(Object interest, Long clientID, Map<Object, Map> filts) { // get instance of the filter Class filterClass; InterestFilter filter; try { filterClass = ClassLoadUtil.classFromName((String) interest); filter = (InterestFilter) filterClass.newInstance(); } catch (ClassNotFoundException cnfe) { throw new RuntimeException(String.format("Class %s not found in classpath.", interest), cnfe); } catch (Exception e) { throw new RuntimeException(String.format("Class %s could not be instantiated.", interest), e); } Map interestMap = filts.get(clientID); if (interestMap == null) { interestMap = new CopyOnWriteHashMap(); filts.put(clientID, interestMap); } interestMap.put(interest, filter); }
public AuthorizeRequest(String authzFactoryName, DistributedMember dm, Principal principal, Cache cache) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, NotAuthorizedException { this.principal = principal; if (this.principal instanceof Serializable) { this.isPrincipalSerializable = true; } else { this.isPrincipalSerializable = false; } this.logger = cache.getSecurityLogger(); Method authzMethod = ClassLoadUtil.methodFromName(authzFactoryName); this.authzCallback = (AccessControl) authzMethod.invoke(null, (Object[]) null); this.authzCallback.init(principal, dm, cache); this.id = null; }
/** * 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; try { actualClass = classFromName(className); } catch (Exception e) { throw new GemFireSecurityException("Instance could not be obtained, " + e, e); } if (!expectedClazz.isAssignableFrom(actualClass)) { throw new GemFireSecurityException( "Instance could not be obtained. Expecting a " + expectedClazz.getName() + " class."); } try { return (T) actualClass.newInstance(); } catch (Exception e) { throw new GemFireSecurityException( "Instance could not be obtained. Error instantiating " + actualClass.getName(), e); } }
/** * this method would never return null, it either throws an exception or returns an object */ private static <T> T getObjectOfTypeFromFactoryMethod(String factoryMethodName) { T actualObject; try { Method factoryMethod = methodFromName(factoryMethodName); actualObject = (T) factoryMethod.invoke(null, (Object[]) null); } catch (Exception e) { throw new GemFireSecurityException("Instance could not be obtained from " + factoryMethodName, e); } if (actualObject == null) { throw new GemFireSecurityException( "Instance could not be obtained from " + factoryMethodName); } return actualObject; }
/** * Resolve the class from the given name. Supports primitive types, too. */ public static Class classFromName(String className) throws ClassNotFoundException { Class result = checkForPrimType(className); if (result == null) { result = ClassPathLoader.getLatest().forName(className); } return result; }
/** * Checks whether an MBean implements notification support classes or not * * @return if this MBean can be a notification broadcaster */ public boolean hasNotificationSupport(ObjectName objectName) { try { if (!isRegistered(objectName)) { return false; } ObjectInstance instance = mbeanServer.getObjectInstance(objectName); String className = instance.getClassName(); Class cls = ClassLoadUtil.classFromName(className); Type[] intfTyps = cls.getGenericInterfaces(); for (Type intfTyp1 : intfTyps) { Class intfTyp = (Class) intfTyp1; if (intfTyp.equals(NotificationEmitter.class)) { return true; } } Class superClassType = (Class) cls.getGenericSuperclass(); if (superClassType != null && superClassType.equals(NotificationBroadcasterSupport.class)) { return true; } } catch (InstanceNotFoundException | ClassNotFoundException e) { throw new ManagementException(e); } return false; }
public AuthorizeRequestPP(String postAuthzFactoryName, ClientProxyMembershipID id, Principal principal, Cache cache) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { this.id = id; this.principal = principal; if (this.principal instanceof Serializable) { this.isPrincipalSerializable = true; } else { this.isPrincipalSerializable = false; } this.logger = cache.getSecurityLogger(); Method postAuthzMethod = ClassLoadUtil.methodFromName(postAuthzFactoryName); this.postAuthzCallback = (AccessControl) postAuthzMethod.invoke(null, (Object[]) null); this.postAuthzCallback.init(principal, id.getDistributedMember(), cache); if (this.logger.infoEnabled()) { this.logger.info( String.format( "AuthorizeRequestPP: Setting post process authorization callback to %s for client[%s].", new Object[] {id, postAuthzFactoryName})); } }
@Override public void afterCreate(EntryEvent<String, Object> event) { ObjectName objectName = null; try { if (!service.isStartedAndOpen() || !service.isManager()) { // NO OP return; No work for Non Manager Nodes return; } objectName = ObjectName.getInstance(event.getKey()); FederationComponent newObject = (FederationComponent) event.getNewValue(); String className = newObject.getMBeanInterfaceClass(); Class interfaceClass; if (classRef.get(className) != null) { interfaceClass = classRef.get(className); } else { interfaceClass = ClassLoadUtil.classFromName(className); classRef.put(className, interfaceClass); } service.afterPseudoCreateProxy(objectName, interfaceClass, null, newObject); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("{}: Aggregation Failed failed for {} With Exception {}", THIS_COMPONENT, objectName, e); } } }
return securityService.login(credentials); } else { Method instanceGetter = ClassLoadUtil.methodFromName(authenticatorMethod); auth = (Authenticator) instanceGetter.invoke(null, (Object[]) null); auth.init(securityProperties, logWriter, securityLogWriter);
@Override public void afterUpdate(EntryEvent<String, Object> event) { ObjectName objectName = null; try { if (!service.isStartedAndOpen() || !service.isManager()) { // NO OP return; No work for Non Manager Nodes return; } objectName = ObjectName.getInstance(event.getKey()); FederationComponent oldObject = (FederationComponent) event.getOldValue(); FederationComponent newObject = (FederationComponent) event.getNewValue(); String className = newObject.getMBeanInterfaceClass(); Class interfaceClass; if (classRef.get(className) != null) { interfaceClass = classRef.get(className); } else { interfaceClass = ClassLoadUtil.classFromName(className); classRef.put(className, interfaceClass); } service.afterUpdateProxy(objectName, interfaceClass, null, newObject, oldObject); } catch (Exception e) { if (logger.isDebugEnabled()) { logger.debug("Aggregation Failed failed for {} with exception {}", e); } } }
Method authzMethod = ClassLoadUtil.methodFromName(postAuthzFactoryName); authzCallback = (AccessControl) authzMethod.invoke(null, (Object[]) null); authzCallback.init(principal, member, this.getCache());
InterestFilter filter; try { Class filterClass = ClassLoadUtil.classFromName(key); filter = (InterestFilter) filterClass.newInstance(); } catch (ClassNotFoundException cnfe) {
/** * Creates a single proxy and adds a {@link ProxyInfo} to proxy repository * {@link MBeanProxyInfoRepository} * * @param member {@link org.apache.geode.distributed.DistributedMember} * @param objectName {@link javax.management.ObjectName} of the Bean * @param monitoringRegion monitoring region containing the proxies */ public void createProxy(DistributedMember member, ObjectName objectName, Region<String, Object> monitoringRegion, Object newVal) { try { FederationComponent federationComponent = (FederationComponent) newVal; String interfaceClassName = federationComponent.getMBeanInterfaceClass(); Class interfaceClass = ClassLoadUtil.classFromName(interfaceClassName); Object object = MBeanProxyInvocationHandler.newProxyInstance(member, monitoringRegion, objectName, federationComponent, interfaceClass); jmxAdapter.registerMBeanProxy(object, objectName); if (logger.isDebugEnabled()) { logger.debug("Registered ObjectName : {}", objectName); } ProxyInfo proxyInfo = new ProxyInfo(interfaceClass, object, objectName); proxyRepo.addProxyToRepository(member, proxyInfo); service.afterCreateProxy(objectName, interfaceClass, object, (FederationComponent) newVal); if (logger.isDebugEnabled()) { logger.debug("Proxy Created for : {}", objectName); } } catch (ClassNotFoundException | IntrospectionException e) { throw new ManagementException(e); } }
instance = mbeanServer.getObjectInstance(objectName); String className = instance.getClassName(); Class cls = ClassLoadUtil.classFromName(className); Type[] intfTyps = cls.getGenericInterfaces();
instance = mbeanServer.getObjectInstance(objectName); String className = instance.getClassName(); Class cls = ClassLoadUtil.classFromName(className); Type[] intfTyps = cls.getGenericInterfaces();