List of usage examples for org.apache.commons.lang StringUtils upperCase
public static String upperCase(String str)
Converts a String to upper case as per String#toUpperCase() .
From source file:com.evolveum.icf.dummy.connector.DummyConnector.java
private DummyPrivilege convertToPriv(Set<Attribute> createAttributes) throws ConnectException, FileNotFoundException { String icfName = Utils.getMandatoryStringAttribute(createAttributes, Name.NAME); if (configuration.getUpCaseName()) { icfName = StringUtils.upperCase(icfName); }//from w w w. jav a 2 s. c o m final DummyPrivilege newPriv = new DummyPrivilege(icfName); Boolean enabled = null; for (Attribute attr : createAttributes) { if (attr.is(Uid.NAME)) { throw new IllegalArgumentException("UID explicitly specified in the group attributes"); } else if (attr.is(Name.NAME)) { // Skip, already processed } else if (attr.is(OperationalAttributeInfos.PASSWORD.getName())) { throw new IllegalArgumentException("Password specified for a privilege"); } else if (attr.is(OperationalAttributeInfos.ENABLE.getName())) { throw new IllegalArgumentException("Unsupported ENABLE attribute in privilege"); } else { String name = attr.getName(); try { newPriv.replaceAttributeValues(name, attr.getValue()); } catch (SchemaViolationException e) { throw new IllegalArgumentException(e.getMessage(), e); } } } return newPriv; }
From source file:eu.stork.peps.auth.engine.STORKSAMLEngine.java
/** * Gets the country from X.509 Certificate. * //from ww w . java 2s . c o m * @param keyInfo the key info * * @return the country */ private String getCountry(final KeyInfo keyInfo) { LOG.debug("Recover country information."); String result = ""; try { final org.opensaml.xml.signature.X509Certificate xmlCert = keyInfo.getX509Datas().get(0) .getX509Certificates().get(0); // Transform the KeyInfo to X509Certificate. CertificateFactory certFact; certFact = CertificateFactory.getInstance("X.509"); final ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(xmlCert.getValue())); final X509Certificate cert = (X509Certificate) certFact.generateCertificate(bis); String distName = cert.getSubjectDN().toString(); distName = StringUtils.deleteWhitespace(StringUtils.upperCase(distName)); final String countryCode = "C="; final int init = distName.indexOf(countryCode); if (init > StringUtils.INDEX_NOT_FOUND) { // Exist country code. int end = distName.indexOf(',', init); if (end <= StringUtils.INDEX_NOT_FOUND) { end = distName.length(); } if (init < end && end > StringUtils.INDEX_NOT_FOUND) { result = distName.substring(init + countryCode.length(), end); //It must be a two characters value if (result.length() > 2) { result = result.substring(0, 2); } } } } catch (CertificateException e) { LOG.error("Procces getCountry from certificate."); } return result.trim(); }
From source file:net.sourceforge.subsonic.service.SearchServiceTestCase.java
private void doTestLine(final String artist, final String album, final String title, final String year, final String path, final String genre, final long lastModified, final long length) { MusicFile file = new MusicFile() { public synchronized MetaData getMetaData() { MetaData metaData = new MetaData(); metaData.setArtist(artist);//from www . j a va 2 s . c om metaData.setAlbum(album); metaData.setTitle(title); metaData.setYear(year); metaData.setGenre(genre); return metaData; } public File getFile() { return new File(path); } public boolean isFile() { return true; } public boolean isDirectory() { return false; } public long lastModified() { return lastModified; } public long length() { return length; } }; SearchService.Line line = SearchService.Line.forFile(file, Collections.<File, SearchService.Line>emptyMap(), Collections.<File>emptySet()); String yearString = year == null ? "" : year; String expected = 'F' + SearchService.Line.SEPARATOR + lastModified + SearchService.Line.SEPARATOR + lastModified + SearchService.Line.SEPARATOR + path + SearchService.Line.SEPARATOR + length + SearchService.Line.SEPARATOR + StringUtils.upperCase(artist) + SearchService.Line.SEPARATOR + StringUtils.upperCase(album) + SearchService.Line.SEPARATOR + StringUtils.upperCase(title) + SearchService.Line.SEPARATOR + yearString + SearchService.Line.SEPARATOR + StringUtils.capitalize(genre); assertEquals("Error in toString().", expected, line.toString()); assertEquals("Error in forFile().", expected, SearchService.Line .forFile(file, Collections.<File, SearchService.Line>emptyMap(), Collections.<File>emptySet()) .toString()); assertEquals("Error in parse().", expected, SearchService.Line.parse(expected).toString()); }
From source file:net.ymate.framework.webmvc.intercept.AjaxAllowCrossDomainInterceptor.java
private void __addHeadersToView(String hosts, String methods, String headers, boolean notAllowCredentials) { HttpServletResponse _response = WebContext.getResponse(); _response.addHeader("Access-Control-Allow-Origin", StringUtils.defaultIfBlank(hosts, "*")); if (StringUtils.isNotBlank(methods)) { _response.addHeader("Access-Control-Allow-Methods", StringUtils.upperCase(methods)); }/*from ww w .j av a2 s . c o m*/ if (StringUtils.isNotBlank(headers)) { _response.addHeader("Access-Control-Allow-Headers", headers); } _response.addHeader("Access-Control-Allow-Credentials", notAllowCredentials ? "false" : "true"); }
From source file:net.ymate.module.oauth.impl.DefaultOAuthModuleCfg.java
public DefaultOAuthModuleCfg(YMP owner) { IConfigReader _moduleCfg = MapSafeConfigReader.bind(owner.getConfig().getModuleConfigs(IOAuth.MODULE_NAME)); //// w w w .ja v a2 s. c o m __accessTokenExpireIn = _moduleCfg.getInt(ACCESS_TOKEN_EXPIRE_IN); if (__accessTokenExpireIn <= 0) { __accessTokenExpireIn = 7200; } // __refreshCountMax = _moduleCfg.getInt(REFRESH_COUNT_MAX); if (__refreshCountMax < 0) { __refreshCountMax = 0; } // __refreshTokenExpireIn = _moduleCfg.getInt(REFRESH_TOKEN_EXPIRE_IN); if (__refreshTokenExpireIn <= 0) { __refreshTokenExpireIn = 30; } // __authorizationCodeExpireIn = _moduleCfg.getInt(AUTHORIZATION_CODE_EXPIRE_IN); if (__authorizationCodeExpireIn <= 0) { __authorizationCodeExpireIn = 5; } // __cacheNamePrefix = StringUtils.trimToEmpty(_moduleCfg.getString(CACHE_NAME_PREFIX)); // __allowGrantTypes = new HashSet<GrantType>(); String _grantTypeStr = _moduleCfg.getString(ALLOW_GRANT_TYPES, "none"); if (!StringUtils.containsIgnoreCase(_grantTypeStr, "none")) { String[] _types = StringUtils.split(_grantTypeStr, "|"); if (ArrayUtils.isNotEmpty(_types)) { for (String _item : _types) { try { GrantType _type = GrantType.valueOf(StringUtils.upperCase(StringUtils.trimToEmpty(_item))); __allowGrantTypes.add(_type); } catch (IllegalArgumentException ignored) { } } } } // if (!__allowGrantTypes.isEmpty()) { __tokenGenerator = _moduleCfg.getClassImpl(TOKEN_GENERATOR_CLASS, IOAuthTokenGenerator.class); if (__tokenGenerator == null) { __tokenGenerator = new DefaultTokenGenerator(); } // __storageAdapter = _moduleCfg.getClassImpl(STORAGE_ADAPTER_CLASS, IOAuthStorageAdapter.class); } // __errorAdapter = _moduleCfg.getClassImpl(ERROR_ADAPTER_CLASS, IOAuthErrorAdapter.class); if (__errorAdapter == null) { __errorAdapter = new DefaultErrorAdapter(); } }
From source file:net.ymate.module.oauth.web.controller.OAuthController.java
/** * ??????? (response_type=[code|token], scope=[snsapi_base|snsapi_userinfo]) * * @param authorized ??/* www .j a v a 2 s . c o m*/ * @return ??redirect_urlURL? * @throws Exception ? */ @RequestMapping(value = "/sns/authorize", method = { Type.HttpMethod.POST, Type.HttpMethod.GET }) @Before(UserSessionCheckInterceptor.class) @ContextParam(@ParamItem(Optional.OBSERVE_SILENCE)) public IView authorize(@RequestParam(defaultValue = "false") Boolean authorized) throws Exception { IView _view; OAuthResponse _response; try { HttpServletRequest _request = WebContext.getRequest(); ResponseType _responseType = ResponseType.valueOf(StringUtils.upperCase(StringUtils .trimToEmpty(_request.getParameter(org.apache.oltu.oauth2.common.OAuth.OAUTH_RESPONSE_TYPE)))); GrantType _grantType; if (ResponseType.CODE.equals(_responseType)) { _grantType = GrantType.AUTHORIZATION_CODE; } else { _grantType = GrantType.IMPLICIT; } if (OAuth.get().getModuleCfg().getAllowGrantTypes().contains(_grantType)) { IOAuthGrantProcessor _processor = new ImplicitGrantProcessor(OAuth.get(), _responseType) .setParam(IOAuth.Const.UID, UserSessionBean.current().getUid()) .setParam(IOAuth.Const.AUTHORIZED, authorized); // _response = _processor.process(WebContext.getRequest()); } else { _response = IOAuthGrantProcessor.UNSUPPORTED_GRANT_TYPE.process(WebContext.getRequest()); } if (StringUtils.isNotBlank(_response.getLocationUri())) { _view = View.httpStatusView(_response.getResponseStatus()).addHeader("Location", _response.getLocationUri()); } else { _view = new HttpStatusView(_response.getResponseStatus(), false).writeBody(_response.getBody()); } } catch (NeedAuthorizationException e) { INeedAuthorizationProcessor _processorClass = ClassUtils.impl( OAuth.get().getOwner().getConfig() .getParam(IOAuth.MODULE_NAME + ".need_authorization_processor_class"), INeedAuthorizationProcessor.class, this.getClass()); if (_processorClass == null) { _processorClass = new DefaultNeedAuthorizationProcessor(); } _view = _processorClass.process(e); } catch (IllegalArgumentException e) { _response = OAuth.get().getModuleCfg().getErrorAdapter().onError(IOAuth.ErrorType.INVALID_REQUEST); _view = new HttpStatusView(_response.getResponseStatus(), false).writeBody(_response.getBody()); } return _view; }
From source file:net.ymate.module.oauth.web.controller.OAuthController.java
/** * @return ? (grant_type=[authorization_code|password]) * @throws Exception ?/*w w w . j av a 2 s. c o m*/ */ @RequestMapping(value = "/sns/access_token", method = Type.HttpMethod.POST) public IView accessToken() throws Exception { OAuthResponse _response; try { HttpServletRequest _request = WebContext.getRequest(); GrantType _grantType = GrantType.valueOf(StringUtils.upperCase(StringUtils .trimToEmpty(_request.getParameter(org.apache.oltu.oauth2.common.OAuth.OAUTH_GRANT_TYPE)))); switch (_grantType) { case AUTHORIZATION_CODE: case PASSWORD: _response = OAuth.get().getGrantProcessor(_grantType).process(_request); break; default: _response = IOAuthGrantProcessor.UNSUPPORTED_GRANT_TYPE.process(WebContext.getRequest()); } } catch (OAuthProblemException e) { _response = OAuth.get().getModuleCfg().getErrorAdapter().onError(e); } catch (IllegalArgumentException e) { _response = OAuth.get().getModuleCfg().getErrorAdapter().onError(IOAuth.ErrorType.INVALID_REQUEST); } return new HttpStatusView(_response.getResponseStatus(), false).writeBody(_response.getBody()); }
From source file:nl.nn.adapterframework.util.Misc.java
public static String toSortName(String name) { // replace low line (x'5f') by asterisk (x'2a) so it's sorted before any digit and letter return StringUtils.upperCase(StringUtils.replace(name, "_", "*")); }
From source file:nl.nn.adapterframework.webcontrol.action.ShowTracingConfiguration.java
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { // Initialize action initAction(request);/*from w w w.j a v a 2 s .c o m*/ if (null == config) { return (mapping.findForward("noconfig")); } XmlBuilder tracingConfigurationXML = new XmlBuilder("tracingConfiguration"); XmlBuilder adapters = new XmlBuilder("registeredAdapters"); for (int j = 0; j < config.getRegisteredAdapters().size(); j++) { Adapter adapter = (Adapter) config.getRegisteredAdapter(j); XmlBuilder adapterXML = new XmlBuilder("adapter"); adapterXML.addAttribute("name", adapter.getName()); adapterXML.addAttribute("nameUC", StringUtils.upperCase(adapter.getName())); Iterator recIt = adapter.getReceiverIterator(); if (recIt.hasNext()) { XmlBuilder receiversXML = new XmlBuilder("receivers"); while (recIt.hasNext()) { ReceiverBase receiver = (ReceiverBase) recIt.next(); XmlBuilder receiverXML = new XmlBuilder("receiver"); receiversXML.addSubElement(receiverXML); receiverXML.addAttribute("name", receiver.getName()); receiverXML.addAttribute("beforeEvent", Integer.toString(receiver.getBeforeEvent())); receiverXML.addAttribute("afterEvent", Integer.toString(receiver.getAfterEvent())); receiverXML.addAttribute("exceptionEvent", Integer.toString(receiver.getExceptionEvent())); } adapterXML.addSubElement(receiversXML); } XmlBuilder pipelineXML = new XmlBuilder("pipeline"); List pipeList = adapter.getPipeLine().getPipes(); if (pipeList.size() > 0) { for (int i = 0; i < pipeList.size(); i++) { IPipe pipe = adapter.getPipeLine().getPipe(i); XmlBuilder pipeXML = new XmlBuilder("pipe"); pipeXML.addAttribute("name", pipe.getName()); if (pipe instanceof AbstractPipe) { AbstractPipe ap = (AbstractPipe) pipe; pipeXML.addAttribute("beforeEvent", Integer.toString(ap.getBeforeEvent())); pipeXML.addAttribute("afterEvent", Integer.toString(ap.getAfterEvent())); pipeXML.addAttribute("exceptionEvent", Integer.toString(ap.getExceptionEvent())); } pipelineXML.addSubElement(pipeXML); } adapterXML.addSubElement(pipelineXML); } adapters.addSubElement(adapterXML); } tracingConfigurationXML.addSubElement(adapters); request.setAttribute("tracingConfiguration", tracingConfigurationXML.toXML()); // Forward control to the specified success URI log.debug("forward to success"); return (mapping.findForward("success")); }
From source file:nl.nn.adapterframework.webcontrol.api.ShowConfigurationStatus.java
private Map<String, Object> mapAdapter(Adapter adapter) { Map<String, Object> adapterInfo = new HashMap<String, Object>(); Configuration config = adapter.getConfiguration(); String adapterName = adapter.getName(); adapterInfo.put("name", adapterName); adapterInfo.put("description", adapter.getDescription()); adapterInfo.put("configuration", config.getName()); // replace low line (x'5f') by asterisk (x'2a) so it's sorted before any digit and letter String nameUC = StringUtils.upperCase(StringUtils.replace(adapterName, "_", "*")); adapterInfo.put("nameUC", nameUC); RunStateEnum adapterRunState = adapter.getRunState(); boolean started = adapterRunState.equals(RunStateEnum.STARTED); adapterInfo.put("started", started); String state = adapterRunState.toString().toLowerCase().replace("*", ""); adapterInfo.put("state", state); boolean configured = adapter.configurationSucceeded(); adapterInfo.put("configured", configured); adapterInfo.put("upSince", adapter.getStatsUpSinceDate().getTime()); Date lastMessage = adapter.getLastMessageDateDate(); adapterInfo.put("lastMessage", (lastMessage == null) ? 0 : lastMessage.getTime()); int messagesInProcess = adapter.getNumOfMessagesInProcess(); adapterInfo.put("messagesInProcess", messagesInProcess); long messagesProcessed = adapter.getNumOfMessagesProcessed(); adapterInfo.put("messagesProcessed", messagesProcessed); long messagesInError = adapter.getNumOfMessagesInError(); adapterInfo.put("messagesInError", messagesInError); return adapterInfo; }