Revision 9513
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/none/UserIdentificationGuestFactory.java | ||
---|---|---|
1 |
package org.gvsig.online.swing.impl.authentication.none; |
|
2 |
|
|
3 |
import org.gvsig.online.lib.api.OnlineLocator; |
|
4 |
import org.gvsig.online.lib.api.OnlineManager; |
|
5 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester.OnlineUserIdentificationRequesterFactory; |
|
6 |
|
|
7 |
/** |
|
8 |
* |
|
9 |
* @author jjdelcerro |
|
10 |
*/ |
|
11 |
public class UserIdentificationGuestFactory implements OnlineUserIdentificationRequesterFactory { |
|
12 |
|
|
13 |
public UserIdentificationGuestFactory() { |
|
14 |
} |
|
15 |
|
|
16 |
@Override |
|
17 |
public String getName() { |
|
18 |
return "Guest"; |
|
19 |
} |
|
20 |
|
|
21 |
@Override |
|
22 |
public UserIdentificationGuestConfig create(Object... parameters) { |
|
23 |
return new UserIdentificationGuestConfig(this, (String)parameters[0]); |
|
24 |
} |
|
25 |
|
|
26 |
|
|
27 |
public static void selfRegister() { |
|
28 |
OnlineManager manager = OnlineLocator.getOnlineManager(); |
|
29 |
manager.addUserIdentificationRequester(new UserIdentificationGuestFactory()); |
|
30 |
} |
|
31 |
} |
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/none/UserIdentificationGuest.java | ||
---|---|---|
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.none; |
|
24 |
|
|
25 |
import javax.swing.SwingUtilities; |
|
26 |
import org.apache.commons.lang3.mutable.MutableBoolean; |
|
27 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester; |
|
28 |
|
|
29 |
/** |
|
30 |
* |
|
31 |
* @author gvSIG Team |
|
32 |
*/ |
|
33 |
@SuppressWarnings("UseSpecificCatch") |
|
34 |
public class UserIdentificationGuest |
|
35 |
implements OnlineUserIdentificationRequester |
|
36 |
{ |
|
37 |
|
|
38 |
private final UserIdentificationGuestConfig config; |
|
39 |
|
|
40 |
public UserIdentificationGuest(UserIdentificationGuestConfig config) { |
|
41 |
this.config = config; |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public boolean requestIdentification() { |
|
46 |
if( !SwingUtilities.isEventDispatchThread() ) { |
|
47 |
try { |
|
48 |
MutableBoolean r = new MutableBoolean(); |
|
49 |
SwingUtilities.invokeAndWait(() -> { |
|
50 |
r.setValue(requestIdentification()); |
|
51 |
}); |
|
52 |
return r.booleanValue(); |
|
53 |
} catch (Exception ex) { |
|
54 |
return false; |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
58 |
return true; |
|
59 |
} |
|
60 |
|
|
61 |
@Override |
|
62 |
public String getUserId() { |
|
63 |
return "guest"; |
|
64 |
} |
|
65 |
|
|
66 |
@Override |
|
67 |
public String getAuthorization() { |
|
68 |
return null; |
|
69 |
} |
|
70 |
|
|
71 |
} |
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/none/UserIdentificationGuestConfig.java | ||
---|---|---|
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.online.swing.impl.authentication.none; |
|
7 |
|
|
8 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester; |
|
9 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester.OnlineUserIdentificationRequesterConfig; |
|
10 |
import org.gvsig.online.lib.spi.AbstractOnlineUserIdentificationRequesterConfig; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
*/ |
|
16 |
public class UserIdentificationGuestConfig |
|
17 |
extends AbstractOnlineUserIdentificationRequesterConfig |
|
18 |
implements OnlineUserIdentificationRequesterConfig |
|
19 |
{ |
|
20 |
|
|
21 |
public UserIdentificationGuestConfig(UserIdentificationGuestFactory factory, String siteURL) { |
|
22 |
super(factory,siteURL); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public OnlineUserIdentificationRequester createUserIdentificationRequester() { |
|
27 |
return new UserIdentificationGuest(this); |
|
28 |
} |
|
29 |
} |
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 | ||
---|---|---|
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 |
} |
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/UserIdentificationOnlineConfig.java | ||
---|---|---|
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.online.swing.impl.authentication.online; |
|
7 |
|
|
8 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester; |
|
9 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester.OnlineUserIdentificationRequesterConfig; |
|
10 |
import org.gvsig.online.lib.spi.AbstractOnlineUserIdentificationRequesterConfig; |
|
11 |
|
|
12 |
/** |
|
13 |
* |
|
14 |
* @author jjdelcerro |
|
15 |
*/ |
|
16 |
public class UserIdentificationOnlineConfig |
|
17 |
extends AbstractOnlineUserIdentificationRequesterConfig |
|
18 |
implements OnlineUserIdentificationRequesterConfig |
|
19 |
{ |
|
20 |
|
|
21 |
public UserIdentificationOnlineConfig(UserIdentificationOnlineFactory factory, String siteURL) { |
|
22 |
super(factory,siteURL); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
public OnlineUserIdentificationRequester createUserIdentificationRequester() { |
|
27 |
return new UserIdentificationOnline(this); |
|
28 |
} |
|
29 |
|
|
30 |
} |
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/UserIdentificationOnlineFactory.java | ||
---|---|---|
1 |
package org.gvsig.online.swing.impl.authentication.online; |
|
2 |
|
|
3 |
import org.gvsig.online.lib.api.OnlineLocator; |
|
4 |
import org.gvsig.online.lib.api.OnlineManager; |
|
5 |
import static org.gvsig.online.lib.api.OnlineManager.AUTH_MODE_ONLINE; |
|
6 |
import org.gvsig.online.lib.api.OnlineUserIdentificationRequester.OnlineUserIdentificationRequesterFactory; |
|
7 |
|
|
8 |
/** |
|
9 |
* |
|
10 |
* @author jjdelcerro |
|
11 |
*/ |
|
12 |
public class UserIdentificationOnlineFactory implements OnlineUserIdentificationRequesterFactory { |
|
13 |
|
|
14 |
public UserIdentificationOnlineFactory() { |
|
15 |
} |
|
16 |
|
|
17 |
@Override |
|
18 |
public String getName() { |
|
19 |
return AUTH_MODE_ONLINE; |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
public UserIdentificationOnlineConfig create(Object... parameters) { |
|
24 |
return new UserIdentificationOnlineConfig(this, (String)parameters[0]); |
|
25 |
} |
|
26 |
|
|
27 |
public static void selfRegister() { |
|
28 |
OnlineManager manager = OnlineLocator.getOnlineManager(); |
|
29 |
manager.addUserIdentificationRequester(new UserIdentificationOnlineFactory()); |
|
30 |
} |
|
31 |
} |
Also available in: Unified diff