Revision 47845 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.downloader/org.gvsig.downloader.swing/org.gvsig.downloader.swing.scribejava/src/main/java/org/gvsig/downloader/swing/scribejava/keycloak/DownloaderKeycloakCredentials.java

View differences:

DownloaderKeycloakCredentials.java
7 7

  
8 8
import com.github.scribejava.core.model.OAuth2AccessToken;
9 9
import javax.json.JsonObject;
10
import org.apache.commons.lang3.StringUtils;
10 11
import org.apache.commons.lang3.builder.ToStringBuilder;
11 12
import org.apache.commons.lang3.builder.ToStringStyle;
12 13
import org.gvsig.downloader.DownloaderAuthenticationConfig;
13 14
import org.gvsig.downloader.DownloaderCredentials;
15
import org.gvsig.downloader.DownloaderLocator;
16
import org.gvsig.downloader.DownloaderManager;
14 17
import org.gvsig.downloader.spi.AbstractDownloaderCredentials;
15 18
import org.gvsig.json.Json;
16 19

  
......
52 55
        return userid;
53 56
    }
54 57

  
58
    @Override
55 59
    public boolean isAuthorizationTokenExpired() { 
56 60
        try {
57 61
            long now = System.currentTimeMillis();
......
109 113
        builder.append("AuthorizationToken", this.getAuthorizationToken());
110 114
        return builder.build();
111 115
    }
112
          
113
    
114
 
115 116

  
117
    @Override
118
    public DownloaderCredentials createCredentials(String serviceUrl) {
119
        if (StringUtils.isBlank(serviceUrl)) {
120
            return null;
121
        }
122
        
123
        DownloaderManager downloader = DownloaderLocator.getDownloaderManager();
124
        DownloaderAuthenticationConfig theConfig = downloader.getAuthenticationConfigurationService(serviceUrl);
125
        if(theConfig == null){
126
            theConfig = this.config.createAuthenticationConfig(serviceUrl);
127
        }
128
        
129
        return new DownloaderKeycloakCredentials(
130
            (DownloaderAuthenticationKeycloakConfig) theConfig,
131
            this.getToken(),
132
            this.getUserid(),
133
            this.getTime()
134
        );
135
    }
136

  
137
    @Override
138
    public DownloaderCredentials createCredentials(DownloaderAuthenticationConfig config) {
139
        if(!(config instanceof DownloaderAuthenticationKeycloakConfig)){
140
            return null;
141
        }
142
        DownloaderAuthenticationKeycloakConfig otherConfig = (DownloaderAuthenticationKeycloakConfig)config;
143
        DownloaderAuthenticationKeycloakConfig myConfig = this.getConfig();
144
        
145
        if (!DownloaderManager.areSameURLs(myConfig.getKeycloakBaseurl(), otherConfig.getKeycloakBaseurl())) {
146
            return null;
147
        }
148
        if (!StringUtils.equals(myConfig.getRealm(), otherConfig.getRealm())) {
149
            return null;
150
        }
151
        if (!StringUtils.equals(myConfig.getClientid(), otherConfig.getClientid())) {
152
            return null;
153
        }
154
        if (!StringUtils.equals(myConfig.getScope(), otherConfig.getScope())) {
155
            return null;
156
        }
157
        
158
        return new DownloaderKeycloakCredentials(
159
            otherConfig,
160
            this.getToken(),
161
            this.getUserid(),
162
            this.getTime()
163
        );
164
    }
165

  
166

  
167

  
116 168
}

Also available in: Unified diff