* @param propertyProfile property profile ID (0 for default / global)
* @return String
* @throws Exception
*/
public static String getProxyURL(User user, int propertyProfile) throws Exception {
String type = Property.getProperty(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.type", user.getRealm().getResourceId()));
if (type.equals("http") || type.equals("https")) {
String hostname = Property.getProperty(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.hostname", user.getRealm().getResourceId()));
if (!hostname.equals("")) {
StringBuffer url = new StringBuffer();
url.append(type);
url.append("://");
String username = Property.getProperty(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.username", user.getRealm().getResourceId()));
String domain = Property.getProperty(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.ntlmDomain", user.getRealm().getResourceId()));
String auth = Property.getProperty(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.preferredAuthentication", user.getRealm().getResourceId()));
if (!username.equals("")) {
if (!domain.equals("")) {
url.append(DAVUtilities.encodeURIUserInfo(domain + "\\"));
}
url.append(DAVUtilities.encodeURIUserInfo(username));
String password = Property.getProperty(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.password", user.getRealm().getResourceId()));
if (!password.equals("")) {
url.append(":");
url.append(DAVUtilities.encodeURIUserInfo(password));
}
url.append("@");
}
url.append(hostname);
int port = Property.getPropertyInt(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.port", user.getRealm().getResourceId()));
if (port != 0) {
url.append(":");
url.append(port);
}
url.append("?");
url.append(auth);
return url.toString();
}
} else if (type.equals("browser")) {
String auth = Property.getProperty(new ProfilePropertyKey(propertyProfile, user.getPrincipalName(), "clientProxy.preferredAuthentication", user.getRealm().getResourceId()));
return "browser://" + auth;
}
return null;
}