Skip to content

Commit

Permalink
Completed the logic that determines how credentials are acquired by the
Browse files Browse the repository at this point in the history
plugin.
  • Loading branch information
smoyer64 committed Nov 20, 2012
1 parent 6cf9a6b commit 8904017
Showing 1 changed file with 34 additions and 5 deletions.
Expand Up @@ -31,6 +31,7 @@

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.Settings;
import org.jboss.as.controller.client.ModelControllerClient;
import org.jboss.as.controller.client.helpers.domain.DomainClient;
Expand All @@ -43,6 +44,14 @@
* @author Stuart Douglas
*/
public abstract class AbstractServerConnection extends AbstractMojo implements ConnectionInfo, Closeable {

public static final String DEBUG_MESSAGE_NO_CREDS = "No username and password in settings.xml file - falling back to CLI entry";
public static final String DEBUG_MESSAGE_NO_ID = "No <id> element was found in the POM - Getting credentials from CLI entry";
public static final String DEBUG_MESSAGE_NO_SERVER_SECTION = "No <server> section was found for the specified id";
public static final String DEBUG_MESSAGE_NO_SETTINGS_FILE = "No settings.xml file was found in this Mojo's execution context";
public static final String DEBUG_MESSAGE_POM_HAS_CREDS = "Getting credentials from the POM";
public static final String DEBUG_MESSAGE_SETTINGS_HAS_CREDS = "Found username and password in the settings.xml file";
public static final String DEBUG_MESSAGE_SETTINGS_HAS_ID = "Found the server's id in the settings.xml file";

protected static final Object CLIENT_LOCK = new Object();

Expand Down Expand Up @@ -183,18 +192,38 @@ public synchronized final InetAddress getHostAddress() {
public synchronized final CallbackHandler getCallbackHandler() {
CallbackHandler result = handler;
if (result == null) {
if(username == null && password == null && id != null) {
getCredentialsFromSettings();
if(username == null && password == null) {
if(id != null) {
getCredentialsFromSettings();
} else {
getLog().debug(DEBUG_MESSAGE_NO_ID);
}
} else {
getLog().debug(DEBUG_MESSAGE_POM_HAS_CREDS);
}
result = handler = new ClientCallbackHandler(username, password);
}
return result;
}

private void getCredentialsFromSettings() {
getLog().info("AbstractServerConnection.getCredentialsFromSettings()");
password = settings.getServer(id).getPassword();
username = settings.getServer(id).getUsername();
if(settings != null) {
Server server = settings.getServer(id);
if(server != null) {
getLog().info(DEBUG_MESSAGE_SETTINGS_HAS_ID);
password = server.getPassword();
username = server.getUsername();
if(username != null && password != null) {
getLog().info(DEBUG_MESSAGE_SETTINGS_HAS_CREDS);
} else {
getLog().info(DEBUG_MESSAGE_NO_CREDS);
}
} else {
getLog().debug(DEBUG_MESSAGE_NO_SERVER_SECTION);
}
} else {
getLog().debug(DEBUG_MESSAGE_NO_SETTINGS_FILE);
}
}

private String getPasswordFromSettings() {
Expand Down

0 comments on commit 8904017

Please sign in to comment.