Revision 9517
org.gvsig.online/trunk/org.gvsig.online/org.gvsig.online.swing/org.gvsig.online.swing.scribejava/src/main/java/org/gvsig/online/swing/scribejava/keycloak/UserIdentificationKeycloak.java | ||
---|---|---|
34 | 34 |
import java.util.UUID; |
35 | 35 |
import java.util.concurrent.ExecutionException; |
36 | 36 |
import javax.json.JsonObject; |
37 |
import javax.swing.JOptionPane; |
|
37 | 38 |
import javax.swing.SwingUtilities; |
38 | 39 |
import org.apache.commons.codec.net.URLCodec; |
39 | 40 |
import org.apache.commons.lang.StringUtils; |
... | ... | |
43 | 44 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester; |
44 | 45 |
import org.gvsig.online.swing.scribejava.keycloak.callbacks.CallbackAuthorizationHandler; |
45 | 46 |
import org.gvsig.online.swing.scribejava.keycloak.callbacks.CallbackLogoutHandler; |
47 |
import org.gvsig.tools.ToolsLocator; |
|
48 |
import org.gvsig.tools.i18n.I18nManager; |
|
46 | 49 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
50 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
|
51 |
import org.gvsig.tools.swing.api.threadsafedialogs.ThreadSafeDialogsManager; |
|
47 | 52 |
import org.gvsig.tools.util.ToolsUtilLocator; |
48 | 53 |
import org.slf4j.Logger; |
49 | 54 |
import org.slf4j.LoggerFactory; |
... | ... | |
64 | 69 |
private String authorization; |
65 | 70 |
private final UserIdentificationKeycloakConfig config; |
66 | 71 |
private final Object monitor = new Object(); |
72 |
private boolean stopedWaitingForResponse = false; |
|
73 |
private boolean userCancelledWaitingForResponse = false; |
|
67 | 74 |
|
68 | 75 |
public UserIdentificationKeycloak(UserIdentificationKeycloakConfig config) { |
69 | 76 |
this.config = config; |
... | ... | |
96 | 103 |
OAuth20Service service = createService(authCallback); |
97 | 104 |
|
98 | 105 |
logout(service, requestId); |
99 |
authorize(service, requestId); |
|
106 |
if( !this.isUserCancelledWaitingForResponse() ) { |
|
107 |
authorize(service, requestId); |
|
108 |
} |
|
100 | 109 |
|
101 | 110 |
applicationToFront(); |
102 | 111 |
return StringUtils.isNotBlank(this.authorization); |
... | ... | |
220 | 229 |
public void waitForResponse() { |
221 | 230 |
// LOGGER.info("waitForTheResponse"); |
222 | 231 |
synchronized (this.monitor) { |
232 |
ThreadSafeDialogsManager dialogs = ToolsSwingLocator.getThreadSafeDialogsManager(); |
|
233 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
|
223 | 234 |
try { |
224 |
this.monitor.wait(3 * 60 * 1000); |
|
235 |
this.stopedWaitingForResponse = false; |
|
236 |
this.userCancelledWaitingForResponse = false; |
|
237 |
while( !this.userCancelledWaitingForResponse && !this.stopedWaitingForResponse) { |
|
238 |
this.monitor.wait(20 * 1000); |
|
239 |
if( !this.stopedWaitingForResponse ) { |
|
240 |
int n = dialogs.confirmDialog( |
|
241 |
i18n.getTranslation("_Do_you_want_to_continue_waiting_for_the_authentication_to_complete"), |
|
242 |
i18n.getTranslation("_Authentication"), |
|
243 |
JOptionPane.YES_NO_OPTION, |
|
244 |
JOptionPane.QUESTION_MESSAGE |
|
245 |
); |
|
246 |
if( n == JOptionPane.NO_OPTION ) { |
|
247 |
this.userCancelledWaitingForResponse = true; |
|
248 |
} |
|
249 |
} |
|
250 |
} |
|
225 | 251 |
} catch (InterruptedException ex) { |
226 | 252 |
|
227 | 253 |
} |
... | ... | |
232 | 258 |
public void stopWaitingForResponse() { |
233 | 259 |
// LOGGER.info("stopWaitingForResponse"); |
234 | 260 |
synchronized (this.monitor) { |
261 |
this.stopedWaitingForResponse = true; |
|
235 | 262 |
this.monitor.notifyAll(); |
236 | 263 |
} |
237 | 264 |
// LOGGER.info("stopWaitingForResponse exit"); |
238 | 265 |
} |
266 |
|
|
267 |
private boolean isUserCancelledWaitingForResponse() { |
|
268 |
return this.userCancelledWaitingForResponse; |
|
269 |
} |
|
239 | 270 |
|
240 | 271 |
@Override |
241 | 272 |
public String getUserId() { |
Also available in: Unified diff