protected static String getHostFromURL(String url) { String result = url; final int colonSlashSlash = url.indexOf("://"); //$NON-NLS-1$ if (colonSlashSlash < 0) return ""; //$NON-NLS-1$ if (colonSlashSlash >= 0) { result = url.substring(colonSlashSlash + 3); } /////////////// Start change /////////////// int requestPath = result.indexOf('/'); final int user = result.indexOf('@'); if ( (requestPath > 0 && user > 0 && user < requestPath ) || (requestPath < 0 && user > 0)){ result = result.substring(user + 1); requestPath = result.indexOf('/'); } /////////////// End change /////////////// final int colonPort = result.indexOf(':'); int substringEnd; if (colonPort > 0 && requestPath > 0) substringEnd = Math.min(colonPort, requestPath); else if (colonPort > 0) substringEnd = colonPort; else if (requestPath > 0) substringEnd = requestPath; else substringEnd = result.length(); return result.substring(0, substringEnd); }
* New method */ protected Credentials getFileRequestCredentials(String urlString) throws UnsupportedCallbackException, IOException { Credentials credentials = getFileRequestCredentials(); if ( credentials != null ) return credentials; if ( urlString.matches(".+://.+:.+@.+") ) { String result = urlString.substring(urlString.indexOf("://") + 3); //$NON-NLS-1$ final int index1 = result.indexOf(":") ; //$NON-NLS-1$ username = result.substring(0,index1); result = result.substring(index1 + 1); password = result.substring(0, result.indexOf("@")); return new UsernamePasswordCredentials(username, password); } return null; } ... protected void setupAuthentication(String urlString) throws UnsupportedCallbackException, IOException { // code removed // Credentials credentials = null; // if (username == null) { // credentials = getFileRequestCredentials(); // } // Call the new method Credentials credentials = getFileRequestCredentials(urlString); ... }
BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext(); ServiceReference<IProvisioningAgent> serviceReference = bundleContext .getServiceReference(IProvisioningAgent.class); IProvisioningAgent baseagent= bundleContext.getService(serviceReference); if (baseagent== null) { System.out.println(">> no agent loaded!"); return; }
final UIServices adminUIService = (UIServices) baseagent.getService(UIServices.SERVICE_NAME); baseagent.registerService(UIServices.SERVICE_NAME, new UIServices() { @Override public AuthenticationInfo getUsernamePassword(String location, AuthenticationInfo previousInfo) { return new AuthenticationInfo("USER base on LOCATION", "PASS", false);// change if need } @Override public AuthenticationInfo getUsernamePassword(String location) { return new AuthenticationInfo("USER base on LOCATION", "PASS", false);// change if need } @Override public TrustInfo getTrustInfo(Certificate[][] untrustedChain, String[] unsignedDetail) { return adminUIService.getTrustInfo(untrustedChain, unsignedDetail); } });