private boolean isEnvEntryType(final String type, final Module module) { if (SIMPLE_ENTRIES.contains(type)) { return true; } try { return module.getClassLoader().loadClass(type).isEnum(); } catch (ClassNotFoundException e) { return false; } }
/** * Creates an {@code AuditManager} * * @param securityDomain name of the security domain * @return an instance of {@code AuditManager} * @throws Exception if creation fails */ private AuditManager createAuditManager(String securityDomain) throws Exception { int i = auditManagerClassName.lastIndexOf(":"); if (i == -1) throw SecurityLogger.ROOT_LOGGER.missingModuleName("audit manager class"); String moduleSpec = auditManagerClassName.substring(0, i); String className = auditManagerClassName.substring(i + 1); Class<?> clazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className); Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class }); return (AuditManager) ctr.newInstance(new Object[] { securityDomain }); }
/** * Creates an {@code MappingManager} * * @param securityDomain name of the security domain * @return an instance of {@code MappingManager} * @throws Exception if creation fails */ private MappingManager createMappingManager(String securityDomain) throws Exception { int i = mappingManagerClassName.lastIndexOf(":"); if (i == -1) throw SecurityLogger.ROOT_LOGGER.missingModuleName("mapping manager class"); String moduleSpec = mappingManagerClassName.substring(0, i); String className = mappingManagerClassName.substring(i + 1); Class<?> clazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className); Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class }); return (MappingManager) ctr.newInstance(new Object[] { securityDomain }); }
/** * Creates an {@code AuthorizationManager} * * @param securityDomain name of the security domain * @return an instance of {@code AuthorizationManager} * @throws Exception if creation fails */ private AuthorizationManager createAuthorizationManager(String securityDomain) throws Exception { int i = authorizationManagerClassName.lastIndexOf(":"); if (i == -1) throw SecurityLogger.ROOT_LOGGER.missingModuleName("authorization manager class"); String moduleSpec = authorizationManagerClassName.substring(0, i); String className = authorizationManagerClassName.substring(i + 1); Class<?> clazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className); Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class }); return (AuthorizationManager) ctr.newInstance(new Object[] { securityDomain }); }
/** * Creates an {@code IdentityTrustManager} * * @param securityDomain name of the security domain * @return an instance of {@code IdentityTrustManager} * @throws Exception if creation fails */ private IdentityTrustManager createIdentityTrustManager(String securityDomain) throws Exception { int i = identityTrustManagerClassName.lastIndexOf(":"); if (i == -1) throw SecurityLogger.ROOT_LOGGER.missingModuleName("identity trust manager class"); String moduleSpec = identityTrustManagerClassName.substring(0, i); String className = identityTrustManagerClassName.substring(i + 1); Class<?> clazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className); Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class }); return (IdentityTrustManager) ctr.newInstance(new Object[] { securityDomain }); }
/** * If the class name is found in additionalClasses then return it. * * Otherwise the class will be loaded from the module ClassLoader */ @Override public Class<?> classForName(String name) { try { if (classes.containsKey(name)) { return classes.get(name); } final Class<?> clazz = module.getClassLoader().loadClass(name); classes.put(name, clazz); return clazz; } catch (ClassNotFoundException | LinkageError e) { throw new ResourceLoadingException(e); } }
private Class<?> loadClass(final String module, final String className) throws ClassNotFoundException, ModuleLoadException { if (module != null) { return SecurityActions.getModuleClassLoader(module).loadClass(className); } return SecurityActions.loadClass(className); }
/** * Creates an {@code AuthenticationManager} * * @param securityDomain name of the security domain * @return an instance of {@code AuthenticationManager} * @throws Exception if creation fails */ private AuthenticationManager createAuthenticationManager(String securityDomain) throws Exception { int i = callbackHandlerClassName.lastIndexOf(":"); if (i == -1) throw SecurityLogger.ROOT_LOGGER.missingModuleName("default-callback-handler-class-name attribute"); String moduleSpec = callbackHandlerClassName.substring(0, i); String className = callbackHandlerClassName.substring(i + 1); Class<?> callbackHandlerClazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className); CallbackHandler ch = (CallbackHandler) callbackHandlerClazz.newInstance(); i = authenticationManagerClassName.lastIndexOf(":"); if (i == -1) throw SecurityLogger.ROOT_LOGGER.missingModuleName("authentication-manager-class-name attribute"); moduleSpec = authenticationManagerClassName.substring(0, i); className = authenticationManagerClassName.substring(i + 1); Class<?> clazz = SecurityActions.getModuleClassLoader(loader, moduleSpec).loadClass(className); Constructor<?> ctr = clazz.getConstructor(new Class[] { String.class, CallbackHandler.class }); return (AuthenticationManager) ctr.newInstance(new Object[] { securityDomain, ch }); }
/** * Load class. * * @param visitor the visitor * @param className the class name * @return class or null if null class name */ protected static Class<?> getType(ConfigVisitor visitor, String className) { if (className != null) { try { return visitor.getModule().getClassLoader().loadClass(className); } catch (Exception e) { throw new IllegalArgumentException(e); } } return null; }
static Class<? extends Protocol> findProtocolClass(OperationContext context, String protocolName, String moduleName) throws OperationFailedException { String className = protocolName; if (moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !protocolName.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix)) { className = String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, protocolName); } try { return Module.getContextModuleLoader().loadModule(moduleName).getClassLoader().loadClass(className).asSubclass(Protocol.class); } catch (ClassNotFoundException | ModuleLoadException e) { throw JGroupsLogger.ROOT_LOGGER.unableToLoadProtocolClass(className); } } }
private static Class unwrapClass(ModelNode classModel) throws OperationFailedException { String className = classModel.get(NAME).asString(); String moduleName = classModel.get(MODULE).asString(); try { ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName); Module module = Module.getCallerModuleLoader().loadModule(moduleID); Class<?> clazz = module.getClassLoader().loadClass(className); return clazz; } catch (Exception e) { throw ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName); } } }
private static Class unwrapClass(ModelNode classModel) throws OperationFailedException { String className = classModel.get(NAME).asString(); String moduleName = classModel.get(MODULE).asString(); try { ModuleIdentifier moduleID = ModuleIdentifier.fromString(moduleName); Module module = Module.getCallerModuleLoader().loadModule(moduleID); Class<?> clazz = module.getClassLoader().loadClass(className); return clazz; } catch (Exception e) { throw ROOT_LOGGER.unableToLoadClassFromModule(className, moduleName); } } }
private String inferRemoteInterfaceFromHome(final String homeClassName, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws ClassNotFoundException, DeploymentUnitProcessingException { final Class<?> homeClass = module.getClassLoader().loadClass(homeClassName); final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(homeClass); Class<?> remote = null; for (final Method method : (Iterable<Method>)index.getMethods()) { if (method.getName().startsWith("create")) { if (remote != null && remote != method.getReturnType()) { throw EjbLogger.ROOT_LOGGER.multipleCreateMethod(homeClass); } remote = method.getReturnType(); } } if(remote == null) { throw EjbLogger.ROOT_LOGGER.couldNotDetermineRemoteInterfaceFromHome(homeClassName, description.getEJBName()); } return remote.getName(); }
@Override public void visit(ConfigVisitor visitor) { if (getType() != null) { try { clazz = visitor.getModule().getClassLoader().loadClass(getType()); } catch (ClassNotFoundException e) { throw new IllegalArgumentException(e); } } }
private String inferLocalInterfaceFromLocalHome(final String localHomeClassName, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final SessionBeanComponentDescription description) throws ClassNotFoundException, DeploymentUnitProcessingException { final Class<?> localHomeClass = module.getClassLoader().loadClass(localHomeClassName); final ClassReflectionIndex index = deploymentReflectionIndex.getClassIndex(localHomeClass); Class<?> localClass = null; for (final Method method : (Iterable<Method>)index.getMethods()) { if (method.getName().startsWith("create")) { if (localClass != null && localClass != method.getReturnType()) { throw EjbLogger.ROOT_LOGGER.multipleCreateMethod(localHomeClass); } localClass = method.getReturnType(); } } if (localClass == null) { throw EjbLogger.ROOT_LOGGER.couldNotDetermineLocalInterfaceFromLocalHome(localHomeClassName, description.getEJBName()); } return localClass.getName(); }
/** {@inheritDoc} */ @Override public synchronized void start(StartContext context) throws StartException { SecurityLogger.ROOT_LOGGER.debugf("Starting SubjectFactoryService"); final ISecurityManagement injectedSecurityManagement = securityManagementValue.getValue(); int i = subjectFactoryClassName.lastIndexOf(":"); if (i == -1) throw SecurityLogger.ROOT_LOGGER.missingModuleName("subject-factory-class-name attribute"); String moduleSpec = subjectFactoryClassName.substring(0, i); String className = subjectFactoryClassName.substring(i + 1); JBossSecuritySubjectFactory subjectFactory = null; try { Class<?> subjectFactoryClazz = SecurityActions.getModuleClassLoader(moduleSpec).loadClass(className); subjectFactory = (JBossSecuritySubjectFactory) subjectFactoryClazz.newInstance(); } catch (Exception e) { throw SecurityLogger.ROOT_LOGGER.unableToStartException("SubjectFactoryService", e); } subjectFactory.setSecurityManagement(injectedSecurityManagement); this.subjectFactory = subjectFactory; }
private void processComponentConfig(final DeploymentUnit deploymentUnit, final EEApplicationClasses applicationClasses, final Module module, final DeploymentReflectionIndex deploymentReflectionIndex, final T description) throws DeploymentUnitProcessingException { final Class<?> componentClass; try { componentClass = module.getClassLoader().loadClass(description.getEJBClassName()); } catch (ClassNotFoundException e) { throw EjbLogger.ROOT_LOGGER.failToLoadEjbClass(description.getEJBClassName(), e); } if (!MetadataCompleteMarker.isMetadataComplete(deploymentUnit)) { handleAnnotations(deploymentUnit, applicationClasses, deploymentReflectionIndex, componentClass, description); } handleDeploymentDescriptor(deploymentUnit, deploymentReflectionIndex, componentClass, description); }
private static Class<?> loadClass(String driverName, String moduleName, String className) throws IllegalArgumentException { try { Module module = Module.getCallerModuleLoader().loadModule(moduleName); AgroalLogger.DRIVER_LOGGER.debugf("loaded module '%s' for driver: %s", moduleName, driverName); Class<?> providerClass = module.getClassLoader().loadClass(className); AgroalLogger.DRIVER_LOGGER.driverLoaded(className, driverName); return providerClass; } catch (ModuleLoadException e) { throw AgroalLogger.DRIVER_LOGGER.loadModuleException(e, moduleName); } catch (ClassNotFoundException e) { throw AgroalLogger.DRIVER_LOGGER.loadClassException(e, className); } }
private static void configure(BeanInfo beanInfo, Module module, Object bean, PropertyConfig pc, boolean nullify) throws Throwable { ValueConfig value = pc.getValue(); Class<?> clazz = null; String type = pc.getType(); // check property if (type == null) type = value.getType(); // check value if (type != null) clazz = module.getClassLoader().loadClass(type); Method setter = beanInfo.getSetter(pc.getPropertyName(), clazz); MethodJoinpoint joinpoint = new MethodJoinpoint(setter); ValueConfig param = (nullify == false) ? value : null; joinpoint.setParameters(new ValueConfig[]{param}); joinpoint.setTarget(new ImmediateValue<Object>(bean)); joinpoint.dispatch(); }
@Override public PersistenceConfiguration get() { PersistenceConfiguration persistence = super.get(); StoreConfiguration store = persistence.stores().get(0); try { @SuppressWarnings("unchecked") Class<StoreConfigurationBuilder<?, ?>> storeClass = (Class<StoreConfigurationBuilder<?, ?>>) this.module.get().getClassLoader().loadClass(this.className).asSubclass(StoreConfigurationBuilder.class); return new ConfigurationBuilder().persistence().passivation(persistence.passivation()).addStore(storeClass) .async().read(store.async()) .fetchPersistentState(store.fetchPersistentState()) .preload(store.preload()) .purgeOnStartup(store.purgeOnStartup()) .shared(store.shared()) .withProperties(store.properties()) .persistence().create(); } catch (ClassNotFoundException | ClassCastException e) { throw InfinispanLogger.ROOT_LOGGER.invalidCacheStore(e, this.className); } }