Search in sources :

Example 41 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class SetGoogleAuthenticatorCredentialService method processService.

@Override
@Secured({ "ROLE_USER", "ROLE_ADMIN" })
public SetGoogleAuthenticatorCredentialResponse processService(final SetGoogleAuthenticatorCredentialRequest serviceRequest) {
    final SetGoogleAuthenticatorCredentialResponse inputValidation = inputValidation(serviceRequest);
    if (inputValidation != null) {
        return inputValidation;
    }
    LOGGER.info("{}:{}", serviceRequest.getClass().getSimpleName(), serviceRequest.getSessionId());
    final CreateApplicationEventRequest eventRequest = createApplicationEventForService(serviceRequest);
    final UserAccount userAccount = getUserAccountFromSecurityContext();
    final SetGoogleAuthenticatorCredentialResponse response = new SetGoogleAuthenticatorCredentialResponse(ServiceResult.SUCCESS);
    if (userAccount != null) {
        eventRequest.setUserId(userAccount.getUserId());
        final GoogleAuthenticator gAuth = new GoogleAuthenticator();
        final GoogleAuthenticatorKey gKey = gAuth.createCredentials();
        final UserAccount updateUserAccount = userDAO.load(userAccount.getHjid());
        updateUserAccount.setGoogleAuthKey(gKey.getKey());
        updateUserAccount.setGoogleAuthVerificationCode(gKey.getVerificationCode());
        updateUserAccount.setGoogleAuthScratchCodes(gKey.getScratchCodes());
        userDAO.merge(updateUserAccount);
        final String otpAuthTotpURL = GoogleAuthenticatorQRGenerator.getOtpAuthTotpURL(agencyDAO.getAll().get(0).getAgencyName(), updateUserAccount.getEmail(), gKey);
        response.setOtpAuthTotpURL(otpAuthTotpURL);
        response.setGoogleAuthKey(gKey.getKey());
        response.setGoogleAuthVerificationCode(gKey.getVerificationCode());
        response.setGoogleAuthScratchCodes(gKey.getScratchCodes());
    }
    eventRequest.setApplicationMessage(response.getResult().toString());
    createApplicationEventService.processService(eventRequest);
    return response;
}
Also used : GoogleAuthenticatorKey(com.warrenstrange.googleauth.GoogleAuthenticatorKey) GoogleAuthenticator(com.warrenstrange.googleauth.GoogleAuthenticator) SetGoogleAuthenticatorCredentialResponse(com.hack23.cia.service.api.action.user.SetGoogleAuthenticatorCredentialResponse) CreateApplicationEventRequest(com.hack23.cia.service.api.action.application.CreateApplicationEventRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 42 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class UserHomeApplicationEventsPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout panelContent = createPanelContent();
    final String pageId = getPageId(parameters);
    userHomeMenuItemFactory.createUserHomeMenuBar(menuBar, pageId);
    LabelFactory.createHeader2Label(panelContent, USER_EVENTS);
    final Long userIdFromSecurityContext = UserContextUtil.getUserInternalIdFromSecurityContext();
    if (userIdFromSecurityContext == null) {
        UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
    } else {
        final DataContainer<UserAccount, Long> dataContainer = getApplicationManager().getDataContainer(UserAccount.class);
        final UserAccount userAccount = dataContainer.load(userIdFromSecurityContext);
        final DataContainer<ApplicationActionEvent, Long> eventDataContainer = getApplicationManager().getDataContainer(ApplicationActionEvent.class);
        getGridFactory().createBasicBeanItemGrid(panelContent, ApplicationActionEvent.class, eventDataContainer.findOrderedListByProperty(ApplicationActionEvent_.userId, userAccount.getUserId(), ApplicationActionEvent_.createdDate), APPLICATION_ACTION_EVENT, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, null);
    }
    panel.setCaption(NAME + "::" + USERHOME + USER_EVENTS);
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_USER_HOME_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
    return panelContent;
}
Also used : ApplicationActionEvent(com.hack23.cia.model.internal.application.system.impl.ApplicationActionEvent) VerticalLayout(com.vaadin.ui.VerticalLayout) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 43 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class UserHomeApplicationSessionsPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout panelContent = createPanelContent();
    final String pageId = getPageId(parameters);
    userHomeMenuItemFactory.createUserHomeMenuBar(menuBar, pageId);
    LabelFactory.createHeader2Label(panelContent, USER_VISITS);
    final Long userIdFromSecurityContext = UserContextUtil.getUserInternalIdFromSecurityContext();
    if (userIdFromSecurityContext == null) {
        UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
    } else {
        final DataContainer<UserAccount, Long> dataContainer = getApplicationManager().getDataContainer(UserAccount.class);
        final UserAccount userAccount = dataContainer.load(userIdFromSecurityContext);
        final DataContainer<ApplicationSession, Long> sessionDataContainer = getApplicationManager().getDataContainer(ApplicationSession.class);
        getGridFactory().createBasicBeanItemGrid(panelContent, ApplicationSession.class, sessionDataContainer.findOrderedListByProperty(ApplicationSession_.userId, userAccount.getUserId(), ApplicationSession_.createdDate), APPLICATION_SESSION, COLUMN_ORDER, HIDE_COLUMNS, LISTENER, null, COLLECTION_PROPERTY_CONVERTERS);
    }
    panel.setCaption(NAME + "::" + USERHOME + USER_VISITS);
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_USER_HOME_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
    return panelContent;
}
Also used : ApplicationSession(com.hack23.cia.model.internal.application.system.impl.ApplicationSession) VerticalLayout(com.vaadin.ui.VerticalLayout) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Example 44 with UserAccount

