List of usage examples for org.springframework.util StringUtils hasLength
public static boolean hasLength(@Nullable String str)
From source file:com.wavemaker.tools.security.CloudFoundrySecurityFilter.java
private void checkAuthenticationCookie(HttpServletRequest request) throws TransportTokenDigestMismatchException { Cookie[] allCookies = request.getCookies(); Assert.state(allCookies.length < 12, "Way too many auth cookies."); Cookie[] authCookies = new Cookie[allCookies.length]; int num = 0;//w w w .j a v a 2 s . co m for (Cookie cookie : allCookies) { if (cookie.getName().equals("wavemaker_authentication_token")) { authCookies[num++] = cookie; } } for (Cookie cookie : authCookies) { try { Assert.state(cookie != null, "This is no cookie"); Assert.state(StringUtils.hasLength(cookie.getValue()), "This cookie has no value"); log.debug("Trying = " + cookie.getValue()); SharedSecret sharedSecret = this.propagation.getForSelf(true); sharedSecret.decrypt(TransportToken.decode(cookie.getValue())); return; } catch (TransportTokenDigestMismatchException ttdme) { log.debug("Invalid cookie"); } } log.warn("NO valid cookie - redirecting " + request.getRequestURI() + " to spinup app"); throw (new TransportTokenDigestMismatchException("Unable to find valid secret token")); }
From source file:de.thm.arsnova.security.CustomBindAuthenticator.java
public DirContextOperations authenticate(Authentication authentication) { DirContextOperations user = null;/* w w w .j a va2 s . c om*/ Assert.isInstanceOf(UsernamePasswordAuthenticationToken.class, authentication, "Can only process UsernamePasswordAuthenticationToken objects"); String username = authentication.getName(); String password = (String) authentication.getCredentials(); if (!StringUtils.hasLength(password)) { logger.debug("Rejecting empty password for user " + username); throw new BadCredentialsException( messages.getMessage("BindAuthenticator.emptyPassword", "Empty Password")); } // If DN patterns are configured, try authenticating with them directly for (String dn : getUserDns(username)) { user = bindWithDn(dn, username, password); if (user != null) { break; } } // Otherwise use the configured search object to find the user and authenticate // with the returned DN. if (user == null && getUserSearch() != null) { DirContextOperations userFromSearch = getUserSearch().searchForUser(username); user = bindWithDn(userFromSearch.getDn().toString(), username, password); } if (user == null) { throw new BadCredentialsException( messages.getMessage("BindAuthenticator.badCredentials", "Bad credentials")); } return user; }
From source file:easycare.web.password.ChangePasswordController.java
@RequestMapping(value = LICENSE_AGREEMENT_URL, method = RequestMethod.POST) public ModelAndView licenseAgreementPost(HttpServletRequest request) { ModelAndView mav = null;//from w ww . j a v a 2 s. c o m String accept = request.getParameter("accept"); if (StringUtils.hasLength(accept) && accept.equals(Boolean.TRUE.toString())) { User user = this.sessionSecurityService.getCurrentUser(); // Update current User with license agreement user = this.userService.acceptLicenseAgreement(user); // Refresh User authorities this.sessionSecurityService.refreshUserContext(request, user, null); mav = new ModelAndView(new RedirectView("/", true)); } else { mav = this.licenseAgreementGet(); } return mav; }
From source file:gda.data.scan.datawriter.NexusDataWriter.java
protected void setupProperties() throws InstantiationException { if (setupPropertiesDone) return;//from w w w. j a v a 2 s .co m metadata = GDAMetadataProvider.getInstance(); try { beamline = metadata.getMetadataValue("instrument", "gda.instrument", null); } catch (DeviceException e1) { } // If the beamline name isn't set then default to 'base'. if (beamline == null) { // If the beamline name is not set then use 'base' beamline = "base"; } // Check to see if we want to use a different NeXus backend format. defaultNeXusBackend = LocalProperties.get(GDA_DATA_NEXUS_BACKEND); if (defaultNeXusBackend == null) { defaultNeXusBackend = NexusGlobals.GDA_NX_DEFAULT; } // Check to see if the data directory has been defined. dataDir = PathConstructor.createFromDefaultProperty(); if (dataDir == null) { // this java property is compulsory - stop the scan throw new InstantiationException("cannot work out data directory - cannot create a new data file."); } if (beforeScanMetaData == null) { String metaDataProviderName = LocalProperties.get(GDA_NEXUS_METADATAPROVIDER_NAME); if (StringUtils.hasLength(metaDataProviderName)) { NexusTreeAppender metaDataProvider = Finder.getInstance().find(metaDataProviderName); InterfaceProvider.getTerminalPrinter().print("Getting meta data before scan"); beforeScanMetaData = new NexusTreeNode("before_scan", NexusExtractor.NXCollectionClassName, null); metaDataProvider.appendToTopNode(beforeScanMetaData); } } setupPropertiesDone = true; }
From source file:io.micrometer.spring.export.prometheus.PrometheusPushGatewayManager.java
private void push() { try {/*from www . jav a2s.c om*/ this.pushGateway.pushAdd(this.registry, this.job, this.groupingKey); } catch (UnknownHostException ex) { String host = ex.getMessage(); String message = "Unable to locate prometheus push gateway host" + (StringUtils.hasLength(host) ? " '" + host + "'" : "") + ". No longer attempting metrics publication to this host"; logger.error(message, ex); shutdown(ShutdownOperation.NONE); } catch (Throwable ex) { logger.error("Unable to push metrics to Prometheus Pushgateway", ex); } }
From source file:net.neurowork.cenatic.centraldir.workers.SatelitesExecutorJob.java
protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException { logger.info("Se ejecuta la busqueda en los satlites"); if (sateliteService == null) { logger.error("Servicio invlido."); return;//ww w . j a v a2 s . c o m } try { Collection<Satelite> satelites = sateliteService.findActivado(); for (Satelite satelite : satelites) { if (BooleanUtils.isTrue(satelite.isActivado())) { if (StringUtils.hasLength(satelite.getHostUrl()) && StringUtils.hasLength(satelite.getUser()) && StringUtils.hasLength(satelite.getPassword())) { Thread t = new Thread(new XMLRestWorker(satelite, sateliteService, provinciaService, organizacionService, organizacionSedeService, formaJuridicaService, sectorService, asociacionService)); t.start(); } // else{ // logger.warn("No se inicia la busqueda para el satelite: " + satelite + " por falta de informacin."); // } } } } catch (ServiceException e) { logger.error(e.getMessage()); } }
From source file:net.neurowork.cenatic.centraldir.workers.xml.AbstractXmlImporter.java
public T findBaseEntity(String idValue, String name) { if (!StringUtils.hasLength(idValue)) return null; Integer id = getId(idValue);/* ww w.j a va 2s . c o m*/ T ret = null; List<T> l = null; try { l = findByName(name); } catch (ServiceException e) { logger.error(e.getMessage()); } if (l != null && l.size() > 0) { ret = l.get(0); } else { ret = findRestEntity(id); } return ret; }
From source file:net.neurowork.cenatic.centraldir.workers.xml.CapacidadXmlImporter.java
private Capacidad importCapacidad(String xmlString, Integer capacityId) throws ParserConfigurationException, SAXException, IOException { Document doc = XmlParserUtil.createDocumentFromString(xmlString); Capacidad ret = null;/*from ww w. j a v a 2 s .co m*/ NodeList nodeLst = doc.getElementsByTagName("capacity"); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element elPDU = (Element) fstNode; String code = XmlParserUtil.getAttribute(elPDU, XML_CODE); String category = XmlParserUtil.getAttribute(elPDU, "category"); NodeList fstNm = elPDU.getChildNodes(); String capacidadName = null; if (fstNm.getLength() > 0) { capacidadName = ((Node) fstNm.item(0)).getNodeValue(); Integer capId = AbstractXmlImporter.getId(code); Capacidad capacidad = null; try { List<Capacidad> capacidades = organizacionService.findCapacidadByName(capacidadName); if (capacidades != null && capacidades.size() > 0) { capacidad = capacidades.get(0); } else { capacidad = new Capacidad(); capacidad.setName(capacidadName); if (StringUtils.hasLength(category)) capacidad.setCategoria(category); organizacionService.saveCapacidad(capacidad); } if (capId != null && capId.equals(capacityId)) { ret = capacidad; } } catch (ServiceException e) { logger.error(e.getMessage()); } } } } if (ret != null) { if (logger.isTraceEnabled()) logger.trace("Se devuelve la Capacidad: " + ret); return ret; } if (logger.isTraceEnabled()) logger.trace("No se ha encontrado la Capacidad con Id: " + capacityId); return null; }
From source file:net.neurowork.cenatic.centraldir.workers.xml.OrganizacionXmlImporter.java
private Organizacion parseOrganizacion(String xmlString) throws ParserConfigurationException, SAXException, IOException, ServiceException { Document doc = XmlParserUtil.createDocumentFromString(xmlString); Organizacion ret = null;//from www .j a v a2s .com NodeList nodeLst = doc.getElementsByTagName(ORGANIZATION_TAG); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element elOrg = (Element) fstNode; String legalId = XmlParserUtil.getStringNodeValue(elOrg, XML_LEGAL_ID); if (!legalId.isEmpty()) { ret = organizacionService.findByCIF(legalId); if (ret == null) { if (logger.isTraceEnabled()) ; logger.trace("Organizacion con CIF: " + legalId + " no encontrada, AGREGANDO"); ret = new Organizacion(); } else { if (logger.isTraceEnabled()) ; logger.trace("Organizacion con CIF: " + legalId + " encontrada, ACTUALIZANDO"); } String name = XmlParserUtil.getStringNodeValue(elOrg, "name"); String description = XmlParserUtil.getStringNodeValue(elOrg, "description"); String web = XmlParserUtil.getStringNodeValue(elOrg, "web"); String logoUrl = XmlParserUtil.getStringNodeValue(elOrg, "logo_url"); String direccion = XmlParserUtil.getStringNodeValue(elOrg, "HQstreet"); String localidad = XmlParserUtil.getStringNodeValue(elOrg, "HQlocality"); String newsTitle = XmlParserUtil.getStringNodeValue(elOrg, "newsTitle"); String newsBody = XmlParserUtil.getStringNodeValue(elOrg, "newsBody"); Element provEl = XmlParserUtil.getChildren(elOrg, "HQprovince"); String provId = XmlParserUtil.getAttribute(provEl, "code"); String provincia = XmlParserUtil.getStringNodeValue(elOrg, "HQprovince"); String codPostal = XmlParserUtil.getStringNodeValue(elOrg, "HQpostalCode"); String year = XmlParserUtil.getStringNodeValue(elOrg, "year"); String partners = XmlParserUtil.getStringNodeValue(elOrg, "partners"); String corpGroup = XmlParserUtil.getStringNodeValue(elOrg, "enpresarialGroup"); String phoneNumber = XmlParserUtil.getStringNodeValue(elOrg, "telephone"); String email = XmlParserUtil.getStringNodeValue(elOrg, "email"); String research = XmlParserUtil.getStringNodeValue(elOrg, "researchAndDevelopmentProgrammes"); String relacionesComunidad = XmlParserUtil.getStringNodeValue(elOrg, "communityRelationships"); String qualityCertifications = XmlParserUtil.getStringNodeValue(elOrg, "qualityCertifications"); Element orgClassEl = XmlParserUtil.getChildren(elOrg, "organizationClasification"); String orgClassCode = XmlParserUtil.getAttribute(orgClassEl, "code"); String organizationClasification = XmlParserUtil.getStringNodeValue(elOrg, "organizationClasification"); Element orgTypeEl = XmlParserUtil.getChildren(elOrg, "organizationType"); String orgTypeCode = XmlParserUtil.getAttribute(orgTypeEl, "code"); String organizationType = XmlParserUtil.getStringNodeValue(elOrg, "organizationType"); Element degationsEl = XmlParserUtil.getChildren(elOrg, "delegations"); Element capacitiesEl = XmlParserUtil.getChildren(elOrg, "capacities"); Element demandsEl = XmlParserUtil.getChildren(elOrg, "demands"); Element eventsEl = XmlParserUtil.getChildren(elOrg, "events"); // Association Memberships Element associationsEl = XmlParserUtil.getChildren(elOrg, "associationMemberships"); //username String username = XmlParserUtil.getStringNodeValue(elOrg, "username"); //password String password = XmlParserUtil.getStringNodeValue(elOrg, "password"); ret.setCif(legalId); ret.setName(name); ret.setDescripcion(description); ret.setNewsTitle(newsTitle); ret.setNewsBody(newsBody); ret.setWeb(web); ret.setLogoUrl(logoUrl); ret.setDireccion(direccion); ret.setLocalidad(localidad); Provincia prov = provinciaImporter.findProvincia(provId, provincia); if (prov != null) ret.setProvincia(prov); ret.setCodigoPostal(Integer.parseInt(codPostal)); try { if (year != null && !year.isEmpty()) ret.setAnoConstitucion(Integer.parseInt(year)); } catch (NumberFormatException e) { } ret.setPartners(partners); ret.setGrupoEmpresarial(corpGroup); ret.setTelefono(phoneNumber); ret.setEmail(email); ret.setActividadesImasD(!research.isEmpty()); ret.setParticipacionImasD(research); ret.setRelacionesComunidad(relacionesComunidad); ret.setCertificacionesCalidad(Organizacion.decoded(qualityCertifications)); if (orgClassEl != null && StringUtils.hasLength(orgClassCode)) { ClasificacionOrganizacion co = clasificacionOrganizacionImporter .findBaseEntity(orgClassCode, organizationClasification); if (co != null) ret.setClasificacionOrganizacion(co); } if (orgTypeEl != null && StringUtils.hasLength(orgTypeCode)) { FormaJuridica fj = formaJuridicaImporter.findBaseEntity(orgTypeCode, organizationType); if (fj != null) ret.setFormaJuridica(fj); } if (degationsEl != null) { Set<OrganizacionSede> sedes = sedeImporter.buscarSedes(degationsEl, ret); if (ret.getSedes() == null) { ret.setSedes(sedes); } else { ret.getSedes().addAll(sedes); } } if (capacitiesEl != null) { Set<OrganizacionCapacidadOferta> ofertas = ofertasImporter.buscarOfertas(capacitiesEl, ret); if (ret.getOfertas() == null) { ret.setOfertas(ofertas); } else { ret.getOfertas().addAll(ofertas); } } if (demandsEl != null) { Set<OrganizacionCapacidadDemanda> demandas = demandasImporter.buscarDemandas(demandsEl, ret); if (ret.getDemandas() == null) { ret.setDemandas(demandas); } else { ret.getDemandas().addAll(demandas); } } if (associationsEl != null) { Set<OrganizacionAsociacion> organizacionAsociacions = asociacionImporter .buscarAsociaciones(associationsEl, ret); if (ret.getOrganizacionAsociacions() == null) { ret.setOrganizacionAsociacions(organizacionAsociacions); } else { ret.getOrganizacionAsociacions().addAll(organizacionAsociacions); } } if (eventsEl != null) { Set<OrganizacionEvento> eventos = eventosImporter.buscarEventos(eventsEl, ret); if (ret.getEventos() == null) { ret.setEventos(eventos); } else { ret.getEventos().addAll(eventos); } } ret.setUsername(username); ret.setPassword(password); } } } return ret; }
From source file:net.neurowork.cenatic.centraldir.workers.XMLRestWorker.java
private Organizacion parseOrganizacion(String xmlString) throws ParserConfigurationException, SAXException, IOException, ServiceException { Document doc = XmlParserUtil.createDocumentFromString(xmlString); Organizacion ret = null;// w ww . j a v a 2 s . co m NodeList nodeLst = doc.getElementsByTagName(ORGANIZATION_TAG); for (int s = 0; s < nodeLst.getLength(); s++) { Node fstNode = nodeLst.item(s); if (fstNode.getNodeType() == Node.ELEMENT_NODE) { Element elOrg = (Element) fstNode; String legalId = XmlParserUtil.getStringNodeValue(elOrg, "legalID"); if (!legalId.isEmpty()) { ret = organizacionService.findByCIF(legalId); if (ret == null) { if (logger.isTraceEnabled()) ; logger.trace("Organizacion con CIF: " + legalId + " no encontrada, AGREGANDO"); ret = new Organizacion(); } else { if (logger.isTraceEnabled()) ; logger.trace("Organizacion con CIF: " + legalId + " encontrada, ACTUALIZANDO"); } String name = XmlParserUtil.getStringNodeValue(elOrg, "name"); String description = XmlParserUtil.getStringNodeValue(elOrg, "description"); String web = XmlParserUtil.getStringNodeValue(elOrg, "web"); String logoUrl = XmlParserUtil.getStringNodeValue(elOrg, "logo_url"); String direccion = XmlParserUtil.getStringNodeValue(elOrg, "HQstreet"); String localidad = XmlParserUtil.getStringNodeValue(elOrg, "HQlocality"); String newsTitle = XmlParserUtil.getStringNodeValue(elOrg, "newsTitle"); String newsBody = XmlParserUtil.getStringNodeValue(elOrg, "newsBody"); Element provEl = XmlParserUtil.getChildren(elOrg, "HQprovince"); String provId = XmlParserUtil.getAttribute(provEl, "code"); String provincia = XmlParserUtil.getStringNodeValue(elOrg, "HQprovince"); String codPostal = XmlParserUtil.getStringNodeValue(elOrg, "HQpostalCode"); String year = XmlParserUtil.getStringNodeValue(elOrg, "year"); String partners = XmlParserUtil.getStringNodeValue(elOrg, "partners"); String corpGroup = XmlParserUtil.getStringNodeValue(elOrg, "enpresarialGroup"); String phoneNumber = XmlParserUtil.getStringNodeValue(elOrg, "telephone"); String email = XmlParserUtil.getStringNodeValue(elOrg, "email"); String research = XmlParserUtil.getStringNodeValue(elOrg, "researchAndDevelopmentProgrammes"); String relacionesComunidad = XmlParserUtil.getStringNodeValue(elOrg, "communityRelationships"); String qualityCertifications = XmlParserUtil.getStringNodeValue(elOrg, "qualityCertifications"); Element orgClassEl = XmlParserUtil.getChildren(elOrg, "organizationClasification"); String orgClassCode = XmlParserUtil.getAttribute(orgClassEl, "code"); String organizationClasification = XmlParserUtil.getStringNodeValue(elOrg, "organizationClasification"); Element orgTypeEl = XmlParserUtil.getChildren(elOrg, "organizationType"); String orgTypeCode = XmlParserUtil.getAttribute(orgTypeEl, "code"); String organizationType = XmlParserUtil.getStringNodeValue(elOrg, "organizationType"); Element degationsEl = XmlParserUtil.getChildren(elOrg, "delegations"); Element capacitiesEl = XmlParserUtil.getChildren(elOrg, "capacities"); Element demandsEl = XmlParserUtil.getChildren(elOrg, "demands"); Element eventsEl = XmlParserUtil.getChildren(elOrg, "events"); // Association Memberships Element associationsEl = XmlParserUtil.getChildren(elOrg, "associationMemberships"); //username String username = XmlParserUtil.getStringNodeValue(elOrg, "username"); //password String password = XmlParserUtil.getStringNodeValue(elOrg, "password"); ret.setCif(legalId); ret.setName(name); ret.setDescripcion(description); ret.setNewsTitle(newsTitle); ret.setNewsBody(newsBody); ret.setWeb(web); ret.setLogoUrl(logoUrl); ret.setDireccion(direccion); ret.setLocalidad(localidad); ret.setProvincia(findProvincia(provId, provincia)); ret.setCodigoPostal(Integer.parseInt(codPostal)); try { if (year != null && !year.isEmpty()) ret.setAnoConstitucion(Integer.parseInt(year)); } catch (NumberFormatException e) { } ret.setPartners(partners); ret.setGrupoEmpresarial(corpGroup); ret.setTelefono(phoneNumber); ret.setEmail(email); ret.setActividadesImasD(!research.isEmpty()); ret.setParticipacionImasD(research); ret.setRelacionesComunidad(relacionesComunidad); ret.setCertificacionesCalidad(Organizacion.decoded(qualityCertifications)); if (orgClassEl != null && StringUtils.hasLength(orgClassCode)) { ret.setClasificacionOrganizacion( findClasificacionOrganizacion(orgClassCode, organizationClasification)); } if (orgTypeEl != null && StringUtils.hasLength(orgTypeCode)) { ret.setFormaJuridica(findFormaJuridica(orgTypeCode, organizationType)); } if (degationsEl != null) { Set<OrganizacionSede> sedes = buscarSedes(degationsEl, ret); if (ret.getSedes() == null) { ret.setSedes(sedes); } else { ret.getSedes().addAll(sedes); } } if (capacitiesEl != null) { Set<OrganizacionCapacidadOferta> ofertas = buscarOfertas(capacitiesEl, ret); if (ret.getOfertas() == null) { ret.setOfertas(ofertas); } else { ret.getOfertas().addAll(ofertas); } } if (demandsEl != null) { Set<OrganizacionCapacidadDemanda> demandas = buscarDemandas(demandsEl, ret); if (ret.getDemandas() == null) { ret.setDemandas(demandas); } else { ret.getDemandas().addAll(demandas); } } if (associationsEl != null) { Set<OrganizacionAsociacion> organizacionAsociacions = buscarAsociaciones(associationsEl, ret); if (ret.getOrganizacionAsociacions() == null) { ret.setOrganizacionAsociacions(organizacionAsociacions); } else { ret.getOrganizacionAsociacions().addAll(organizacionAsociacions); } } if (eventsEl != null) { Set<OrganizacionEvento> eventos = buscarEventos(eventsEl, ret); if (ret.getEventos() == null) { ret.setEventos(eventos); } else { ret.getEventos().addAll(eventos); } } ret.setUsername(username); ret.setPassword(password); } } } return ret; }