21 |
21 |
*/
|
22 |
22 |
package org.gvsig.online.swing.scribejava.keycloak;
|
23 |
23 |
|
24 |
|
import org.gvsig.online.swing.scribejava.keycloak.callbacks.CallbackAuthorizationHandler;
|
25 |
|
import javax.swing.SwingUtilities;
|
26 |
|
import org.apache.commons.lang3.mutable.MutableBoolean;
|
27 |
|
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester;
|
28 |
|
|
29 |
24 |
import com.github.scribejava.apis.KeycloakApi;
|
30 |
25 |
import com.github.scribejava.core.builder.ServiceBuilder;
|
31 |
26 |
import com.github.scribejava.core.model.OAuthRequest;
|
32 |
27 |
import com.github.scribejava.core.model.Response;
|
33 |
28 |
import com.github.scribejava.core.model.Verb;
|
34 |
29 |
import com.github.scribejava.core.oauth.OAuth20Service;
|
35 |
|
import java.awt.Desktop;
|
36 |
30 |
import java.awt.Frame;
|
37 |
|
|
38 |
31 |
import java.io.IOException;
|
39 |
32 |
import java.net.URI;
|
40 |
33 |
import java.net.URISyntaxException;
|
41 |
34 |
import java.util.UUID;
|
42 |
35 |
import java.util.concurrent.ExecutionException;
|
43 |
36 |
import javax.json.JsonObject;
|
|
37 |
import javax.swing.SwingUtilities;
|
44 |
38 |
import org.apache.commons.codec.net.URLCodec;
|
45 |
39 |
import org.apache.commons.lang.StringUtils;
|
|
40 |
import org.apache.commons.lang3.mutable.MutableBoolean;
|
|
41 |
import org.gvsig.desktopopen.DesktopOpen;
|
46 |
42 |
import org.gvsig.json.Json;
|
|
43 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester;
|
|
44 |
import org.gvsig.online.swing.scribejava.keycloak.callbacks.CallbackAuthorizationHandler;
|
47 |
45 |
import org.gvsig.online.swing.scribejava.keycloak.callbacks.CallbackLogoutHandler;
|
48 |
46 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer;
|
|
47 |
import org.gvsig.tools.util.ToolsUtilLocator;
|
49 |
48 |
import org.slf4j.Logger;
|
50 |
49 |
import org.slf4j.LoggerFactory;
|
51 |
50 |
|
... | ... | |
148 |
147 |
try {
|
149 |
148 |
factory.addCallback(config, contextPath, callbackHandler);
|
150 |
149 |
final String authorizationUrl = service.getAuthorizationUrl();
|
151 |
|
Desktop.getDesktop().browse(new URI(authorizationUrl));
|
|
150 |
browse(authorizationUrl);
|
152 |
151 |
this.waitForResponse();
|
153 |
152 |
} catch(Exception e) {
|
154 |
153 |
LOGGER.warn("Can't authorize",e);
|
... | ... | |
173 |
172 |
|
174 |
173 |
factory.addCallback(config, contextPath, callbackHandler);
|
175 |
174 |
String logoutUrl = String.format(
|
176 |
|
"%s/auth/realms/%s/protocol/openid-connect/logout?post_logout_redirect_uri=%s&client_id=%s",
|
|
175 |
// "%s/auth/realms/%s/protocol/openid-connect/logout?post_logout_redirect_uri=%s&client_id=%s",
|
|
176 |
"%s/auth/realms/%s/protocol/openid-connect/logout?redirect_uri=%s&client_id=%s",
|
177 |
177 |
config.getBaseurl(),
|
178 |
178 |
realm,
|
179 |
179 |
redirect_uri,
|
180 |
180 |
client_id
|
181 |
181 |
);
|
182 |
182 |
|
183 |
|
Desktop.getDesktop().browse(new URI(logoutUrl));
|
|
183 |
browse(logoutUrl);
|
184 |
184 |
this.waitForResponse();
|
185 |
185 |
} catch(Exception e) {
|
186 |
186 |
LOGGER.warn("Can't logout",e);
|
... | ... | |
191 |
191 |
// LOGGER.info("logout finally2 "+requestId);
|
192 |
192 |
}
|
193 |
193 |
}
|
|
194 |
|
|
195 |
private void browse(String url) throws URISyntaxException, IOException {
|
|
196 |
// Desktop.getDesktop().browse(new URI(url));
|
|
197 |
DesktopOpen desktop = ToolsUtilLocator.getToolsUtilManager().createDesktopOpen();
|
|
198 |
desktop.browse(new URI(url));
|
|
199 |
}
|
194 |
200 |
|
195 |
201 |
public JsonObject userInfo(OAuth20Service service) throws InterruptedException, IOException, ExecutionException {
|
196 |
202 |
// LOGGER.info("userInfo");
|
... | ... | |
256 |
262 |
|
257 |
263 |
UserIdentificationKeycloakConfig conf = factory.create("https://devel.gvsigonline.com/gvsigonline");
|
258 |
264 |
|
259 |
|
conf.setLocalPort(8888);
|
|
265 |
conf.setLocalPort(8889);
|
260 |
266 |
conf.setBaseurl("https://keycloak.scolab.eu");
|
261 |
267 |
conf.setRealm("joaquin");
|
262 |
268 |
|