/** * Checks for certain params existence in the value, and replace them with real values obtained * from <tt>request</tt>. * * @param value the value of the header param * @param request the request we are processing * @return the value with replaced params */ private static String processParams(String value, Request request) { if (value.indexOf("${from.address}") != -1) { FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME); if (fromHeader != null) { value = value.replace("${from.address}", fromHeader.getAddress().getURI().toString()); } } if (value.indexOf("${from.userID}") != -1) { FromHeader fromHeader = (FromHeader) request.getHeader(FromHeader.NAME); if (fromHeader != null) { URI fromURI = fromHeader.getAddress().getURI(); String fromAddr = fromURI.toString(); // strips sip: or sips: if (fromURI.isSipURI()) { fromAddr = fromAddr.replaceFirst(fromURI.getScheme() + ":", ""); } // take the userID part int index = fromAddr.indexOf('@'); if (index > -1) fromAddr = fromAddr.substring(0, index); value = value.replace("${from.userID}", fromAddr); } } if (value.indexOf("${to.address}") != -1) { ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME); if (toHeader != null) { value = value.replace("${to.address}", toHeader.getAddress().getURI().toString()); } } if (value.indexOf("${to.userID}") != -1) { ToHeader toHeader = (ToHeader) request.getHeader(ToHeader.NAME); if (toHeader != null) { URI toURI = toHeader.getAddress().getURI(); String toAddr = toURI.toString(); // strips sip: or sips: if (toURI.isSipURI()) { toAddr = toAddr.replaceFirst(toURI.getScheme() + ":", ""); } // take the userID part int index = toAddr.indexOf('@'); if (index > -1) toAddr = toAddr.substring(0, index); value = value.replace("${to.userID}", toAddr); } } return value; }
/** * Resolves an external entity. If the entity cannot be resolved, this method should return <code> * null</code>. This method returns an input source if an entry was found in the catalog for the * given external identifier. It should be overrided if other behaviour is required. * * @param name the identifier of the external entity * @param publicId the public identifier, or <code>null</code> if none was supplied * @param baseURI the URI with respect to which relative systemIDs are interpreted. * @param systemId the system identifier * @throws SAXException any SAX exception, possibly wrapping another exception * @throws IOException thrown if some i/o error occurs */ public InputSource resolveEntity(String name, String publicId, String baseURI, String systemId) throws SAXException, IOException { String resolvedId = null; if (!getUseLiteralSystemId() && baseURI != null) { // Attempt to resolve the system identifier against the base URI. try { URI uri = new URI(new URI(baseURI), systemId); systemId = uri.toString(); } // Ignore the exception. Fallback to the literal system identifier. catch (URI.MalformedURIException ex) { } } if (publicId != null && systemId != null) { resolvedId = resolvePublic(publicId, systemId); } else if (systemId != null) { resolvedId = resolveSystem(systemId); } if (resolvedId != null) { InputSource source = new InputSource(resolvedId); source.setPublicId(publicId); return source; } return null; }
/** * Take a SystemID string and try to turn it into a good absolute URI. * * @param urlString SystemID string * @param base The URI string used as the base for resolving the systemID * @return The resolved absolute URI * @throws TransformerException thrown if the string can't be turned into a URI. */ public static String getAbsoluteURI(String urlString, String base) throws TransformerException { if (base == null) return getAbsoluteURI(urlString); String absoluteBase = getAbsoluteURI(base); URI uri = null; try { URI baseURI = new URI(absoluteBase); uri = new URI(baseURI, urlString); } catch (MalformedURIException mue) { throw new TransformerException(mue); } return replaceChars(uri.toString()); }
/** * Resolves a resource using the catalog. This method interprets that the namespace URI * corresponds to uri entries in the catalog. Where both a namespace and an external identifier * exist, the namespace takes precedence. * * @param type the type of the resource being resolved * @param namespaceURI the namespace of the resource being resolved, or <code>null</code> if none * was supplied * @param publicId the public identifier of the resource being resolved, or <code>null</code> if * none was supplied * @param systemId the system identifier of the resource being resolved, or <code>null</code> if * none was supplied * @param baseURI the absolute base URI of the resource being parsed, or <code>null</code> if * there is no base URI */ public LSInput resolveResource( String type, String namespaceURI, String publicId, String systemId, String baseURI) { String resolvedId = null; try { // The namespace is useful for resolving namespace aware // grammars such as XML schema. Let it take precedence over // the external identifier if one exists. if (namespaceURI != null) { resolvedId = resolveURI(namespaceURI); } if (!getUseLiteralSystemId() && baseURI != null) { // Attempt to resolve the system identifier against the base URI. try { URI uri = new URI(new URI(baseURI), systemId); systemId = uri.toString(); } // Ignore the exception. Fallback to the literal system identifier. catch (URI.MalformedURIException ex) { } } // Resolve against an external identifier if one exists. This // is useful for resolving DTD external subsets and other // external entities. For XML schemas if there was no namespace // mapping we might be able to resolve a system identifier // specified as a location hint. if (resolvedId == null) { if (publicId != null && systemId != null) { resolvedId = resolvePublic(publicId, systemId); } else if (systemId != null) { resolvedId = resolveSystem(systemId); } } } // Ignore IOException. It cannot be thrown from this method. catch (IOException ex) { } if (resolvedId != null) { return new DOMInputImpl(publicId, resolvedId, baseURI); } return null; }
public String buildQuery() { if (cachedQuery != null) { return cachedQuery; } URI query = buildViewPath(); if (isNotEmpty(key)) { query.param("key", key); } if (isNotEmpty(startKey)) { query.param("startkey", startKey); } if (isNotEmpty(endKey)) { query.param("endkey", endKey); } if (isNotEmpty(startDocId)) { query.param("startkey_docid", startDocId); } if (isNotEmpty(endDocId)) { query.param("endkey_docid", endDocId); } if (hasValue(limit)) { query.param("limit", limit); } if (staleOk != null) { query.param("stale", staleOk); } if (descending) { query.param("descending", "true"); } if (!inclusiveEnd) { query.param("inclusive_end", "false"); } if (!reduce) { query.param("reduce", "false"); } if (hasValue(skip)) { query.param("skip", skip); } if (includeDocs) { query.param("include_docs", "true"); } if (group) { query.param("group", "true"); } if (hasValue(groupLevel)) { query.param("group_level", groupLevel); } if (queryParams != null && !queryParams.isEmpty()) { appendQueryParams(query); } cachedQuery = query.toString(); return cachedQuery; }
/** * Check the response and answer true if authentication succeeds. We are making simplifying * assumptions here and assuming that the password is available to us for computation of the MD5 * hash. We also dont cache authentications so that the user has to authenticate on each * registration. * * @param user is the username * @param authHeader is the Authroization header from the SIP request. * @param requestLine is the SIP Request line from the SIP request. * @exception SIPAuthenticationException is thrown when authentication fails or message is bad */ public boolean doAuthenticate(String user, AuthorizationHeader authHeader, Request request) { String realm = authHeader.getRealm(); String username = authHeader.getUsername(); URI requestURI = request.getRequestURI(); if (username == null) { ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "WARNING: userName parameter not set in the header received!!!"); username = user; } if (realm == null) { ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "WARNING: realm parameter not set in the header received!!! WE use the default one"); realm = DEFAULT_REALM; } ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "Trying to authenticate user: "******" for " + " the realm: " + realm); String password = (String) passwordTable.get(username + "@" + realm); if (password == null) { ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "ERROR: password not found for the user: "******"@" + realm); return false; } String nonce = authHeader.getNonce(); // If there is a URI parameter in the Authorization header, // then use it. URI uri = authHeader.getURI(); // There must be a URI parameter in the authorization header. if (uri == null) { ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "ERROR: uri paramater not set in the header received!"); return false; } ProxyDebug.println( "DEBUG, DigestAuthenticationMethod, doAuthenticate(), username:"******"!"); ProxyDebug.println("DEBUG, DigestAuthenticationMethod, doAuthenticate(), realm:" + realm + "!"); ProxyDebug.println( "DEBUG, DigestAuthenticationMethod, doAuthenticate(), password:"******"!"); ProxyDebug.println("DEBUG, DigestAuthenticationMethod, doAuthenticate(), uri:" + uri + "!"); ProxyDebug.println("DEBUG, DigestAuthenticationMethod, doAuthenticate(), nonce:" + nonce + "!"); ProxyDebug.println( "DEBUG, DigestAuthenticationMethod, doAuthenticate(), method:" + request.getMethod() + "!"); String A1 = username + ":" + realm + ":" + password; String A2 = request.getMethod().toUpperCase() + ":" + uri.toString(); byte mdbytes[] = messageDigest.digest(A1.getBytes()); String HA1 = ProxyUtilities.toHexString(mdbytes); ProxyDebug.println("DEBUG, DigestAuthenticationMethod, doAuthenticate(), HA1:" + HA1 + "!"); mdbytes = messageDigest.digest(A2.getBytes()); String HA2 = ProxyUtilities.toHexString(mdbytes); ProxyDebug.println("DEBUG, DigestAuthenticationMethod, doAuthenticate(), HA2:" + HA2 + "!"); String cnonce = authHeader.getCNonce(); String KD = HA1 + ":" + nonce; if (cnonce != null) { KD += ":" + cnonce; } KD += ":" + HA2; mdbytes = messageDigest.digest(KD.getBytes()); String mdString = ProxyUtilities.toHexString(mdbytes); String response = authHeader.getResponse(); ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "we have to compare his response: " + response + " with our computed" + " response: " + mdString); int res = (mdString.compareTo(response)); if (res == 0) { ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "User authenticated..."); } else { ProxyDebug.println( "DEBUG, DigestAuthenticateMethod, doAuthenticate(): " + "User not authenticated..."); } return res == 0; }
@Override public String marshal(URI v) throws Exception { return v == null ? null : v.toString(); }
/** Construct connection using URI * */ public RhoConnection(URI _uri) { uri = new URI(_uri.toString()); uri_external = _uri; uri.setPath("/apps" + uri.getPath()); }
public String getURL() { log("getURL: " + uri_external.toString()); return uri_external.toString(); }