Revision 47828 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.lib/org.gvsig.downloader.lib.impl/src/main/java/org/gvsig/downloader/lib/impl/DownloaderManagerImpl.java

View differences:

DownloaderManagerImpl.java
69 69
        return t;
70 70
    }
71 71

  
72
    private String getUrlWithoutQuery(URL url) {
73
        try {
74
            URL x = new URL(url.getProtocol(), url.getHost(), url.getPath());
75
            return x.toExternalForm();
76
        } catch(Exception ex) {
77
            return null;
78
        }
79
    }
80
    
81
    private String getUrlWithoutQuery(String url) {
82
        try {
83
            return this.getUrlWithoutQuery(new URL(url));
84
        } catch(Exception ex) {
85
            return null;
86
        }
87
    }
88
    
72 89
    @Override
73 90
    public void addOrReplaceCredentials(DownloaderCredentials credentials) {
74
        this.credentials.put(credentials.getBaseUrl(), credentials);
91
        if( credentials == null ) {
92
            LOG.warn("Invalid credentials (null).");
93
            return;
94
        }
95
        String url = this.getUrlWithoutQuery(credentials.getServiceUrl());
96
        if( url == null ) {
97
            LOG.warn("Invalid URL '"+credentials.getServiceUrl()+"'");
98
            return;
99
        }
100
        this.credentials.put(url, credentials);
75 101
    }
76 102

  
77 103
    @Override
78 104
    public void removeCredentials(DownloaderCredentials credentials) {
79
        this.credentials.remove(credentials.getBaseUrl());
105
        if( credentials == null ) {
106
            return;
107
        }
108
        String x = credentials.getServiceUrl();
109
        if( x == null ) {
110
            return;
111
        }
112
        this.credentials.remove(x);
80 113
    }
81 114

  
82 115
    @Override
116
    public DownloaderCredentials getCredentials(URL url) {
117
        return this.getCredentials(url.toExternalForm());
118
    }
119

  
120
    @Override
121
    public DownloaderCredentials getCredentials(String url) {
122
        for (DownloaderCredentials theCredentials : this.credentials.values()) {
123
            if( StringUtils.startsWith(url, theCredentials.getServiceUrl()) ) {
124
                return theCredentials;
125
            }
126
        }
127
        return null;
128
    }
129

  
130
    @Override
83 131
    public void registerAuthenticationConfigurationService(DownloaderAuthenticationConfig config ) {
84 132
        authenticationConfigurationServices.put(config.getKey(), config);
85 133
    }
......
97 145
    @Override
98 146
    public DownloaderAuthenticationConfig getAuthenticationConfigurationService(String baseUrl) {
99 147
        for (DownloaderAuthenticationConfig config : this.authenticationConfigurationServices.values()) {
100
            if( StringUtils.startsWith(baseUrl, config.getBaseUrl()) ) {
148
            if( StringUtils.startsWith(baseUrl, config.getServiceUrl()) ) {
101 149
                return config;
102 150
            }
103 151
        }
......
119 167
        return this.credentials.values();
120 168
    }
121 169

  
122
    @Override
123
    public DownloaderCredentials getCredentials(URL url) {
124
        for (DownloaderCredentials theCredentials : this.credentials.values()) {
125
            if( StringUtils.startsWith(url.toString(), theCredentials.getBaseUrl()) ) {
126
                return theCredentials;
127
            }
128
        }
170
    public DownloaderAuthenticationConfig requestAutenticationConfig(URL url) { // TODO: falta por implementar
129 171
        return null;
130 172
    }
131 173

  
132
    public DownloaderAuthenticationConfig requestAutenticationConfig(URL url) { // TODO: falta por implementar
133
        return null;
174
    @Override
175
    public DownloaderAuthenticationFactory getDownloaderAuthenticationFactory(String providerName) {
176
        return this.authenticationTypes.get(providerName);
134 177
    }
135 178

  
136 179
}

Also available in: Unified diff