/** * Get a list of Contextual References by type, regardless of qualifiers (including dependent scoped beans). * * You can use this method to get all contextual references of a given type. A 'Contextual Reference' is a proxy * which will automatically resolve the correct contextual instance when you access any method. * * <p> * <b>Attention:</b> please see the notes on manually resolving @Dependent beans in * {@link #getContextualReference(Class, java.lang.annotation.Annotation...)}!</p> * <p> * <b>Attention:</b> This will also return instances of beans for which an Alternative exists! The @Alternative * resolving is only done via {@link BeanManager#resolve(java.util.Set)} which we cannot use in this case!</p> * * @param type the type of the bean in question * @param optional if <code>true</code> it will return an empty list if no bean could be found or created. Otherwise * it will throw an {@code IllegalStateException} * @param <T> target type * * @return the resolved list of Contextual Reference or an empty-list if optional is true */ public static <T> List<T> getContextualReferences(Class<T> type, boolean optional) { return getContextualReferences(type, optional, true); }
private void checkAuthorizationInfoMarkers() { authorizationInfoRequired = !BeanProvider.getContextualReferences(PrincipalAuthorizationInfoAvailibility.class, true).isEmpty(); }
@PostConstruct public void init() { globalFilterConfigurations = BeanProvider.getContextualReferences(GlobalFilterConfiguration.class, true); }
/** * Get a list of Contextual References by type, regardless of qualifiers (including dependent scoped beans). * * You can use this method to get all contextual references of a given type. A 'Contextual Reference' is a proxy * which will automatically resolve the correct contextual instance when you access any method. * * <p> * <b>Attention:</b> please see the notes on manually resolving @Dependent beans in * {@link #getContextualReference(Class, java.lang.annotation.Annotation...)}!</p> * <p> * <b>Attention:</b> This will also return instances of beans for which an Alternative exists! The @Alternative * resolving is only done via {@link BeanManager#resolve(java.util.Set)} which we cannot use in this case!</p> * * @param type the type of the bean in question * @param optional if <code>true</code> it will return an empty list if no bean could be found or created. Otherwise * it will throw an {@code IllegalStateException} * @param <T> target type * * @return the resolved list of Contextual Reference or an empty-list if optional is true */ public static <T> List<T> getContextualReferences(Class<T> type, boolean optional) { return getContextualReferences(type, optional, true); }
/** * <p>Get a list of Contextual References by type independent of the qualifier * (including dependent scoped beans). * * You can use this method to get all contextual references of a given type. * A 'Contextual Reference' is a proxy which will automatically resolve * the correct contextual instance when you access any method.</p> * * <p><b>Attention:</b> please see the notes on manually resolving @Dependent bean * in {@link #getContextualReference(Class, boolean, java.lang.annotation.Annotation...)}!</p> * <p><b>Attention:</b> This will also return instances of beans for which an Alternative * exists! The @Alternative resolving is only done via {@link BeanManager#resolve(java.util.Set)} * which we cannot use in this case!</p> * * @param type the type of the bean in question * @param optional if <code>true</code> it will return an empty list if no bean could be found or created. * Otherwise it will throw an {@code IllegalStateException} * @param <T> target type * @return the resolved list of Contextual Reference or an empty-list if optional is true */ public static <T> List<T> getContextualReferences(Class<T> type, boolean optional) { return getContextualReferences(type, optional, true); }
@PostConstruct public void init() { securityChecks = BeanProvider.getContextualReferences(SecurityCheck.class, true); }
@PostConstruct public void init() { defineConfigurationSources(); List<TwoStepProvider> references = BeanProvider.getContextualReferences(TwoStepProvider.class, true); twoStepAuthenticationProviderFound = !references.isEmpty(); }
private void addPluginConfiguration(Ini ini) { List<ConfigurationPlugin> plugins = BeanProvider.getContextualReferences(ConfigurationPlugin.class, true, false); orderPlugins(plugins); for (ConfigurationPlugin plugin : plugins) { plugin.addConfiguration(ini); } }
@Override protected void onSuccessfulLogin(AuthenticationToken token, AuthenticationInfo info, Subject subject) { List<AfterSuccessfulLoginHandler> handlers = BeanProvider.getContextualReferences(AfterSuccessfulLoginHandler.class, true); for (AfterSuccessfulLoginHandler handler : handlers) { handler.onSuccessfulLogin(token, info, subject); } super.onSuccessfulLogin(token, info, subject); // TODO Convert the rememberMe to AfterSuccessfulLoginHandler }
private void addManuallyConfiguredUrls(Ini.Section target, Ini.Section source) { Boolean globalAudit = Boolean.valueOf(config.getIsGlobalAuditActive()); List<GlobalFilterConfiguration> globalFilterConfigurations = BeanProvider.getContextualReferences(GlobalFilterConfiguration.class, true); for (Map.Entry<String, String> entry : source.entrySet()) { String value = entry.getValue(); String url = entry.getKey(); if (!url.startsWith("/")) { url = '/' + url; } List<String> additionalFilters = new ArrayList<String>(); if (globalAudit) { additionalFilters.add("audit"); } for (GlobalFilterConfiguration globalFilterConfiguration : globalFilterConfigurations) { additionalFilters.addAll(globalFilterConfiguration.addFiltersTo(url)); } if (!additionalFilters.isEmpty()) { StringBuilder filters = new StringBuilder(); filters.append(value); for (String additionalFilter : additionalFilters) { filters.append(", ").append(additionalFilter); } value = filters.toString(); } target.put(url, value); } }
BeanProvider.getContextualReferences(EntityManager.class, true, false);
@Test public void alternativeImplementationWithClassAsBaseType() { List<BaseBean2> testBeans = BeanProvider.getContextualReferences(BaseBean2.class, true); Assert.assertEquals(1, testBeans.size()); Assert.assertEquals(BaseBean2.class.getName(), testBeans.get(0).getClass().getName()); }
private Ini readURLPatterns() { Ini iniWithURLS = createIni(config.getLocationSecuredURLProperties(), false); //securedURLs.ini is optional since 0.9.7 if (iniWithURLS == null) { iniWithURLS = new Ini(); } if (iniWithURLS.getSectionProperty(APP_URL, "/**") != null) { LOGGER.warn("securedURLs.ini file contains /** definition and thus blocks programmatic URL definition (by system or developer)"); } List<ProgrammaticURLProtectionProvider> urlProtectionProviders = BeanProvider.getContextualReferences(ProgrammaticURLProtectionProvider.class, true); orderURLProtectionProviders(urlProtectionProviders); for (ProgrammaticURLProtectionProvider urlProtectionProvider : urlProtectionProviders) { for (Map.Entry<String, String> entry : urlProtectionProvider.getURLEntriesToAdd().entrySet()) { iniWithURLS.setSectionProperty(APP_URL, entry.getKey(), entry.getValue()); } } iniWithURLS.setSectionProperty(APP_URL, "/**", "anon"); return iniWithURLS; }
@Override protected void onInit() { super.onInit(); securityDataProvider = BeanProvider.getContextualReference(SecurityDataProvider.class); config = BeanProvider.getContextualReference(OctopusConfig.class); twoStepConfig = BeanProvider.getContextualReference(TwoStepConfig.class); codecUtil = BeanProvider.getContextualReference(CodecUtil.class); octopusDefinedAuthenticationInfoList = BeanProvider.getContextualReferences(OctopusDefinedAuthenticationInfo.class, false); octopusDefinedAuthorizationInfoList = BeanProvider.getContextualReferences(OctopusDefinedAuthorizationInfo.class, false); setCachingEnabled(true); setAuthenticationTokenClass(AuthenticationToken.class); setPermissionResolver(BeanProvider.getContextualReference(OctopusPermissionResolver.class)); }
@Test public void multiBeanLookupWithDependentBean() throws Exception { List<MultiBean> result = BeanProvider.getContextualReferences(MultiBean.class, false); Assert.assertNotNull(result); Assert.assertEquals(2, result.size()); }
@Test public void multiBeanLookupWithoutDependentBean() throws Exception { List<MultiBean> result = BeanProvider.getContextualReferences(MultiBean.class, false, false); Assert.assertNotNull(result); Assert.assertEquals(1, result.size()); }
List<Authenticator> references = BeanProvider.getContextualReferences(Authenticator.class, true);
List<Authenticator> references = BeanProvider.getContextualReferences(Authenticator.class, true);
public static AnnotationInfo getAllAnnotations(OctopusConfig config, Class<?> someClassType, Method someMethod) { List<AnnotationsToFind> annotationsToFindList = BeanProvider.getContextualReferences(AnnotationsToFind.class, true); AnnotationInfo result = new AnnotationInfo();