1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application.views.user.home.pagemode;
20
21 import org.springframework.beans.factory.annotation.Autowired;
22 import org.springframework.security.access.annotation.Secured;
23 import org.springframework.stereotype.Component;
24 import org.springframework.web.context.request.RequestContextHolder;
25
26 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
27 import com.hack23.cia.service.api.action.user.SetGoogleAuthenticatorCredentialRequest;
28 import com.hack23.cia.web.impl.ui.application.action.ViewAction;
29 import com.hack23.cia.web.impl.ui.application.util.UserContextUtil;
30 import com.hack23.cia.web.impl.ui.application.views.common.labelfactory.LabelFactory;
31 import com.hack23.cia.web.impl.ui.application.views.common.menufactory.api.UserHomeMenuItemFactory;
32 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommonsViews;
33 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.UserHomePageMode;
34 import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.SetGoogleAuthenticatorCredentialClickListener;
35 import com.vaadin.server.FontAwesome;
36 import com.vaadin.ui.Button;
37 import com.vaadin.ui.Layout;
38 import com.vaadin.ui.MenuBar;
39 import com.vaadin.ui.Panel;
40 import com.vaadin.ui.UI;
41 import com.vaadin.ui.VerticalLayout;
42
43
44
45
46 @Component
47 public final class UserHomeSecuritySettingsPageModContentFactoryImpl extends AbstractUserHomePageModContentFactoryImpl {
48
49
50 private static final String ENABLE_GOOGLE_AUTHENTICATOR = "Enable Google Authenticator";
51
52
53 private static final String USERHOME = "Userhome:";
54
55
56 private static final String SECURITY_SETTINGS = "Security Settings";
57
58
59 @Autowired
60 private UserHomeMenuItemFactory userHomeMenuItemFactory;
61
62
63
64
65
66 public UserHomeSecuritySettingsPageModContentFactoryImpl() {
67 super();
68 }
69
70 @Override
71 public boolean matches(final String page, final String parameters) {
72 return NAME.equals(page) && parameters.contains(UserHomePageMode.SECURITY_SETTINGS.toString());
73 }
74
75 @Secured({ "ROLE_USER", "ROLE_ADMIN" })
76 @Override
77 public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
78 final VerticalLayout panelContent = createPanelContent();
79
80 final String pageId = getPageId(parameters);
81
82 userHomeMenuItemFactory.createUserHomeMenuBar(menuBar, pageId);
83
84 LabelFactory.createHeader2Label(panelContent, SECURITY_SETTINGS);
85
86 final Long userIdFromSecurityContext = UserContextUtil.getUserInternalIdFromSecurityContext();
87
88 if (userIdFromSecurityContext == null) {
89 UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
90 } else {
91
92 final Button googleAuthButton = new Button(ENABLE_GOOGLE_AUTHENTICATOR, FontAwesome.USER_SECRET);
93 googleAuthButton.setId(ENABLE_GOOGLE_AUTHENTICATOR);
94
95 final SetGoogleAuthenticatorCredentialRequest googleAuthRequest = new SetGoogleAuthenticatorCredentialRequest();
96 googleAuthRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
97 googleAuthButton.addClickListener(
98 new SetGoogleAuthenticatorCredentialClickListener(googleAuthRequest));
99
100 panelContent.addComponent(googleAuthButton);
101
102 }
103
104 panel.setCaption(USERHOME + SECURITY_SETTINGS);
105
106 getPageActionEventHelper().createPageEvent(ViewAction.VISIT_USER_HOME_VIEW, ApplicationEventGroup.USER, NAME,
107 parameters, pageId);
108
109 return panelContent;
110
111 }
112
113 }