use of com.hack23.cia.model.internal.application.user.impl.UserAccount in project cia by Hack23.

the class UserHomeOverviewPageModContentFactoryImpl method createContent.

@Secured({ "ROLE_USER", "ROLE_ADMIN" })
@Override
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout panelContent = createPanelContent();
    final String pageId = getPageId(parameters);
    userHomeMenuItemFactory.createUserHomeMenuBar(menuBar, pageId);
    LabelFactory.createHeader2Label(panelContent, OVERVIEW);
    final Button logoutButton = new Button(LOGOUT, VaadinIcons.SIGN_OUT);
    final LogoutRequest logoutRequest = new LogoutRequest();
    logoutRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
    logoutButton.addClickListener(new LogoutClickListener(logoutRequest));
    panelContent.addComponent(logoutButton);
    final DataContainer<UserAccount, Long> dataContainer = getApplicationManager().getDataContainer(UserAccount.class);
    final Long userIdFromSecurityContext = UserContextUtil.getUserInternalIdFromSecurityContext();
    if (userIdFromSecurityContext == null) {
        UI.getCurrent().getNavigator().navigateTo(CommonsViews.MAIN_VIEW_NAME);
    } else {
        final UserAccount userAccount = dataContainer.load(userIdFromSecurityContext);
        getFormFactory().addFormPanelTextFields(panelContent, userAccount, UserAccount.class, AS_LIST);
        panelContent.setExpandRatio(logoutButton, ContentRatio.SMALL);
        final VerticalLayout overviewLayout = new VerticalLayout();
        overviewLayout.setSizeFull();
        panelContent.addComponent(overviewLayout);
        panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);
        userHomeMenuItemFactory.createOverviewPage(overviewLayout);
    }
    panel.setCaption(NAME + "::" + USERHOME);
    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_USER_HOME_VIEW, ApplicationEventGroup.USER, NAME, parameters, pageId);
    return panelContent;
}
Also used : LogoutClickListener(com.hack23.cia.web.impl.ui.application.views.pageclicklistener.LogoutClickListener) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) LogoutRequest(com.hack23.cia.service.api.action.application.LogoutRequest) UserAccount(com.hack23.cia.model.internal.application.user.impl.UserAccount) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

UserAccount (com.hack23.cia.model.internal.application.user.impl.UserAccount)37 Test (org.junit.Test)19 Secured (org.springframework.security.access.annotation.Secured)18 CreateApplicationEventRequest (com.hack23.cia.service.api.action.application.CreateApplicationEventRequest)14 RegisterUserResponse (com.hack23.cia.service.api.action.application.RegisterUserResponse)14 CreateApplicationSessionRequest (com.hack23.cia.service.api.action.application.CreateApplicationSessionRequest)13 RegisterUserRequest (com.hack23.cia.service.api.action.application.RegisterUserRequest)13 AbstractServiceFunctionalIntegrationTest (com.hack23.cia.service.impl.AbstractServiceFunctionalIntegrationTest)13 PerfTest (org.databene.contiperf.PerfTest)10 LoginResponse (com.hack23.cia.service.api.action.application.LoginResponse)8 LoginRequest (com.hack23.cia.service.api.action.application.LoginRequest)7 PageModeMenuCommand (com.hack23.cia.web.impl.ui.application.views.common.pagelinks.api.PageModeMenuCommand)7 ManageUserAccountResponse (com.hack23.cia.service.api.action.admin.ManageUserAccountResponse)6 ArrayList (java.util.ArrayList)6 WebDriver (org.openqa.selenium.WebDriver)6 ManageUserAccountRequest (com.hack23.cia.service.api.action.admin.ManageUserAccountRequest)5 Required (org.databene.contiperf.Required)5 LogoutRequest (com.hack23.cia.service.api.action.application.LogoutRequest)4 VerticalLayout (com.vaadin.ui.VerticalLayout)4 WebElement (org.openqa.selenium.WebElement)4