List of usage examples for org.apache.commons.lang ArrayUtils contains
public static boolean contains(boolean[] array, boolean valueToFind)
Checks if the value is in the given array.
From source file:net.shopxx.interceptor.LogInterceptor.java
@SuppressWarnings("unchecked") @Override//from w w w . j ava 2 s . c om public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { //List<LogConfig> logConfigs = logConfigService.getAll(); //?????? List<LogConfig> logConfigs = logConfigService.findAll(); if (logConfigs != null) { String path = request.getServletPath(); for (LogConfig logConfig : logConfigs) { if (antPathMatcher.match(logConfig.getUrlPattern(), path)) { String username = adminService.getCurrentUsername(); String operation = logConfig.getOperation(); String operator = username; String content = (String) request.getAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); String ip = request.getRemoteAddr(); request.removeAttribute(Log.LOG_CONTENT_ATTRIBUTE_NAME); StringBuffer parameter = new StringBuffer(); Map<String, String[]> parameterMap = request.getParameterMap(); if (parameterMap != null) { for (Entry<String, String[]> entry : parameterMap.entrySet()) { String parameterName = entry.getKey(); if (!ArrayUtils.contains(ignoreParameters, parameterName)) { String[] parameterValues = entry.getValue(); if (parameterValues != null) { for (String parameterValue : parameterValues) { parameter.append(parameterName + " = " + parameterValue + "\n"); } } } } } Log log = new Log(); log.setOperation(operation); log.setOperator(operator); log.setContent(content); log.setParameter(parameter.toString()); log.setIp(ip); logService.save(log); break; } } } }
From source file:com.kibana.multitenancy.plugin.HTTPSProxyClientCertAuthenticator.java
public User authenticate(RestRequest request, RestChannel channel, AuthenticationBackend backend, Authorizator authorizator) throws AuthException { User user = null;// ww w . j a va2 s .c om try { user = proxyAuthenticator.authenticate(request, channel, backend, authorizator); } catch (AuthException e) { log.debug("Unable to Authenticate using the proxy header. Trying certificate authorization..."); } if (user != null) { if (ArrayUtils.contains(userWhitelists, user.getName())) { log.info( "Denying a request because it has a proxy user header that is the same as one that is whitelisted"); throw new AuthException( "Denying a request because it has a proxy userheader that is the same as one that is whitelisted."); } return user; } try { return certAuthenticator.authenticate(request, channel, backend, authorizator); } catch (AuthException e) { throw new UnauthorizedException(e); } }
From source file:at.ac.tuwien.infosys.jcloudscale.utility.ReflectionUtil.java
/** * Returns a {@link Constructor} object that reflects the specified constructor of the given type. * <p/>/*from w w w .j a v a 2 s .com*/ * If no parameter types are specified i.e., {@code paramTypes} is {@code null} or empty, the default constructor * is returned.<br/> * If a parameter type is not known i.e., it is {@code null}, all declared constructors are checked whether their * parameter types conform to the known parameter types i.e., if every known type is assignable to the parameter * type of the constructor and if exactly one was found, it is returned.<br/> * Otherwise a {@link NoSuchMethodException} is thrown indicating that no or several constructors were found. * * @param type the class * @param paramTypes the full-qualified class names of the parameters (can be {@code null}) * @param classLoader the class loader to use * @return the accessible constructor resolved * @throws NoSuchMethodException if there are zero or more than one constructor candidates * @throws ClassNotFoundException if a class cannot be located by the specified class loader */ @SuppressWarnings("unchecked") public static <T> Constructor<T> findConstructor(Class<T> type, Class<?>... clazzes) throws NoSuchMethodException, ClassNotFoundException { Constructor<T> constructor = null; // If all parameter types are known, find the constructor that exactly matches the signature if (!ArrayUtils.contains(clazzes, null)) { try { constructor = type.getDeclaredConstructor(clazzes); } catch (NoSuchMethodException e) { // Ignore } } // If no constructor was found, find all possible candidates if (constructor == null) { List<Constructor<T>> candidates = new ArrayList<>(1); for (Constructor<T> declaredConstructor : (Constructor<T>[]) type.getDeclaredConstructors()) { if (ClassUtils.isAssignable(clazzes, declaredConstructor.getParameterTypes())) { // Check if there is already a constructor method with the same signature for (int i = 0; i < candidates.size(); i++) { Constructor<T> candidate = candidates.get(i); /** * If all parameter types of constructor A are assignable to the types of constructor B * (at least one type is a subtype of the corresponding parameter), keep the one whose types * are more concrete and drop the other one. */ if (ClassUtils.isAssignable(declaredConstructor.getParameterTypes(), candidate.getParameterTypes())) { candidates.remove(candidate); i--; } else if (ClassUtils.isAssignable(candidate.getParameterTypes(), declaredConstructor.getParameterTypes())) { declaredConstructor = null; break; } } if (declaredConstructor != null) { candidates.add(declaredConstructor); } } } if (candidates.size() != 1) { throw new NoSuchMethodException( String.format("Cannot find distinct constructor for type '%s' with parameter types %s", type, Arrays.toString(clazzes))); } constructor = candidates.get(0); } //do we really need this dependency? //ReflectionUtils.makeAccessible(constructor); if (constructor != null && !constructor.isAccessible()) constructor.setAccessible(true); return constructor; }
From source file:com.lingxiang2014.template.directive.BaseDirective.java
protected List<Filter> getFilters(Map<String, TemplateModel> params, Class<?> type, String... ignoreProperties) throws TemplateModelException { List<Filter> filters = new ArrayList<Filter>(); PropertyDescriptor[] propertyDescriptors = PropertyUtils.getPropertyDescriptors(type); for (PropertyDescriptor propertyDescriptor : propertyDescriptors) { String propertyName = propertyDescriptor.getName(); Class<?> propertyType = propertyDescriptor.getPropertyType(); if (!ArrayUtils.contains(ignoreProperties, propertyName) && params.containsKey(propertyName)) { Object value = FreemarkerUtils.getParameter(propertyName, propertyType, params); filters.add(Filter.eq(propertyName, value)); }//from w w w. java 2 s . c om } return filters; }
From source file:io.fabric8.elasticsearch.plugin.OpenshiftRequestContextFactory.java
@Inject public OpenshiftRequestContextFactory(final Settings settings, final RequestUtils utils, final OpenshiftClientFactory clientFactory) { this.clientFactory = clientFactory; this.utils = utils; this.operationsProjects = settings.getAsArray(ConfigurationSettings.OPENSHIFT_CONFIG_OPS_PROJECTS, ConfigurationSettings.DEFAULT_OPENSHIFT_OPS_PROJECTS); this.kibanaPrefix = settings.get(ConfigurationSettings.KIBANA_CONFIG_INDEX_NAME, ConfigurationSettings.DEFAULT_USER_PROFILE_PREFIX); this.kibanaIndexMode = settings.get(ConfigurationSettings.OPENSHIFT_KIBANA_INDEX_MODE, UNIQUE); if (!ArrayUtils.contains(new String[] { UNIQUE, SHARED_OPS, SHARED_NON_OPS }, kibanaIndexMode.toLowerCase())) { this.kibanaIndexMode = UNIQUE; }/*from www . j a va2s. c om*/ LOGGER.info("Using kibanaIndexMode: '{}'", this.kibanaIndexMode); }
From source file:fr.exanpe.t5.lib.internal.contextpagereset.ContextPageResetFilter.java
public void handlePageRender(PageRenderRequestParameters parameters, ComponentRequestHandler handler) throws IOException { PageRenderRequestParameters p = parameters; if (parameters.getActivationContext() != null && parameters.getActivationContext().toStrings() != null && parameters.getActivationContext().toStrings().length > 0 && ArrayUtils.contains(parameters.getActivationContext().toStrings(), contextMarker)) { if (logger.isDebugEnabled()) { logger.debug(//from ww w .j ava 2s . co m "Context page reset marker {} has been found for page activation {} and will be removed.", contextMarker, parameters.getActivationContext()); } URLEventContext old = (URLEventContext) parameters.getActivationContext(); p = new PageRenderRequestParameters(parameters.getLogicalPageName(), new URLEventContext(contextValueEncoder, (String[]) ArrayUtils.removeElement(old.toStrings(), contextMarker)), false); } handler.handlePageRender(p); }
From source file:com.kibana.multitenancy.plugin.acl.SearchGuardACLRequestActionFilter.java
private boolean isACLRequest(GetRequest request) { return ArrayUtils.contains(request.indices(), armorIndex) && includesProperyValue(request, "type", ARMOR_TYPE) && includesProperyValue(request, "id", ARMOR_ID); }
From source file:gda.device.scannable.DummyPersistentEnumScannable.java
@Override public void asynchronousMoveTo(Object position) throws DeviceException { if (position instanceof PyString) { position = position.toString();/*w w w. jav a2s . co m*/ } if (position instanceof String) { if (ArrayUtils.contains(acceptableStrings, position)) { configuration.setProperty(getName() + "PersistentPosition", position); try { configuration.save(); } catch (ConfigurationException e) { mylogger.error("configuration error when saving to UserConfiguration", e); } notifyIObservers(getName(), position); notifyIObservers(getName(), new ScannablePositionChangeEvent(position.toString())); return; } } else { int pos = Integer.parseInt(position.toString()); if (acceptableStrings.length > pos) { String newpos = acceptableStrings[pos]; configuration.setProperty(getName() + "PersistentPosition", newpos); try { configuration.save(); } catch (ConfigurationException e) { mylogger.error("configuration error when saving to UserConfiguration", e); } notifyIObservers(getName(), newpos); notifyIObservers(getName(), new ScannablePositionChangeEvent(newpos)); return; } } // if get here then value unacceptable throw new DeviceException( "Target position " + position + " unacceptable for DummyPersistentEnumScannable " + getName()); }
From source file:info.magnolia.voting.voters.ExtensionVoter.java
@Override protected boolean boolVote(Object value) { String extension;// ww w. j a v a2 s .c o m if (value instanceof String) { extension = StringUtils.substringAfterLast((String) value, "."); } else { extension = MgnlContext.getAggregationState().getExtension(); } if (StringUtils.isEmpty(MIMEMapping.getMIMEType(extension))) { return false; // check for MIMEMapping, extension must exist } if (allow != null && allow.length > 0 && !ArrayUtils.contains(allow, extension)) { return false; } if (deny != null && deny.length > 0 && ArrayUtils.contains(deny, extension)) { return false; } return true; }
From source file:eu.sofia.adk.common.xsd.JavaDatatype.java
/** * Determines if the datatype is a boolean datatype * @param datatype a string representation of the datatype * @return <code>true</code> if the datatype is a boolean type *//* ww w . j a v a 2 s.c om*/ private static boolean isBooleanDatatype(String datatype) { return ArrayUtils.contains(booleanDatatype, datatype); }