Statistics
| Revision:

svn-gvsig-desktop / 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 / types / httpbasic / DownloaderHTTPBasicAuthenticationConfig.java @ 47841

History | View | Annotate | Download (2.32 KB)

1
/*
2
 * To change this license header, choose License Headers in Project Properties.
3
 * To change this template file, choose Tools | Templates
4
 * and open the template in the editor.
5
 */
6
package org.gvsig.downloader.lib.impl.types.httpbasic;
7

    
8
import org.gvsig.downloader.DownloaderAuthenticationConfig;
9
import org.gvsig.downloader.DownloaderAuthenticationRequester;
10
import org.gvsig.downloader.DownloaderCredentials;
11
import org.gvsig.downloader.DownloaderManager;
12
import static org.gvsig.downloader.lib.impl.types.httpbasic.DownloaderHTTPBasicAuthenticationFactory.HTTPBASIC_AUTHENTICATION_NAME;
13
import org.gvsig.downloader.spi.AbstractDownloaderAuthenticationConfig;
14
import org.gvsig.json.JsonObjectBuilder;
15

    
16

    
17
/**
18
 *
19
 * @author jjdelcerro
20
 */
21
public class DownloaderHTTPBasicAuthenticationConfig
22
        extends AbstractDownloaderAuthenticationConfig
23
        implements DownloaderAuthenticationConfig 
24
    {
25
    
26
    /**
27
     * Constructor necesario para la persistencia
28
     */
29
    public DownloaderHTTPBasicAuthenticationConfig() {
30
        this(null, null);
31
    }
32

    
33
    public DownloaderHTTPBasicAuthenticationConfig(DownloaderHTTPBasicAuthenticationFactory factory, String baseUrl) {
34
        super(HTTPBASIC_AUTHENTICATION_NAME, factory, baseUrl);
35
    }
36
    
37
    @Override
38
    public DownloaderAuthenticationRequester create() {
39
        return new DownloaderHTTPBasicAuthenticationRequester(this);
40
    }
41

    
42
    @Override
43
    public Object clone() throws CloneNotSupportedException {
44
        return super.clone();
45
    }
46

    
47
    @Override
48
    public DownloaderCredentials getCredentials(DownloaderCredentials credentials) {
49
        if(!(credentials instanceof DownloaderHTTPBasicCredentials)){
50
            return null;
51
        }
52
        DownloaderHTTPBasicCredentials theCredentials = (DownloaderHTTPBasicCredentials)credentials;
53
        if (DownloaderManager.urlStartsWith(this.getServiceUrl(), theCredentials.getServiceUrl())) {
54
                return new DownloaderHTTPBasicCredentials(
55
                        this.getServiceUrl(),
56
                        theCredentials.getUserid(), 
57
                        theCredentials.getPassword()
58
                );
59
        }
60
        return null;
61
    }
62

    
63
    @Override
64
    public JsonObjectBuilder toJsonBuilder() {
65
        JsonObjectBuilder builder = super.toJsonBuilder();
66
        builder.add_class(this);
67
        return builder;
68
    }
69

    
70

    
71
}