Search in sources :

Example 1 with ICredentialDomain

use of org.jboss.tools.foundation.core.credentials.ICredentialDomain in project jbosstools-openshift by jbosstools.

the class CDKServer method getUsername.

public String getUsername() {
    ControllableServerBehavior beh = (ControllableServerBehavior) getServer().loadAdapter(ControllableServerBehavior.class, new NullProgressMonitor());
    Object user2 = beh.getSharedData(CDKServerBehaviour.PROP_CACHED_USER);
    if (user2 instanceof String)
        return (String) user2;
    String user = getServer().getAttribute(PROP_USERNAME, (String) null);
    if (user == null) {
        ICredentialDomain domain = CredentialService.getCredentialModel().getDomain(CredentialService.REDHAT_ACCESS);
        user = domain.getDefaultUsername();
    }
    return user;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ICredentialDomain(org.jboss.tools.foundation.core.credentials.ICredentialDomain) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)

Example 2 with ICredentialDomain

use of org.jboss.tools.foundation.core.credentials.ICredentialDomain in project jbosstools-openshift by jbosstools.

the class CDKServer method getPassword.

public String getPassword() throws UsernameChangedException {
    ControllableServerBehavior beh = (ControllableServerBehavior) getServer().loadAdapter(ControllableServerBehavior.class, new NullProgressMonitor());
    Object pw = beh.getSharedData(CDKServerBehaviour.PROP_CACHED_PASSWORD);
    if (pw instanceof String)
        return (String) pw;
    ICredentialDomain domain = CredentialService.getCredentialModel().getDomain(CredentialService.REDHAT_ACCESS);
    String user = getUsername();
    if (user != null && domain != null) {
        try {
            return domain.getCredentials(user);
        } catch (StorageException se) {
            CDKCoreActivator.getDefault().getLog().log(new Status(IStatus.ERROR, CDKCoreActivator.PLUGIN_ID, se.getMessage(), se));
        } catch (UsernameChangedException uce) {
            if (uce.getSaveCredentials()) {
                saveChangedCredentials(uce);
            }
            throw uce;
        }
    }
    return null;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) UsernameChangedException(org.jboss.tools.foundation.core.credentials.UsernameChangedException) ICredentialDomain(org.jboss.tools.foundation.core.credentials.ICredentialDomain) ControllableServerBehavior(org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior) StorageException(org.eclipse.equinox.security.storage.StorageException)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ControllableServerBehavior (org.jboss.ide.eclipse.as.wtp.core.server.behavior.ControllableServerBehavior)2 ICredentialDomain (org.jboss.tools.foundation.core.credentials.ICredentialDomain)2 IStatus (org.eclipse.core.runtime.IStatus)1 Status (org.eclipse.core.runtime.Status)1 StorageException (org.eclipse.equinox.security.storage.StorageException)1 UsernameChangedException (org.jboss.tools.foundation.core.credentials.UsernameChangedException)1