Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
themeEclipse
import nl.gx.webmanager.services.credentials.CredentialsProviderService;

public class ExampleCredentialsProviderServiceImpl extends SimpleServiceComponent implements ExampleCredentialsProviderService {

	protected static final Logger LOG = Logger.getLogger(ExampleCredentialsProviderServiceImpl.class.getName());
	private final static String USERNAME = "test";
	private final static String PASSWORD = "test";

	/**
	 * {@inheritDoc}
	 */
	public Credentials getCredentials(String identifier) {
		LOG.log(Level.INFO,"Returning username/password test/test as example credentials for identifier '" + identifier + "'");
		if (identifier.equalsIgnoreCase(CredentialsProviderService.INTERNAL_HTTP_REQUESTS_CREDENTIALS_IDENTIFIER) {
			// Integrate here with some type of storage for credential sets. For now..
			return new CredentialsImpl(identifier, USERNAME, PASSWORD);
		} else if (identifier.equalsIgnoreCase(CredentialsProviderService.HTTP_PROXY_CREDENTIALS_IDENTIFIER) {
			// Integrate here with some type of storage for credential sets. For now..
			return new CredentialsImpl(identifier, USERNAME, PASSWORD);
		} else {
			// For credentials used in custom configuration sets you can identity your own identifiers and capture
 			// them here. For now..
			return new CredentialsImpl(identifier, USERNAME, PASSWORD);
		}
	}
}


// The CredentialsImpl used
 
import nl.gx.webmanager.services.credentials.UsernamePasswordCredentials;
 
/**
 * Simple POJO implementation of the {@link UsernamePasswordCredentials} interface.
 */
public class CredentialsImpl implements UsernamePasswordCredentials {
     private String  myId;
     private String  myUsername;
     private String  myPassword;
 
    /**
     * Creates a new credentials object.
     *
     * @param username The username.
     * @param password The password.
     */
 
    public CredentialsImpl(String id, String username, String password) {
        myId = id;
        myUsername = username;
        myPassword = password;
    }
 
    /**
     * {@inheritDoc}
     */
    public String getId() {
        return myId;
    }
 
    /**
     * {@inheritDoc}
     */
    public String getUsername() {
        return myUsername;
    }
 
    /**
     * {@inheritDoc}
     */
    public String getPassword() {
        return myPassword;
    }
 
    /**
     * Returns the String represenation of a credentials object.
     *
     * @return The String representation.
     */
    @Override
    public String toString() {
        return "id=" + getId() + ", username=" + getUsername() + ", password=" + getPassword();
    }
}


Note that other credential sets that are infrastructure-related that are not already covered via the ones above can also be run though the credential provider logic, however in this case you need to accommodate this yourself. For example:

...