private void assertRealmSecurityManager(SecurityManager securityManager) { if (securityManager == null) { throw new NullPointerException("securityManager instance cannot be null"); } if (!(securityManager instanceof RealmSecurityManager)) { String msg = "securityManager instance is not a " + RealmSecurityManager.class.getName() + " instance. This is required to access or configure realms on the instance."; throw new ConfigurationException(msg); } }
private HashSet<String> getGroups(Topology t, UsernamePasswordToken token){ HashSet<String> groups = null; try { Subject subject = getSubject(getConfig(t)); if(!subject.isAuthenticated()) { subject.login(token); } subject.hasRole(""); //Populate subject groups groups = (HashSet) subject.getSession().getAttribute(SUBJECT_USER_GROUPS); subject.logout(); } catch (AuthenticationException e) { out.println("Error retrieving groups"); out.println(e.toString()); if(debug) { e.printStackTrace(); } else { out.println(debugMessage); } } catch (ConfigurationException e) { out.println(e.toString()); if(debug){ e.printStackTrace(); } } return groups; }
@Override public void contextInitialized(ServletContextEvent sce) { FusekiWebapp.formatBaseArea() ; this.servletContext = sce.getServletContext() ; try { // Shiro. initEnvironment(servletContext); } catch (ConfigurationException ex) { Fuseki.configLog.error("Shiro initialization failed: "+ex.getMessage()); // Exit? throw ex ; } }
private Set<String> getGroups(Topology t, UsernamePasswordToken token){ Set<String> groups = null; try { Subject subject = getSubject(getConfig(t)); if(!subject.isAuthenticated()) { subject.login(token); } subject.hasRole(""); //Populate subject groups groups = (Set) subject.getSession().getAttribute(SUBJECT_USER_GROUPS); subject.logout(); } catch (AuthenticationException e) { out.println("Error retrieving groups"); out.println(e.toString()); if(debug) { e.printStackTrace(); } else { out.println(debugMessage); } } catch (ConfigurationException e) { out.println(e.toString()); if(debug){ e.printStackTrace(); } } return groups; }
@Override public void contextInitialized(ServletContextEvent sce) { FusekiWebapp.formatBaseArea() ; this.servletContext = sce.getServletContext() ; try { // Shiro. initEnvironment(servletContext); } catch (ConfigurationException ex) { Fuseki.configLog.error("Shiro initialization failed: "+ex.getMessage()); // Exit? throw ex ; } }
private Class<? extends WebEnvironment> webEnvironmentClassFromServletContext(ServletContext servletContext) { Class<? extends WebEnvironment> webEnvironmentClass = null; String className = servletContext.getInitParameter(ENVIRONMENT_CLASS_PARAM); if (className != null) { try { webEnvironmentClass = ClassUtils.forName(className); } catch (UnknownClassException ex) { throw new ConfigurationException( "Failed to load custom WebEnvironment class [" + className + "]", ex); } } return webEnvironmentClass; }
/** * Binds the security manager. Override this method in order to provide your own security manager binding. * <p/> * By default, a {@link org.apache.shiro.mgt.DefaultSecurityManager} is bound as an eager singleton. * * @param bind */ protected void bindSecurityManager(AnnotatedBindingBuilder<? super SecurityManager> bind) { try { bind.toConstructor(DefaultSecurityManager.class.getConstructor(Collection.class)).asEagerSingleton(); } catch (NoSuchMethodException e) { throw new ConfigurationException("This really shouldn't happen. Either something has changed in Shiro, or there's a bug in " + ShiroModule.class.getSimpleName(), e); } }
/** * Binds the security manager. Override this method in order to provide your own security manager binding. * <p/> * By default, a {@link org.apache.shiro.web.mgt.DefaultWebSecurityManager} is bound as an eager singleton. * * @param bind */ protected void bindWebSecurityManager(AnnotatedBindingBuilder<? super WebSecurityManager> bind) { try { bind.toConstructor(DefaultWebSecurityManager.class.getConstructor(Collection.class)).asEagerSingleton(); } catch (NoSuchMethodException e) { throw new ConfigurationException("This really shouldn't happen. Either something has changed in Shiro, or there's a bug in ShiroModule.", e); } }
private void setProperty(Object object, String propertyPath, Object value) { try { if (log.isTraceEnabled()) { log.trace("Applying property [{}] value [{}] on object of type [{}]", new Object[]{propertyPath, value, object.getClass().getName()}); } beanUtilsBean.setProperty(object, propertyPath, value); } catch (Exception e) { String msg = "Unable to set property '" + propertyPath + "' with value [" + value + "] on object " + "of type " + (object != null ? object.getClass().getName() : null) + ". If " + "'" + value + "' is a reference to another (previously defined) object, prefix it with " + "'" + OBJECT_REFERENCE_BEGIN_TOKEN + "' to indicate that the referenced " + "object should be used as the actual value. " + "For example, " + OBJECT_REFERENCE_BEGIN_TOKEN + value; throw new ConfigurationException(msg, e); } }
protected boolean isTypedProperty(Object object, String propertyName, Class clazz) { if (clazz == null) { throw new NullPointerException("type (class) argument cannot be null."); } try { PropertyDescriptor descriptor = beanUtilsBean.getPropertyUtils().getPropertyDescriptor(object, propertyName); if (descriptor == null) { String msg = "Property '" + propertyName + "' does not exist for object of " + "type " + object.getClass().getName() + "."; throw new ConfigurationException(msg); } Class propertyClazz = descriptor.getPropertyType(); return clazz.isAssignableFrom(propertyClazz); } catch (ConfigurationException ce) { //let it propagate: throw ce; } catch (Exception e) { String msg = "Unable to determine if property [" + propertyName + "] represents a " + clazz.getName(); throw new ConfigurationException(msg, e); } }
private WebEnvironment webEnvironmentFromServiceLoader() { WebEnvironment webEnvironment = null; // try to load WebEnvironment as a service ServiceLoader<WebEnvironment> serviceLoader = ServiceLoader.load(WebEnvironment.class); Iterator<WebEnvironment> iterator = serviceLoader.iterator(); // Use the first one if (iterator.hasNext()) { webEnvironment = iterator.next(); } // if there are others, throw an error if (iterator.hasNext()) { List<String> allWebEnvironments = new ArrayList<String>(); allWebEnvironments.add(webEnvironment.getClass().getName()); while (iterator.hasNext()) { allWebEnvironments.add(iterator.next().getClass().getName()); } throw new ConfigurationException("ServiceLoader for class [" + WebEnvironment.class + "] returned more then one " + "result. ServiceLoader must return zero or exactly one result for this class. Select one using the " + "servlet init parameter '"+ ENVIRONMENT_CLASS_PARAM +"'. Found: " + allWebEnvironments); } return webEnvironment; }
/** * Loads the INI-formatted text backed by the given InputStream into this instance. This implementation will * close the input stream after it has finished loading. It is expected that the stream's contents are * UTF-8 encoded. * * @param is the {@code InputStream} from which to read the INI-formatted text * @throws ConfigurationException if unable */ public void load(InputStream is) throws ConfigurationException { if (is == null) { throw new NullPointerException("InputStream argument cannot be null."); } InputStreamReader isr; try { isr = new InputStreamReader(is, DEFAULT_CHARSET_NAME); } catch (UnsupportedEncodingException e) { throw new ConfigurationException(e); } load(isr); }
protected int toPort(Object mappedValue) { String[] ports = (String[]) mappedValue; if (ports == null || ports.length == 0) { return getPort(); } if (ports.length > 1) { throw new ConfigurationException("PortFilter can only be configured with a single port. You have " + "configured " + ports.length + ": " + StringUtils.toString(ports)); } return Integer.parseInt(ports[0]); }
protected SecurityManager createInstance(Ini ini) { if (CollectionUtils.isEmpty(ini)) { throw new NullPointerException("Ini argument cannot be null or empty."); } SecurityManager securityManager = createSecurityManager(ini); if (securityManager == null) { String msg = SecurityManager.class + " instance cannot be null."; throw new ConfigurationException(msg); } return securityManager; }
@Deprecated protected static <T extends PathMatchingFilter> Key<T> config(Key<T> baseKey, String configValue) { if( !isGuiceVersion3()) { throw new ConfigurationException("Method ShiroWebModule.config(Key<? extends PathMatchingFilter>, String configValue), is not supported when using Guice 4+"); } return new FilterConfigKey<T>(baseKey, configValue); }
protected void applyChainConfig(String chainName, Filter filter, String chainSpecificFilterConfig) { if (log.isDebugEnabled()) { log.debug("Attempting to apply path [" + chainName + "] to filter [" + filter + "] " + "with config [" + chainSpecificFilterConfig + "]"); } if (filter instanceof PathConfigProcessor) { ((PathConfigProcessor) filter).processPathConfig(chainName, chainSpecificFilterConfig); } else { if (StringUtils.hasText(chainSpecificFilterConfig)) { //they specified a filter configuration, but the Filter doesn't implement PathConfigProcessor //this is an erroneous config: String msg = "chainSpecificFilterConfig was specified, but the underlying " + "Filter instance is not an 'instanceof' " + PathConfigProcessor.class.getName() + ". This is required if the filter is to accept " + "chain-specific configuration."; throw new ConfigurationException(msg); } } }
private void setIndexedProperty(Object object, String propertyPath, int index, Object value) { try { beanUtilsBean.getPropertyUtils().setIndexedProperty(object, propertyPath, index, value); } catch (Exception e) { throw new ConfigurationException("Unable to set array property '" + propertyPath + "'", e); } }
protected void processDefinitions() { try { processRoleDefinitions(); processUserDefinitions(); } catch (ParseException e) { String msg = "Unable to parse user and/or role definitions."; throw new ConfigurationException(msg, e); } }
private Object getProperty(Object object, String propertyPath) { try { return beanUtilsBean.getPropertyUtils().getProperty(object, propertyPath); } catch (Exception e) { throw new ConfigurationException("Unable to access property '" + propertyPath + "'", e); } }
protected void createNewInstance(Map<String, Object> objects, String name, String value) { Object currentInstance = objects.get(name); if (currentInstance != null) { log.info("An instance with name '{}' already exists. " + "Redefining this object as a new instance of type {}", name, value); } Object instance;//name with no property, assume right hand side of equals sign is the class name: try { instance = ClassUtils.newInstance(value); if (instance instanceof Nameable) { ((Nameable) instance).setName(name); } } catch (Exception e) { String msg = "Unable to instantiate class [" + value + "] for object named '" + name + "'. " + "Please ensure you've specified the fully qualified class name correctly."; throw new ConfigurationException(msg, e); } objects.put(name, instance); }