Changeset 5692 in josm for trunk/src/org


Ignore:
Timestamp:
2013-01-30T02:25:13+01:00 (12 years ago)
Author:
Don-vip
Message:

fix EDT violation, javadoc

Location:
trunk/src/org/openstreetmap/josm/io/auth
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/auth/AbstractCredentialsAgent.java

    r4826 r5692  
    88
    99import org.openstreetmap.josm.gui.io.CredentialDialog;
     10import org.openstreetmap.josm.gui.util.GuiHelper;
    1011
    1112abstract public class AbstractCredentialsAgent implements CredentialsAgent {
     
    1415
    1516    /**
    16      * @see CredentialsAgent#getCredentials(RequestorType, boolean)
     17     * @see CredentialsAgent#getCredentials(RequestorType, String, boolean)
    1718     */
    1819    @Override
    19     public CredentialsAgentResponse getCredentials(RequestorType requestorType, String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException{
     20    public CredentialsAgentResponse getCredentials(final RequestorType requestorType, final String host, boolean noSuccessWithLastResponse) throws CredentialsAgentException{
    2021        if (requestorType == null)
    2122            return null;
    2223        PasswordAuthentication credentials =  lookup(requestorType, host);
    23         String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();
    24         String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
     24        final String username = (credentials == null || credentials.getUserName() == null) ? "" : credentials.getUserName();
     25        final String password = (credentials == null || credentials.getPassword() == null) ? "" : String.valueOf(credentials.getPassword());
    2526
    26         CredentialsAgentResponse response = new CredentialsAgentResponse();
     27        final CredentialsAgentResponse response = new CredentialsAgentResponse();
    2728
    2829        /*
     
    4546         */
    4647        } else if (noSuccessWithLastResponse || username.equals("") || password.equals("")) {
    47             CredentialDialog dialog = null;
    48             switch(requestorType) {
    49             case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break;
    50             case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break;
     48            GuiHelper.runInEDTAndWait(new Runnable() {
     49                @Override
     50                public void run() {
     51                    CredentialDialog dialog = null;
     52                    switch(requestorType) {
     53                    case SERVER: dialog = CredentialDialog.getOsmApiCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break;
     54                    case PROXY: dialog = CredentialDialog.getHttpProxyCredentialDialog(username, password, host, getSaveUsernameAndPasswordCheckboxText()); break;
     55                    }
     56                    dialog.setVisible(true);
     57                    response.setCanceled(dialog.isCanceled());
     58                    if (dialog.isCanceled())
     59                        return;
     60                    response.setUsername(dialog.getUsername());
     61                    response.setPassword(dialog.getPassword());
     62                    response.setSaveCredentials(dialog.isSaveCredentials());
     63                }
     64            });
     65            if (response.isCanceled()) {
     66                return response;
    5167            }
    52             dialog.setVisible(true);
    53             response.setCanceled(dialog.isCanceled());
    54             if (dialog.isCanceled())
    55                 return response;
    56             response.setUsername(dialog.getUsername());
    57             response.setPassword(dialog.getPassword());
    58             if (dialog.isSaveCredentials()) {
     68            if (response.isSaveCredentials()) {
    5969                store(requestorType, host, new PasswordAuthentication(
    6070                        response.getUsername(),
     
    6676             */
    6777            } else {
    68                 PasswordAuthentication pa = new PasswordAuthentication(dialog.getUsername(), dialog.getPassword());
     78                PasswordAuthentication pa = new PasswordAuthentication(response.getUsername(), response.getPassword());
    6979                memoryCredentialsCache.put(requestorType, pa);
    7080            }
  • trunk/src/org/openstreetmap/josm/io/auth/CredentialsAgentResponse.java

    r5266 r5692  
    33
    44/**
    5  * CredentialsAgentResponse represents the response from {@link CredentialsAgent#getCredentials(java.net.Authenticator.RequestorType, boolean)}.
     5 * CredentialsAgentResponse represents the response from {@link CredentialsAgent#getCredentials(java.net.Authenticator.RequestorType, String, boolean)}.
    66 *
    77 * The response consists of the username and the password the requested credentials consists of.
    88 * In addition, it provides information whether authentication was canceled by the user, i.e.
    99 * because he or she canceled a username/password dialog (see {@link #isCanceled()}.
     10 * It also provides information whether authentication should be saved.
    1011 *
    1112 */
     
    1415    private char[] password;
    1516    private boolean canceled;
     17    private boolean saveCredentials;
     18    /**
     19     * Replies the user name
     20     * @return The user name
     21     */
    1622    public String getUsername() {
    1723        return username;
    1824    }
     25    /**
     26     * Sets the user name
     27     * @param username The user name
     28     */
    1929    public void setUsername(String username) {
    2030        this.username = username;
    2131    }
     32    /**
     33     * Replies the password
     34     * @return The password in plain text
     35     */
    2236    public char[] getPassword() {
    2337        return password;
    2438    }
     39    /**
     40     * Sets the password
     41     * @param password The password in plain text
     42     */
    2543    public void setPassword(char[] password) {
    2644        this.password = password;
    2745    }
     46    /**
     47     * Determines if authentication request has been canceled by user
     48     * @return true if authentication request has been canceled by user, false otherwise
     49     */
    2850    public boolean isCanceled() {
    2951        return canceled;
    3052    }
     53    /**
     54     * Sets the cancelation status (authentication request canceled by user)
     55     * @param canceled the cancelation status (authentication request canceled by user)
     56     */
    3157    public void setCanceled(boolean canceled) {
    3258        this.canceled = canceled;
    3359    }
     60    /**
     61     * Determines if authentication credentials should be saved
     62     * @return true if authentication credentials should be saved, false otherwise
     63     */
     64    public boolean isSaveCredentials() {
     65        return saveCredentials;
     66    }
     67    /**
     68     * Sets the saving status (authentication credentials to save)
     69     * @param saveCredentials the saving status (authentication credentials to save)
     70     */
     71    public void setSaveCredentials(boolean saveCredentials) {
     72        this.saveCredentials = saveCredentials;
     73    }
    3474}
Note: See TracChangeset for help on using the changeset viewer.