List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:org.elasticsoftware.elasterix.server.actors.User.java
private final boolean authenticate(ActorRef dialog, SipRequestMessage request, State state) { if (log.isDebugEnabled()) { log.debug(String.format("onReceive. Authenticating %s[%s]", request.getMethod(), state.getUsername())); }//from www . jav a 2 s. c om switch (request.getSipMethod()) { case REGISTER: // check if authentication is present... String authorization = request.getHeader(SipHeader.AUTHORIZATION); if (!StringUtils.hasLength(authorization)) { if (log.isDebugEnabled()) log.debug("authenticate. No authorization set"); return false; } Map<String, String> map = request.tokenize(SipHeader.AUTHORIZATION); // check username String val = map.get("username"); if (!state.getUsername().equalsIgnoreCase(val)) { if (log.isDebugEnabled()) log.debug(String.format("authenticate. Provided username[%s] " + "!= given username[%s]", val, state.getUsername())); return false; } // check nonce val = map.get("nonce"); if (!state.getNonce().equalsIgnoreCase(val)) { if (log.isDebugEnabled()) log.debug(String.format("authenticate. Provided nonce[%s] " + "!= given nonce[%s]", val, state.getNonce())); return false; } // check hash val = map.get("response"); String secretHash = generateHash(state, map); if (!secretHash.equals(val)) { if (log.isDebugEnabled()) log.debug(String.format("authenticate. Provided hash[%s] " + "!= given hash[%s]", val, secretHash)); return false; } return true; case INVITE: // check if we have a UAC registered for user Long expires = state.getUserAgentClient(request.getSipUser(SipHeader.CONTACT)); if (expires == null || expires.longValue() < System.currentTimeMillis()) { return false; } else { return true; } } return false; }
From source file:grails.plugin.cache.web.filter.PageFragmentCachingFilter.java
protected PageInfo buildCachedPageInfo(HttpServletRequest request, HttpServletResponse response, CacheStatus cacheStatus) throws Exception { Timer timer = new Timer(getCachedUri(request)); timer.start();//from w ww . j ava 2 s . co m String key = calculateKey(request); PageInfo pageInfo; ValueWrapper element = cacheStatus.valueWrapper; log.debug("Serving cached content for {}", key); pageInfo = (PageInfo) element.get(); for (Map.Entry<String, ? extends Serializable> entry : pageInfo.getRequestAttributes().entrySet()) { request.setAttribute(entry.getKey(), entry.getValue()); } // As the page is cached, we need to add an instance of the associated // controller to the request. This is required by GrailsLayoutDecoratorMapper // to pick the appropriate layout. if (StringUtils.hasLength(getContext().getControllerName())) { Object controller = lookupController(getContext().getControllerClass()); request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controller); } timer.stop(true); response.addHeader(X_CACHED, String.valueOf(true)); return pageInfo; }
From source file:org.grails.datastore.gorm.finders.DynamicFinder.java
private static String calcPropertyName(String queryParameter, String clause) { String propName;//from w ww . ja v a2s.com if (clause != null && !clause.equals(Equal.class.getSimpleName())) { int i = queryParameter.indexOf(clause); propName = queryParameter.substring(0, i); } else { propName = queryParameter; } if (propName.endsWith(NOT)) { int i = propName.lastIndexOf(NOT); propName = propName.substring(0, i); } if (!StringUtils.hasLength(propName)) { throw new IllegalArgumentException("No property name specified in clause: " + clause); } return propName.substring(0, 1).toLowerCase(Locale.ENGLISH) + propName.substring(1); }
From source file:org.jasypt.spring31.xml.encryption.DigesterConfigBeanDefinitionParser.java
@Override protected void doParse(final Element element, final BeanDefinitionBuilder builder) { processStringAttribute(element, builder, PARAM_ALGORITHM, "algorithm"); processIntegerAttribute(element, builder, PARAM_ITERATIONS, "iterations"); processIntegerAttribute(element, builder, PARAM_SALT_SIZE_BYTES, "saltSizeBytes"); processBeanAttribute(element, builder, PARAM_SALT_GENERATOR_BEAN, "saltGenerator"); processStringAttribute(element, builder, PARAM_SALT_GENERATOR_CLASS_NAME, "saltGeneratorClassName"); processBeanAttribute(element, builder, PARAM_PROVIDER_BEAN, "provider"); processStringAttribute(element, builder, PARAM_PROVIDER_CLASS_NAME, "providerClassName"); processStringAttribute(element, builder, PARAM_PROVIDER_NAME, "providerName"); processBooleanAttribute(element, builder, PARAM_INVERT_POSITION_OF_SALT_IN_MESSAGE_BEFORE_DIGESTING, "invertPositionOfSaltInMessageBeforeDigesting"); processBooleanAttribute(element, builder, PARAM_INVERT_POSITION_OF_PLAIN_SALT_IN_ENCRYPTION_RESULTS, "invertPositionOfPlainSaltInEncryptionResults"); processBooleanAttribute(element, builder, PARAM_USE_LENIENT_SALT_SIZE_CHECK, "useLenientSaltSizeCheck"); processIntegerAttribute(element, builder, PARAM_POOL_SIZE, "poolSize"); processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE, "stringOutputType"); processStringAttribute(element, builder, PARAM_UNICODE_NORMALIZATION_IGNORED, "unicodeNormalizationIgnored"); processStringAttribute(element, builder, PARAM_PREFIX, "prefix"); processStringAttribute(element, builder, PARAM_SUFFIX, "suffix"); processStringAttribute(element, builder, PARAM_ALGORITHM_ENV_NAME, "algorithmEnvName"); processStringAttribute(element, builder, PARAM_ITERATIONS_ENV_NAME, "iterationsEnvName"); processStringAttribute(element, builder, PARAM_SALT_SIZE_BYTES_ENV_NAME, "saltSizeBytesEnvName"); processStringAttribute(element, builder, PARAM_SALT_GENERATOR_CLASS_NAME_ENV_NAME, "saltGeneratorClassNameEnvName"); processStringAttribute(element, builder, PARAM_PROVIDER_CLASS_NAME_ENV_NAME, "providerClassNameEnvName"); processStringAttribute(element, builder, PARAM_PROVIDER_NAME_ENV_NAME, "providerNameEnvName"); processStringAttribute(element, builder, PARAM_INVERT_POSITION_OF_SALT_IN_MESSAGE_BEFORE_DIGESTING_ENV_NAME, "invertPositionOfSaltInMessageBeforeDigestingEnvName"); processStringAttribute(element, builder, PARAM_INVERT_POSITION_OF_PLAIN_SALT_IN_ENCRYPTION_RESULTS_ENV_NAME, "invertPositionOfPlainSaltInEncryptionResultsEnvName"); processStringAttribute(element, builder, PARAM_USE_LENIENT_SALT_SIZE_CHECK_ENV_NAME, "useLenientSaltSizeCheckEnvName"); processStringAttribute(element, builder, PARAM_POOL_SIZE_ENV_NAME, "poolSizeEnvName"); processStringAttribute(element, builder, PARAM_ALGORITHM_SYS_PROPERTY_NAME, "algorithmSysPropertyName"); processStringAttribute(element, builder, PARAM_ITERATIONS_SYS_PROPERTY_NAME, "iterationsSysPropertyName"); processStringAttribute(element, builder, PARAM_SALT_SIZE_BYTES_SYS_PROPERTY_NAME, "saltSizeBytesSysPropertyName"); processStringAttribute(element, builder, PARAM_SALT_GENERATOR_CLASS_NAME_SYS_PROPERTY_NAME, "saltGeneratorClassNameSysPropertyName"); processStringAttribute(element, builder, PARAM_PROVIDER_CLASS_NAME_SYS_PROPERTY_NAME, "providerClassNameSysPropertyName"); processStringAttribute(element, builder, PARAM_PROVIDER_NAME_SYS_PROPERTY_NAME, "providerNameSysPropertyName"); processStringAttribute(element, builder, PARAM_INVERT_POSITION_OF_SALT_IN_MESSAGE_BEFORE_DIGESTING_SYS_PROPERTY_NAME, "invertPositionOfSaltInMessageBeforeDigestingSysPropertyName"); processStringAttribute(element, builder, PARAM_INVERT_POSITION_OF_PLAIN_SALT_IN_ENCRYPTION_RESULTS_SYS_PROPERTY_NAME, "invertPositionOfPlainSaltInEncryptionResultsSysPropertyName"); processStringAttribute(element, builder, PARAM_USE_LENIENT_SALT_SIZE_CHECK_SYS_PROPERTY_NAME, "useLenientSaltSizeCheckSysPropertyName"); processStringAttribute(element, builder, PARAM_POOL_SIZE_SYS_PROPERTY_NAME, "poolSizeSysPropertyName"); processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE_ENV_NAME, "stringOutputTypeEnvName"); processStringAttribute(element, builder, PARAM_STRING_OUTPUT_TYPE_SYS_PROPERTY_NAME, "stringOutputTypeSysPropertyName"); processStringAttribute(element, builder, PARAM_UNICODE_NORMALIZATION_IGNORED_ENV_NAME, "unicodeNormalizationIgnoredEnvName"); processStringAttribute(element, builder, PARAM_UNICODE_NORMALIZATION_IGNORED_SYS_PROPERTY_NAME, "unicodeNormalizationIgnoredSysPropertyName"); processStringAttribute(element, builder, PARAM_PREFIX_ENV_NAME, "prefixEnvName"); processStringAttribute(element, builder, PARAM_PREFIX_SYS_PROPERTY_NAME, "prefixSysPropertyName"); processStringAttribute(element, builder, PARAM_SUFFIX_ENV_NAME, "suffixEnvName"); processStringAttribute(element, builder, PARAM_SUFFIX_SYS_PROPERTY_NAME, "suffixSysPropertyName"); String scope = element.getAttribute(SCOPE_ATTRIBUTE); if (StringUtils.hasLength(scope)) { builder.setScope(scope);/*from w w w .ja v a 2 s . c o m*/ } }
From source file:org.brekka.stillingar.spring.config.ConfigurationServiceBeanDefinitionParser.java
protected void prepareReloadMechanism(Element element, ParserContext parserContext) { String id = element.getAttribute("id"); String reloadIntervalStr = element.getAttribute("reload-interval"); if (StringUtils.hasLength(reloadIntervalStr)) { int reloadInterval = 0; try {/* w w w . j av a 2 s . c om*/ reloadInterval = Integer.valueOf(reloadIntervalStr); } catch (NumberFormatException e) { throw new IllegalArgumentException("The attribute reload-interval is invalid", e); } if (reloadInterval >= MINIMUM_RELOAD_INTERVAL) { // Update task BeanDefinitionBuilder updateTask = BeanDefinitionBuilder .genericBeanDefinition(ConfigurationSnapshotRefresher.class); updateTask.addConstructorArgReference(id); // Scheduled executor BeanDefinitionBuilder scheduledExecutorTask = BeanDefinitionBuilder .genericBeanDefinition(ScheduledExecutorTask.class); scheduledExecutorTask.addConstructorArgValue(updateTask.getBeanDefinition()); if (watchableAvailable) { /* * The WatchedResourceMonitor is blocking with a timeout of reloadInterval. Must set a period, choose * an interval of 1s. */ scheduledExecutorTask.addPropertyValue("period", 1000); scheduledExecutorTask.addPropertyValue("delay", 1000); } else { scheduledExecutorTask.addPropertyValue("period", reloadInterval); scheduledExecutorTask.addPropertyValue("delay", reloadInterval); } ManagedList<Object> taskList = new ManagedList<Object>(); taskList.add(scheduledExecutorTask.getBeanDefinition()); // Scheduler factory bean BeanDefinitionBuilder scheduledExecutorFactoryBean = BeanDefinitionBuilder .genericBeanDefinition(ScheduledExecutorFactoryBean.class); scheduledExecutorFactoryBean.addPropertyValue("scheduledExecutorTasks", taskList); scheduledExecutorFactoryBean.addPropertyValue("threadNamePrefix", id + "-reloader"); scheduledExecutorFactoryBean.addPropertyValue("daemon", Boolean.TRUE); parserContext.registerBeanComponent(new BeanComponentDefinition( scheduledExecutorFactoryBean.getBeanDefinition(), id + "-Scheduler")); } } }
From source file:org.springsource.ide.eclipse.commons.internal.configurator.ConfiguratorImporter.java
public void lazyStartup() { List<String> commandLineArgs = Arrays.asList(Platform.getCommandLineArgs()); if (commandLineArgs.contains("-no-autoconfiguration")) { return;/*from w ww . ja va 2 s. c o m*/ } /* * p2 has a bug (ah, more then one actually): it can't make its mind if * it wants sts.ini or STS.ini so on case sensitive file systems we copy * it file again. */ if (Platform.getOS().equals(Platform.OS_MACOSX)) { File upperCaseFile = new File(".", "STS.ini"); File lowerCaseFile = new File(".", "sts.ini"); // Check if STS.ini exists. This will fail if we don't run in the // STS distribution; also check if sts.ini already exists. This // covers the case where STS.ini exists and we run on a // case-insensitive file system where sts.ini would also exist // already. Otherwise copy file over. if (upperCaseFile.exists() && !lowerCaseFile.exists()) { try { FileUtil.copyFile(upperCaseFile, lowerCaseFile, new NullProgressMonitor()); } catch (CoreException e) { StatusHandler.log( new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Could not copy STS.ini to sts.ini", e)); } } } // Check if we should run at all final boolean configured = Activator.getDefault().getPreferenceStore() .getBoolean(Activator.PROPERTY_CONFIGURATOR_PROCESSED); final boolean pendingRequests = StringUtils.hasLength( Activator.getDefault().getPreferenceStore().getString(Activator.PROPERTY_CONFIGURE_TARGETS)); if (configured && !pendingRequests) { return; } Job importJob = new Job("Workspace Configuration") { @Override public IStatus run(IProgressMonitor monitor) { // Rerun workspace participants if (pendingRequests) { Configurator action = new Configurator(); action.executePendingRequests(); } // Check if import already ran on the workspace if (configured) { return Status.OK_STATUS; } // Mark workspace as being processed before running to avoid // re-running on failure Activator.getDefault().getPreferenceStore().setValue(Activator.PROPERTY_CONFIGURATOR_PROCESSED, true); // Save servers view state for later reset boolean isShowOnActivity = ServerUIPlugin.getPreferences().getShowOnActivity(); // Prevent the servers view from showing up ServerUIPlugin.getPreferences().setShowOnActivity(false); // Import the sample projects List<File> samplesPath = scan(SAMPLES_PATH, null); if (samplesPath.size() > 0) { for (File sample : samplesPath.get(0).listFiles()) { createProject(monitor, sample); } } // Run external contributed configurators List<ConfigurableExtension> extensions = detectExtensions(monitor); for (ConfigurableExtension extension : extensions) { // Only configure extensions marked as auto configurable to // avoid adding old runtime/server versions if (extension.isAutoConfigurable()) { extension.configure(monitor); } } // Reset the servers view to original state ServerUIPlugin.getPreferences().setShowOnActivity(isShowOnActivity); lazyStartupJobLatch.countDown(); return Status.OK_STATUS; } }; importJob.setRule(ResourcesPlugin.getWorkspace().getRuleFactory().buildRule()); importJob.schedule(); }
From source file:edu.uchicago.duo.service.DuoPhoneObjImpl.java
@Override @Async/*from w w w . jav a 2 s .c o m*/ public Map<String, Object> verifyObj(String pNumber, String ext, String action) { String txid = null; String pin = null; String info = null; String state = null; jResult = null; Map<String, Object> verifyInfo = new HashMap<>(); apiURL = new String(); apiURL = duoVerifyApi + "/" + action; switch (action) { case "call": request = genHttpRequest("POST", apiURL, "verify"); request.addParam("phone", pNumber); if (StringUtils.hasLength(ext)) { request.addParam("extension", ext); request.addParam("postdelay", "6"); } request.addParam("message", message.getMessage("CALL.Device.Verify", null, Locale.getDefault())); break; case "status": request = genHttpRequest("GET", apiURL, "verify"); request.addParam("txid", pNumber); break; } request = signHttpRequest("verify"); try { jResult = (JSONObject) request.executeRequest(); switch (action) { case "call": txid = jResult.getString("txid"); pin = jResult.getString("pin"); verifyInfo.put("txid", txid); verifyInfo.put("pin", pin); logger.debug("2FA Debug - " + "DuoPhoneService.verifyObj:" + "txid=" + txid + ",Pin=" + pin); break; case "status": info = jResult.getString("info"); state = jResult.getString("state"); verifyInfo.put("info", info); verifyInfo.put("state", state); break; } } catch (Exception ex) { logger.error("2FA Error - " + "Unable to Call Phone!!!"); logger.error("2FA Error - " + "The Error is(PhoneObjImp): " + ex.toString()); } return verifyInfo; }
From source file:org.mifos.androidclient.main.AccountDetailsActivity.java
private void runAccountDetailsTask() { if (mAccount == null || !StringUtils.hasLength(mAccount.getGlobalAccountNum())) { mUIUtils.displayLongMessage(getString(R.string.toast_customer_id_not_available)); return;/* w ww .j av a 2 s . c om*/ } if (mAccountDetailsTask == null || mAccountDetailsTask.getStatus() != AsyncTask.Status.RUNNING) { mAccountDetailsTask = new AccountDetailsTask(this, getString(R.string.dialog_getting_account_data), getString(R.string.dialog_loading_message)); mAccountDetailsTask.execute(mAccount); } }
From source file:org.apache.servicemix.jbi.deployer.impl.AdminCommandsImpl.java
/** * Prints information about service assemblies deployed. * * @param state/*from ww w .j a va 2 s. co m*/ * @param componentName * @param serviceAssemblyName * @return */ public String listServiceAssemblies(String state, String componentName, String serviceAssemblyName) throws Exception { List<ServiceAssembly> assemblies = new ArrayList<ServiceAssembly>(); Component component = null; if (StringUtils.hasLength(componentName)) { component = deployer.getComponent(componentName); } for (ServiceAssembly sa : deployer.getServiceAssemblies().values()) { boolean match = true; if (StringUtils.hasLength(serviceAssemblyName)) { match = serviceAssemblyName.equals(sa.getName()); } if (match && StringUtils.hasLength(state)) { match = state.equalsIgnoreCase(sa.getCurrentState()); } if (match && StringUtils.hasLength(componentName)) { match = false; if (component != null) { for (ServiceUnit su : component.getServiceUnits()) { if (sa.getName().equals(su.getServiceAssembly().getName())) { match = true; break; } } } } if (match) { assemblies.add(sa); } } StringBuffer buffer = new StringBuffer(); buffer.append("<?xml version='1.0'?>\n"); buffer.append( "<service-assembly-info-list xmlns='http://java.sun.com/xml/ns/jbi/service-assembly-info-list' version='1.0'>\n"); for (ServiceAssembly sa : assemblies) { buffer.append(" <service-assembly-info"); buffer.append(" name='").append(sa.getName()).append("'"); buffer.append(" state='").append(sa.getCurrentState()).append("'>\n"); buffer.append(" <description>").append(sa.getDescription()).append("</description>\n"); for (ServiceUnit su : sa.getServiceUnits()) { buffer.append(" <service-unit-info"); buffer.append(" name='").append(su.getName()).append("'"); buffer.append(" state='").append(sa.getCurrentState()).append("'"); buffer.append(" deployed-on='").append(su.getComponent().getName()).append("'>\n"); buffer.append(" <description>").append(su.getDescription()).append("</description>\n"); buffer.append(" </service-unit-info>\n"); } buffer.append(" </service-assembly-info>\n"); } buffer.append("</service-assembly-info-list>"); return buffer.toString(); }