2256 |
27 Feb 14 |
nicklas |
1 |
package net.sf.basedb.yubikey; |
2256 |
27 Feb 14 |
nicklas |
2 |
|
2256 |
27 Feb 14 |
nicklas |
3 |
import net.sf.basedb.clients.web.extensions.AbstractJspActionFactory; |
2256 |
27 Feb 14 |
nicklas |
4 |
import net.sf.basedb.clients.web.extensions.login.FieldInfo; |
2256 |
27 Feb 14 |
nicklas |
5 |
import net.sf.basedb.clients.web.extensions.login.LoginFormAction; |
2256 |
27 Feb 14 |
nicklas |
6 |
import net.sf.basedb.clients.web.extensions.login.LoginFormBean; |
2256 |
27 Feb 14 |
nicklas |
7 |
import net.sf.basedb.util.extensions.InvokationContext; |
2256 |
27 Feb 14 |
nicklas |
8 |
|
2256 |
27 Feb 14 |
nicklas |
9 |
/** |
2256 |
27 Feb 14 |
nicklas |
Action factory for the YubiKey authentication. |
2256 |
27 Feb 14 |
nicklas |
Returns an {@link YubiKeyAuthenticationManager} action. |
2256 |
27 Feb 14 |
nicklas |
12 |
|
2256 |
27 Feb 14 |
nicklas |
@author nicklas |
2256 |
27 Feb 14 |
nicklas |
@since 1.0 |
2256 |
27 Feb 14 |
nicklas |
15 |
*/ |
2256 |
27 Feb 14 |
nicklas |
16 |
public class YubiKeyLoginFormFactory |
2256 |
27 Feb 14 |
nicklas |
17 |
extends AbstractJspActionFactory<LoginFormAction> |
2256 |
27 Feb 14 |
nicklas |
18 |
{ |
2256 |
27 Feb 14 |
nicklas |
19 |
|
5150 |
28 Nov 18 |
nicklas |
20 |
private final LoginFormBean loginForm; |
2256 |
27 Feb 14 |
nicklas |
21 |
|
2256 |
27 Feb 14 |
nicklas |
22 |
public YubiKeyLoginFormFactory() |
2256 |
27 Feb 14 |
nicklas |
23 |
{ |
5150 |
28 Nov 18 |
nicklas |
24 |
loginForm = new LoginFormBean(); |
5150 |
28 Nov 18 |
nicklas |
25 |
loginForm.setDisplayName("YubiKey"); |
5150 |
28 Nov 18 |
nicklas |
26 |
loginForm.setRememberLastLogin(false); |
5150 |
28 Nov 18 |
nicklas |
27 |
loginForm.setHelp( |
3995 |
13 Jun 16 |
nicklas |
28 |
"Insert the <a href=\"http://www.yubico.com/\" target=\"_top\">YubiKey</a> stick into a USB slot in your computer and press " |
3995 |
13 Jun 16 |
nicklas |
29 |
+ "the button when the green light is turned on. " |
5150 |
28 Nov 18 |
nicklas |
30 |
+ "Then enter your regular password."); |
5150 |
28 Nov 18 |
nicklas |
31 |
FieldInfo yubikeyField = new FieldInfo("YubiKey", false); |
5150 |
28 Nov 18 |
nicklas |
32 |
yubikeyField.setStyle("width: 98%;"); |
5150 |
28 Nov 18 |
nicklas |
33 |
yubikeyField.setTooltip("Press the YubiKey button to generate a one-time-password"); |
5150 |
28 Nov 18 |
nicklas |
34 |
loginForm.setLoginField(yubikeyField); |
5150 |
28 Nov 18 |
nicklas |
35 |
loginForm.setPasswordField(FieldInfo.DEFAULT_PASSWORD); |
2256 |
27 Feb 14 |
nicklas |
36 |
} |
2256 |
27 Feb 14 |
nicklas |
37 |
|
3995 |
13 Jun 16 |
nicklas |
38 |
@Override |
3995 |
13 Jun 16 |
nicklas |
39 |
public boolean prepareContext(InvokationContext<? super LoginFormAction> context) |
3995 |
13 Jun 16 |
nicklas |
40 |
{ |
3995 |
13 Jun 16 |
nicklas |
41 |
String clientId = context.getClientContext().getSessionControl().getExternalClientId(); |
5184 |
06 Dec 18 |
nicklas |
42 |
boolean ok = YubiKey.getConfig(true) != null && !YubiKey.isYubiKeyDisabledForClient(clientId); |
4364 |
22 Feb 17 |
nicklas |
43 |
|
4364 |
22 Feb 17 |
nicklas |
44 |
return ok && super.prepareContext(context); |
3995 |
13 Jun 16 |
nicklas |
45 |
} |
3995 |
13 Jun 16 |
nicklas |
46 |
|
2256 |
27 Feb 14 |
nicklas |
47 |
/** |
2256 |
27 Feb 14 |
nicklas |
@return A single {@link LoginFormBean} instance |
2256 |
27 Feb 14 |
nicklas |
49 |
*/ |
2256 |
27 Feb 14 |
nicklas |
50 |
@Override |
2256 |
27 Feb 14 |
nicklas |
51 |
public LoginFormAction[] getActions(InvokationContext<? super LoginFormAction> context) |
2256 |
27 Feb 14 |
nicklas |
52 |
{ |
3995 |
13 Jun 16 |
nicklas |
53 |
String clientId = context.getClientContext().getSessionControl().getExternalClientId(); |
5150 |
28 Nov 18 |
nicklas |
54 |
return new LoginFormAction[] { loginForm }; |
2256 |
27 Feb 14 |
nicklas |
55 |
} |
2256 |
27 Feb 14 |
nicklas |
56 |
|
2256 |
27 Feb 14 |
nicklas |
57 |
} |