List of usage examples for org.apache.commons.lang StringUtils substringBetween
public static String substringBetween(String str, String open, String close)
Gets the String that is nested in between two Strings.
From source file:org.codice.ddf.security.idp.server.IdpEndpointTest.java
@Test public void testPassiveLoginPkiUnsupported() throws SecurityServiceException, WSSecurityException, CertificateEncodingException, IOException { String samlRequest = authNRequestPassivePkiGet; HttpServletRequest request = mock(HttpServletRequest.class); X509Certificate x509Certificate = mock(X509Certificate.class); Subject subject = mock(Subject.class); PrincipalCollection principalCollection = mock(PrincipalCollection.class); SecurityAssertion securityAssertion = mock(SecurityAssertion.class); SecurityToken securityToken = mock(SecurityToken.class); SecurityManager securityManager = mock(SecurityManager.class); when(subject.getPrincipals()).thenReturn(principalCollection); when(principalCollection.asList()).thenReturn(Collections.singletonList(securityAssertion)); when(securityAssertion.getSecurityToken()).thenReturn(securityToken); //this mock element is what will cause the signature error when(securityToken.getToken()).thenReturn(mock(Element.class)); when(securityManager.getSubject(anyObject())).thenReturn(subject); idpEndpoint.setSecurityManager(securityManager); idpEndpoint.setStrictSignature(false); when(request.isSecure()).thenReturn(true); when(request.getRequestURL()).thenReturn(requestURL); when(request.getAttribute(ContextPolicy.ACTIVE_REALM)).thenReturn("*"); //dummy cert//from w w w .j a v a 2s . c om when((X509Certificate[]) request.getAttribute(requestCertificateAttributeName)) .thenReturn(new X509Certificate[] { x509Certificate }); when(x509Certificate.getEncoded()).thenReturn(new byte[48]); Response response = idpEndpoint.showGetLogin(samlRequest, relayState, signatureAlgorithm, signature, request); String responseStr = StringUtils.substringBetween(response.getEntity().toString(), "SAMLResponse=", "&RelayState"); responseStr = URLDecoder.decode(responseStr, "UTF-8"); responseStr = RestSecurity.inflateBase64(responseStr); //the only cookie that should exist is the "1" cookie so "2" should send us to the login webapp assertThat(responseStr, containsString("status:RequestUnsupported")); }
From source file:org.debux.webmotion.netbeans.hints.PatternRule.java
@Override public void run(RuleContext context, List<Hint> hints) { WebMotionParserResult parserResult = (WebMotionParserResult) context.parserResult; Source source = parserResult.getSnapshot().getSource(); Document document = source.getDocument(false); FileObject fileObject = source.getFileObject(); List<OffsetRange> tokens = LexerUtils.getTokens(document, "ACTION_PATH_VARIABLE", "ACTION_PATH_PARAMETER_VALUE_VARIABLE"); for (OffsetRange range : tokens) { try {/*from w w w. j a v a 2 s . c o m*/ String value = LexerUtils.getText(document, range); String regexp = StringUtils.substringBetween(value, ":", "}"); if (regexp != null) { try { String pattern = regexp.replaceAll("\\\\\\{", "{"); pattern = pattern.replaceAll("\\\\\\}", "}"); Pattern.compile(pattern); } catch (PatternSyntaxException pse) { int end = range.getStart() + value.length() - 1; int start = end - regexp.length(); OffsetRange offsetRange = new OffsetRange(start, end); hints.add(new Hint(this, "Invalid pattern", fileObject, offsetRange, WebMotionHintsProvider.NO_FIXES, 100)); } } } catch (BadLocationException ex) { Exceptions.printStackTrace(ex); } } }
From source file:org.debux.webmotion.netbeans.hints.VariableRule.java
@Override public void run(RuleContext context, List<Hint> hints) { WebMotionParserResult parserResult = (WebMotionParserResult) context.parserResult; Source source = parserResult.getSnapshot().getSource(); Document document = source.getDocument(false); FileObject fileObject = source.getFileObject(); List<String> variables = new ArrayList<String>(); TokenHierarchy<Document> hi = TokenHierarchy.get(document); TokenSequence<WebMotionTokenId> ts = (TokenSequence<WebMotionTokenId>) hi.tokenSequence(); while (ts.moveNext()) { Token<WebMotionTokenId> token = ts.token(); WebMotionTokenId id = token.id(); String name = id.name();// w w w . j ava2s . c o m if ("ACTION_METHOD".equals(name)) { variables = new ArrayList<String>(); } if ("ACTION_PATH_PARAMETER_NAME".equals(name)) { String variable = token.text().toString(); variables.add(variable); } if ("ACTION_PATH_VARIABLE".equals(name) || "".equals(name) || "ACTION_PATH_PARAMETER_VALUE_VARIABLE".equals(name)) { String variable = token.text().toString(); if (variable.contains(":")) { variables.add(StringUtils.substringBetween(variable, "{", ":")); } else { variables.add(StringUtils.substringBetween(variable, "{", "}")); } } if ("ACTION_ACTION_JAVA_VARIABLE".equals(name) || "ACTION_ACTION_VIEW_VARIABLE".equals(name) || "ACTION_ACTION_LINK_VARIABLE".equals(name)) { String variable = token.text().toString(); variable = StringUtils.substringBetween(variable, "{", "}"); if (!variables.contains(variable)) { int start = ts.offset() + 1; int end = start + variable.length(); OffsetRange range = new OffsetRange(start, end); hints.add(new Hint(this, "Variable not defined", fileObject, range, WebMotionHintsProvider.NO_FIXES, 100)); } } } }
From source file:org.dspace.app.xmlui.aspect.discovery.AbstractSearch.java
/** * Add our metadata value, this value will might contain the highlight ("<em></em>") tags, these will be removed & rendered as highlight wing fields. * @param metadataFieldList the metadata list we need to add the value to * @param value the metadata value to be rendered * @throws WingException//from w ww. j a v a2s . c om */ protected void addMetadataField(org.dspace.app.xmlui.wing.element.List metadataFieldList, String value) throws WingException { //We need to put everything in <em> tags in a highlight ! org.dspace.app.xmlui.wing.element.Item metadataItem = metadataFieldList.addItem(); while (value.contains("<em>") && value.contains("</em>")) { if (0 < value.indexOf("<em>")) { //Add everything before the <em> ! metadataItem.addContent(value.substring(0, value.indexOf("<em>"))); } metadataItem.addHighlight("highlight").addContent(StringUtils.substringBetween(value, "<em>", "</em>")); value = StringUtils.substringAfter(value, "</em>"); } if (0 < value.length()) { metadataItem.addContent(value); } }
From source file:org.dspace.app.xmlui.cocoon.servlet.multipart.DSpaceMultipartParser.java
/** * Read part headers//from www . ja v a 2 s . c o m * * @param in * * @throws java.io.IOException */ private Hashtable readHeaders(DSpaceTokenStream in) throws IOException { Hashtable headers = new Hashtable(); String hdrline = readln(in); while (!"".equals(hdrline)) { String name = StringUtils.substringBefore(hdrline, ": ").toLowerCase(); String value; if (hdrline.contains(";")) { value = StringUtils.substringBetween(hdrline, ": ", "; "); } else { value = StringUtils.substringAfter(hdrline, ": "); } headers.put(name, value); hdrline = StringUtils.substringAfter(hdrline, ";"); // The extra tokenizer.hasMoreTokens() hdrline headers.put // handles the filename="" case IE6 submits for an empty // upload field. while (0 < hdrline.length()) { name = StringUtils.substringBetween(hdrline, " ", "="); if (hdrline.contains("; ")) { value = StringUtils.substringBetween(hdrline, "=\"", "\";"); hdrline = StringUtils.substringAfter(hdrline, ";"); } else { value = StringUtils.substringBetween(hdrline, "=\"", "\""); hdrline = ""; } headers.put(name, value); } hdrline = readln(in); } return headers; }
From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAClientConfigUtil.java
/** * Parses the client config.// w w w. j ava 2s . c o m * * @param iFile the i file * @return the sOA client config * @throws IOException Signals that an I/O exception has occurred. * @throws JDOMException the jDOM exception */ public static SOAClientConfig parseClientConfig(IFile iFile) throws IOException, JDOMException { SOAClientConfig soaClientConfig = new SOAClientConfig(); File soaConfFile = iFile.getLocation().toFile(); Document document = JDOMUtil.readXML(soaConfFile); Element clientConfigList = document.getRootElement(); Namespace nameSpace = clientConfigList.getNamespace(); if (clientConfigList != null) { Element clientConfig = clientConfigList.getChild(CLIENT_CONFIG, nameSpace); if (clientConfig != null) { final String fullServiceName = clientConfig.getAttributeValue(SERVICE_NAME); soaClientConfig.setFullyQualifiedServiceName(fullServiceName); final String serviceName = getServiceNameFromClientConfigServiceName(fullServiceName); soaClientConfig.setServiceName(serviceName); soaClientConfig.setTargetNamespace(StringUtils.substringBetween(fullServiceName, "{", "}")); Element serviceInterfaceClassName = clientConfig.getChild(SERVICE_INTERFACE_CLASS_NAME, nameSpace); if (serviceInterfaceClassName != null) { soaClientConfig.setServiceInterfaceClassName(serviceInterfaceClassName.getValue()); } Element serviceLocation = clientConfig.getChild(SERVICE_LOCATION, nameSpace); if (serviceLocation != null) { soaClientConfig.setServiceLocation(serviceLocation.getValue()); } Element clientInstanceConfig = clientConfig.getChild(CLIENT_INSTANCE_CONFIG, nameSpace); if (clientInstanceConfig != null) { Element invocationOptions = clientInstanceConfig.getChild(INVOCATION_OPTIONS, nameSpace); if (invocationOptions != null) { Element preferedTransport = invocationOptions.getChild(PREFERRED_TRANSPORT, nameSpace); if (preferedTransport != null) { soaClientConfig.setServiceBinding(preferedTransport.getAttributeValue(NAME)); } Element requestDataBinding = invocationOptions.getChild(REQUEST_DATA_BINDING, nameSpace); if (requestDataBinding != null) { soaClientConfig.setRequestDataBinding(requestDataBinding.getValue()); } Element responseDataBinding = invocationOptions.getChild(RESPONSE_DATA_BINDING, nameSpace); if (responseDataBinding != null) { soaClientConfig.setResponseDataBinding(responseDataBinding.getValue()); } Element invocationUseCase = invocationOptions.getChild(INVOCATION_USE_CASE, nameSpace); if (invocationUseCase != null) { soaClientConfig.setInvocationUseCase(invocationUseCase.getValue()); } Element messageProtocol = invocationOptions.getChild(MESSAGE_PROTOCOL, nameSpace); if (messageProtocol != null) { soaClientConfig.setMessageProtocol(messageProtocol.getValue()); } else { soaClientConfig.setMessageProtocol(MessageProtocol.NONE.name()); } Element consumerId = invocationOptions.getChild(CONSUMER_ID, nameSpace); if (consumerId != null) { soaClientConfig.setConsumerId(consumerId.getValue()); } } } } } soaClientConfig.setDocument(document); soaClientConfig.setFile(iFile); return soaClientConfig; }
From source file:org.ebayopensource.turmeric.eclipse.resources.util.SOAConsumerUtil.java
/** * This function returns the mapped value. Lets say the client config folder * name is "a" and if a has an entry in the the properties file map,then * that entry is returned otherwise a. the format of the String in the props * file is {[a,b],[d,e]}/* ww w . j a v a 2 s. c o m*/ * * @param project the project * @param clientNames the client names * @return the mapped service names from props file * @throws IOException Signals that an I/O exception has occurred. * @throws CoreException the core exception */ public static Map<String, String> getMappedServiceNamesFromPropsFile(IProject project, String... clientNames) throws IOException, CoreException { final Map<String, String> svcClientNameMap = new ConcurrentHashMap<String, String>(); // This is a hot fix for consumers. Impls wont have this props file // This is not a very nice approach. Impls also should have // consumer properties if its a consumer. IFile consumerPropsFile = getConsumerPropertiesFile(project); if (consumerPropsFile != null && consumerPropsFile.isAccessible()) { //this should be a consumer project final Properties properties = loadConsumerProperties(project); Object objMapStr = properties.get(SOAProjectConstants.PROPS_KEY_CONSUMER_SVC_CLIENT_NAME_MAPPING); if (objMapStr != null && objMapStr instanceof String && StringUtils.isNotEmpty((String) objMapStr)) { String strMap = (String) objMapStr; strMap = StringUtils.substringBetween(strMap, "{", "}"); for (String tempStr : StringUtils.substringsBetween(strMap, "[", "]")) { String[] tempArr = StringUtils.split(tempStr, SOAProjectConstants.DELIMITER_COMMA); svcClientNameMap.put(tempArr[0], tempArr[1]); } } } if (clientNames != null) { for (String clientName : clientNames) { String svcName = svcClientNameMap.get(clientName); if (StringUtils.isEmpty(svcName)) { svcClientNameMap.put(clientName, clientName); } } } return svcClientNameMap; }
From source file:org.ebayopensource.turmeric.eclipse.soatools.configtool.ConfigTool.java
/** * Parses the fully qualified service name. * * @param serviceName the service name/*from ww w. j a v a 2 s .com*/ * @return The first value is the namespace and the second is the service name */ public static String[] parseFullyQualifiedServiceName(final String serviceName) { if (StringUtils.isBlank(serviceName)) throw new IllegalArgumentException("Service name must not be empty->" + serviceName); String[] result = new String[2]; result[0] = StringUtils.substringBetween(serviceName, "{", "}"); result[1] = StringUtils.substringAfter(serviceName, "}"); return result; }
From source file:org.ebayopensource.turmeric.eclipse.template.wsdl.processors.ImportProcessor.java
/** * The format for this string is {a#b,c#d) * // ww w . ja va 2s . c o m * @param typeNamesStr * @return */ private List<QName> getTypeNames(String typeNamesStr) { List<QName> retQNames = new ArrayList<QName>(); if (!StringUtils.isEmpty(typeNamesStr)) { typeNamesStr = StringUtils.substringBetween(typeNamesStr, "{", "}"); for (String tempStr : StringUtils.split(typeNamesStr, ",")) { String[] tempArr = StringUtils.split(tempStr, "#"); QName qName = new QName(tempArr[0], tempArr[1]); retQNames.add(qName); } } return retQNames; }
From source file:org.ebayopensource.turmeric.eclipse.test.util.FunctionalTestHelper.java
@SuppressWarnings("unchecked") public static String getConsumerFQN(IProject prj) { // String className = null; String className = "Consumer"; NameFileFilter fileFilter = new NameFileFilter("Consumer.java"); Collection<File> files = FileUtils.listFiles(prj.getLocation().toFile(), fileFilter, TrueFileFilter.INSTANCE);/*from w ww . j a v a2 s. c o m*/ Assert.assertNotNull(files); Assert.assertTrue(files.size() > 0); File consFile = files.iterator().next(); InputStream input = null; try { input = new FileInputStream(consFile); LineIterator iter = IOUtils.lineIterator(input, null); while (iter.hasNext()) { String line = iter.nextLine(); if (line.startsWith("package")) { className = StringUtils.substringBetween(line, "package", ";").trim(); className = className + ".Consumer"; break; } } iter.close(); } catch (Exception e) { e.printStackTrace(); IOUtils.closeQuietly(input); } return className; }