gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.swing / org.gvsig.online.swing.impl / src / main / java / org / gvsig / online / swing / impl / authentication / online / UserIdentificationOnline.java @ 9513
History | View | Annotate | Download (3.2 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2020 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
18 |
*
|
19 |
* For any additional information, do not hesitate to contact us
|
20 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.online.swing.impl.authentication.online; |
24 |
|
25 |
import java.awt.event.ActionEvent; |
26 |
import javax.swing.SwingUtilities; |
27 |
import org.apache.commons.lang3.StringUtils; |
28 |
import org.apache.commons.lang3.mutable.MutableBoolean; |
29 |
import org.gvsig.online.lib.api.OnlineLocator; |
30 |
import org.gvsig.online.lib.api.OnlineManager; |
31 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester; |
32 |
import org.gvsig.online.swing.impl.loggin.LogginDialog; |
33 |
|
34 |
/**
|
35 |
*
|
36 |
* @author gvSIG Team
|
37 |
*/
|
38 |
@SuppressWarnings("UseSpecificCatch") |
39 |
public class UserIdentificationOnline |
40 |
implements OnlineUserIdentificationRequester
|
41 |
{ |
42 |
|
43 |
private String userId; |
44 |
private String password; |
45 |
private String authorization; |
46 |
private final UserIdentificationOnlineConfig config; |
47 |
|
48 |
public UserIdentificationOnline(UserIdentificationOnlineConfig config) {
|
49 |
this.config = config;
|
50 |
this.password = null; |
51 |
this.userId = null; |
52 |
this.authorization = null; |
53 |
} |
54 |
|
55 |
@Override
|
56 |
public boolean requestIdentification() { |
57 |
if( !SwingUtilities.isEventDispatchThread() ) { |
58 |
try {
|
59 |
MutableBoolean r = new MutableBoolean();
|
60 |
SwingUtilities.invokeAndWait(() -> {
|
61 |
r.setValue(requestIdentification()); |
62 |
}); |
63 |
return r.booleanValue();
|
64 |
} catch (Exception ex) { |
65 |
return false; |
66 |
} |
67 |
} |
68 |
|
69 |
LogginDialog logginDialog = new LogginDialog(this.userId, this.password); |
70 |
logginDialog.addActionListener((ActionEvent e) -> {
|
71 |
this.userId = logginDialog.getUserId();
|
72 |
this.password = logginDialog.getPassword();
|
73 |
OnlineManager manager = OnlineLocator.getOnlineManager(); |
74 |
this.authorization = manager.authenticate(
|
75 |
this.config.getUrlOnline(),
|
76 |
this.userId,
|
77 |
this.password
|
78 |
); |
79 |
}); |
80 |
if( !logginDialog.showDialog() ) {
|
81 |
return false; |
82 |
} |
83 |
if( StringUtils.isBlank(this.authorization) ) { |
84 |
return false; |
85 |
} |
86 |
return true; |
87 |
} |
88 |
|
89 |
@Override
|
90 |
public String getUserId() { |
91 |
return this.userId; |
92 |
} |
93 |
|
94 |
@Override
|
95 |
public String getAuthorization() { |
96 |
return this.authorization; |
97 |
} |
98 |
|
99 |
} |