{
Principal prevUsername = null;
Object prevPassword = null;
SPIProvider spiProvider = SPIProviderResolver.getInstance().getProvider();
SecurityAdaptor securityAdaptor = spiProvider.getSPI(SecurityAdaptorFactory.class).newSecurityAdapter();
if (username != null || password != null)
{
prevUsername = securityAdaptor.getPrincipal();
prevPassword = securityAdaptor.getCredential();
securityAdaptor.setPrincipal(new SimplePrincipal(username));
securityAdaptor.setCredential(password);
}
try
{
server.invoke(new ObjectName(MAIN_DEPLOYER), methodName, new Object[] { url }, new String[] { "java.net.URL" });
}
finally
{
if (username != null || password != null)
{
securityAdaptor.setPrincipal(prevUsername);
securityAdaptor.setCredential(prevPassword);
}
}
}