private <T> T createNewTicketValidator(final Class<? extends Cas20ServiceTicketValidator> ticketValidatorClass, final String casServerUrlPrefix, final Class<T> clazz) { if (ticketValidatorClass == null) { return ReflectUtils.newInstance(clazz, casServerUrlPrefix); } return (T) ReflectUtils.newInstance(ticketValidatorClass, casServerUrlPrefix); }
/** * Sets the given property on the target JavaBean using bean instrospection. * @param propertyName Property to set. * @param value Property value to set. * @param target Target java bean on which to set property. */ public static void setProperty(final String propertyName, final Object value, final Object target) { try { setProperty(propertyName, value, target, Introspector.getBeanInfo(target.getClass())); } catch (final IntrospectionException e) { throw new RuntimeException("Failed getting bean info on target JavaBean " + target, e); } }
/** * Sets the CAS ticket validator component. * * @param ticketValidator Ticket validator, MUST NOT be null. */ public void setTicketValidator(final TicketValidator ticketValidator) { CommonUtils.assertNotNull(ticketValidator, "TicketValidator cannot be null"); if (ticketValidator instanceof AbstractUrlBasedTicketValidator) { if (ticketValidator instanceof AbstractCasProtocolUrlBasedTicketValidator) { protocol = Protocol.CAS2; } else { protocol = Protocol.SAML11; } casServerLoginUrl = ReflectUtils.getField("casServerUrlPrefix", ticketValidator) + "/login"; renew = (Boolean) ReflectUtils.getField("renew", ticketValidator); } else { throw new IllegalArgumentException("Unsupported ticket validator " + ticketValidator); } this.ticketValidator = ticketValidator; }
/** * Creates a new instance of the given class by passing the given arguments * to the constructor. * @param className Name of class to be created. * @param args Constructor arguments. * @return New instance of given class. */ public static <T> T newInstance(final String className, final Object... args) { return newInstance(ReflectUtils.<T> loadClass(className), args); }
"Required property casServerUrlPrefix not found."); final Class<TicketValidator> validatorClass = ReflectUtils.loadClass(className); final TicketValidator validator = ReflectUtils.newInstance(validatorClass, propertyMap.get("casServerUrlPrefix")); logger.debug("Attempting to set TicketValidator property {}", property); final String value = (String) propertyMap.get(property); final PropertyDescriptor pd = ReflectUtils.getPropertyDescriptor(info, property); if (pd != null) { ReflectUtils.setProperty(property, convertIfNecessary(pd, value), validator, info); logger.debug("Set {} = {}", property, value); } else {
/** * Gets the property descriptor for the named property on the given class. * @param clazz Class to which property belongs. * @param propertyName Name of property. * @return Property descriptor for given property or null if no property with given * name exists in given class. */ public static PropertyDescriptor getPropertyDescriptor(final Class<?> clazz, final String propertyName) { try { return getPropertyDescriptor(Introspector.getBeanInfo(clazz), propertyName); } catch (final IntrospectionException e) { throw new RuntimeException("Failed getting bean info for " + clazz, e); } }
public Class<? extends T> parse(final String value) { try { return ReflectUtils.loadClass(value); } catch (final IllegalArgumentException e) { return configurationKey.getDefaultValue(); } } });
CommonUtils.assertTrue(propertyMap.containsKey("casServerUrlPrefix"), "Required property casServerUrlPrefix not found."); final Class validatorClass = ReflectUtils.loadClass(className); final TicketValidator validator = (TicketValidator) ReflectUtils.newInstance(validatorClass, new Object[] {propertyMap.get("casServerUrlPrefix")}); log.debug("Attempting to set TicketValidator property " + property); final String value = (String) propertyMap.get(property); final PropertyDescriptor pd = ReflectUtils.getPropertyDescriptor(info, property); if (pd != null) { ReflectUtils.setProperty(property, convertIfNecessary(pd, value), validator, info); log.debug("Set " + property + "=" + value); } else {
/** * Gets the property descriptor for the named property on the given class. * @param clazz Class to which property belongs. * @param propertyName Name of property. * @return Property descriptor for given property or null if no property with given * name exists in given class. */ public static PropertyDescriptor getPropertyDescriptor(final Class clazz, final String propertyName) { try { return getPropertyDescriptor(Introspector.getBeanInfo(clazz), propertyName); } catch (final IntrospectionException e) { throw new RuntimeException("Failed getting bean info for " + clazz, e); } }
/** * Creates a new instance of the given class by passing the given arguments * to the constructor. * @param className Name of class to be created. * @param args Constructor arguments. * @return New instance of given class. */ public static Object newInstance(final String className, final Object[] args) { try { return newInstance(Class.forName(className), args); } catch (final ClassNotFoundException e) { throw new IllegalArgumentException(className + " not found"); } }
/** * Sets the given property on the target javabean using bean instrospection. * @param propertyName Property to set. * @param value Property value to set. * @param target Target java bean on which to set property. */ public static void setProperty(final String propertyName, final Object value, final Object target) { try { setProperty(propertyName, value, target, Introspector.getBeanInfo(target.getClass())); } catch (final IntrospectionException e) { throw new RuntimeException("Failed getting bean info on target javabean " + target, e); } }
/** * Sets the given property on the target JavaBean using bean instrospection. * @param propertyName Property to set. * @param value Property value to set. * @param target Target JavaBean on which to set property. * @param info BeanInfo describing the target JavaBean. */ public static void setProperty(final String propertyName, final Object value, final Object target, final BeanInfo info) { try { final PropertyDescriptor pd = getPropertyDescriptor(info, propertyName); pd.getWriteMethod().invoke(target, value); } catch (final InvocationTargetException e) { throw new RuntimeException("Error setting property " + propertyName, e.getCause()); } catch (final Exception e) { throw new RuntimeException("Error setting property " + propertyName, e); } }
public void testGetFieldSuperclass() { final TestSubBean bean = new TestSubBean(); bean.setName("bob"); assertEquals(bean.getName(), ReflectUtils.getField("name", bean)); }
/** * Gets the configured {@link HostnameVerifier} to use for HTTPS connections * if one is configured for this filter. * @return Instance of specified host name verifier or null if none specified. */ protected HostnameVerifier getHostnameVerifier() { final Class<? extends HostnameVerifier> className = getClass(ConfigurationKeys.HOSTNAME_VERIFIER); final String config = getString(ConfigurationKeys.HOSTNAME_VERIFIER_CONFIG); if (className != null) { if (config != null) { return ReflectUtils.newInstance(className, config); } else { return ReflectUtils.newInstance(className); } } return null; }
/** * Test method for {@link org.jasig.cas.client.util.ReflectUtils#setProperty(java.lang.String, java.lang.Object, java.lang.Object)}. */ public void testSetPropertyStringObjectObject() { final TestBean bean = new TestBean(); ReflectUtils.setProperty("count", new Integer(30000), bean); assertEquals(30000, bean.getCount()); ReflectUtils.setProperty("name", "bob", bean); assertEquals("bob", bean.getName()); ReflectUtils.setProperty("flag", Boolean.TRUE, bean); assertTrue(bean.isFlag()); }
/** * Sets the given property on the target javabean using bean instrospection. * @param propertyName Property to set. * @param value Property value to set. * @param target Target javabean on which to set property. * @param info BeanInfo describing the target javabean. */ public static void setProperty(final String propertyName, final Object value, final Object target, final BeanInfo info) { try { final PropertyDescriptor pd = getPropertyDescriptor(info, propertyName); pd.getWriteMethod().invoke(target, new Object[] { value }); } catch (final InvocationTargetException e) { throw new RuntimeException("Error setting property " + propertyName, e.getCause()); } catch (final Exception e) { throw new RuntimeException("Error setting property " + propertyName, e); } } }
public void testGetField() { final TestBean bean = new TestBean(); bean.setName("bob"); assertEquals(bean.getName(), ReflectUtils.getField("name", bean)); }
public void init(FilterConfig filterConfig) throws ServletException { final String configurationStrategyName = filterConfig.getServletContext().getInitParameter(CONFIGURATION_STRATEGY_KEY); this.configurationStrategy = ReflectUtils.newInstance(ConfigurationStrategyName.resolveToConfigurationStrategy(configurationStrategyName)); this.configurationStrategy.init(filterConfig, getClass()); }
/** * Gets the configured {@link HostnameVerifier} to use for HTTPS connections * if one is configured for this filter. * @param filterConfig Servlet filter configuration. * @return Instance of specified host name verifier or null if none specified. */ protected HostnameVerifier getHostnameVerifier(final FilterConfig filterConfig) { final String className = getPropertyFromInitParams(filterConfig, "hostnameVerifier", null); log.trace("Using hostnameVerifier parameter: " + className); final String config = getPropertyFromInitParams(filterConfig, "hostnameVerifierConfig", null); log.trace("Using hostnameVerifierConfig parameter: " + config); if (className != null) { if (config != null) { return ReflectUtils.newInstance(className, config); } else { return ReflectUtils.newInstance(className); } } return null; }
public void start() throws LifecycleException { super.start(); try { CommonUtils.assertNotNull(this.proxyCallbackUrl, "the proxy callback url cannot be null"); CommonUtils.assertTrue(this.proxyCallbackUrl.startsWith("/"), "proxy callback url must start with \"/\""); PROXY_GRANTING_TICKET_STORAGE = ReflectUtils.newInstance(proxyGrantingTicketStorageClass); } catch (final Exception e) { throw new LifecycleException(e); } logger.info("Startup completed."); }