Example usage for com.vaadin.server VaadinService getCurrentRequest

List of usage examples for com.vaadin.server VaadinService getCurrentRequest

Introduction

In this page you can find the example usage for com.vaadin.server VaadinService getCurrentRequest.

Prototype

public static VaadinRequest getCurrentRequest() 

Source Link

Document

Gets the currently processed Vaadin request.

Usage

From source file:org.geant.sat.ui.UserShibImpl.java

License:BSD License

/**
 * Get value of attribute/header field./*from   w ww .j  av a 2s .c om*/
 * 
 * @param name
 *            of the field.
 * @return value of the field.
 */
private Object getValue(String name) {
    if (useHeaders) {
        return VaadinService.getCurrentRequest().getHeader(name);
    }
    return VaadinService.getCurrentRequest().getAttribute(name);
}

From source file:org.geant.sat.ui.UserShibImpl.java

License:BSD License

/**
 * Clears user data.//from   w ww .j a v  a2 s  . c  om
 */
private void clearUserData() {
    LOG.debug("Clearing user data");
    attributes.clear();
    VaadinService.getCurrentRequest().getWrappedSession().setAttribute(DETAILS_KEY, null);
    VaadinService.getCurrentRequest().getWrappedSession().setAttribute(PRINCIPAL_KEY, null);
}

From source file:org.geant.sat.ui.UserShibImpl.java

License:BSD License

/**
 * Maps user principal to back-end. Creates user if needed.
 * //from w ww. j ava  2  s .com
 * @param userPrincipal user to map.
 * @return true if user was successfully mapped to sat.
 */
private boolean mapUserToSat(String userPrincipal) {
    LOG.debug("User authenticated, trying to locate the user from back-end.");
    if (userPrincipal == null) {
        LOG.debug("User not authenticated");
        return false;
    }
    UserResponse resp = satApiClient.getUser(userPrincipal);
    if (resp.getErrorMessage() == null) {
        LOG.debug("User found from back-end, setting the user details.");
        // not updating user, just taking as it is
        VaadinService.getCurrentRequest().getWrappedSession().setAttribute(DETAILS_KEY, resp.getUser());
        VaadinService.getCurrentRequest().getWrappedSession().setAttribute(PRINCIPAL_KEY, userPrincipal);
        LOG.debug("details and principal set for  "
                + VaadinService.getCurrentRequest().getWrappedSession().getAttribute(PRINCIPAL_KEY));
        return true;
    }
    LOG.debug("Creating a new user");
    UserDetails details = new UserDetails();
    details.setAttributes(attributes);
    details.setPrincipalId(userPrincipal);
    resp = satApiClient.createUser(details);
    if (resp.getErrorMessage() == null) {
        LOG.debug("User creation succeeded, trying to locate the user from back-end.");
        resp = satApiClient.getUser(userPrincipal);
        if (resp.getErrorMessage() == null) {
            LOG.debug("User found from back-end, setting the user details.");
            // freshly created user
            VaadinService.getCurrentRequest().getWrappedSession().setAttribute(DETAILS_KEY, resp.getUser());
            VaadinService.getCurrentRequest().getWrappedSession().setAttribute(PRINCIPAL_KEY, userPrincipal);
            LOG.debug("details and principal set for  "
                    + VaadinService.getCurrentRequest().getWrappedSession().getAttribute(PRINCIPAL_KEY));
            return true;
        }

    }
    LOG.error("Unable to create user " + resp.getErrorMessage());
    return false;
}

From source file:org.geant.sat.ui.UserShibImpl.java

License:BSD License

@Override
public UserDetails getDetails() {
    if (VaadinService.getCurrentRequest().getWrappedSession().getAttribute(PRINCIPAL_KEY) == null) {
        LOG.debug("User not authenticated, init authentication");
        updateUserInformation();//  w  w w  .  j  a  v  a  2  s  . c  om
    }
    return (UserDetails) VaadinService.getCurrentRequest().getWrappedSession().getAttribute(DETAILS_KEY);
}

From source file:org.ikasan.dashboard.ui.administration.panel.UserDirectoriesPanel.java

License:BSD License

protected void populateAll() {
    final IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
            .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

    List<AuthenticationMethod> authenticationMethods = this.securityService.getAuthenticationMethods();

    this.directoryTable.removeAllItems();

    for (final AuthenticationMethod authenticationMethod : authenticationMethods) {
        this.populateDirectoryTable(authenticationMethod);
    }/*w ww  . j  a v  a2s  .co  m*/
}

From source file:org.ikasan.dashboard.ui.framework.action.LogoutAction.java

License:BSD License

@Override
public void exectuteAction() {
    VaadinService.getCurrentRequest().getWrappedSession().setAttribute(DashboardSessionValueConstants.USER,
            null);//from w ww . j a va  2 s  . co m
    this.visibilityGroup.setVisible();
    this.editableGroup.setEditable(false);

    layout.removeComponent(this.logOutButton);
    layout.addComponent(this.loginButton, 2, 0);
    layout.addComponent(this.setupButton, 3, 0);
    layout.setComponentAlignment(this.setupButton, Alignment.MIDDLE_RIGHT);
    layout.setComponentAlignment(this.loginButton, Alignment.MIDDLE_RIGHT);
    this.layout.removeComponent(userLabel);

    VaadinSession vSession = VaadinSession.getCurrent();
    WrappedSession httpSession = vSession.getSession();

    this.navigationPanel.reset();

    //Invalidate HttpSession
    httpSession.invalidate();
    vSession.close();
    //Redirect the user to the login/default Page
    Page.getCurrent().setLocation("/ikasan-dashboard");
}

From source file:org.ikasan.dashboard.ui.framework.data.LoginFieldGroup.java

License:BSD License

@Override
public void commit() throws CommitException {
    Field<String> username = (Field<String>) this.getField(USERNAME);
    Field<String> password = (Field<String>) this.getField(PASSWORD);

    try {/*from   w  ww.j a v a  2 s. co  m*/
        logger.info("Attempting to validate user: " + username.getValue());

        Authentication authentication = authenticationService.login(username.getValue(), password.getValue());

        logger.info("Loaded authentication: " + authentication);

        VaadinService.getCurrentRequest().getWrappedSession().setAttribute(DashboardSessionValueConstants.USER,
                authentication);

        this.visibilityGroup.setVisible();
    } catch (AuthenticationServiceException e) {
        e.printStackTrace();
        logger.info("User has supplied invalid password: " + username.getValue());
        throw new CommitException("Invalid user name or password. Please try again.");
    }
}

From source file:org.ikasan.dashboard.ui.framework.group.VisibilityGroup.java

License:BSD License

/**
 * Method to set if the components are visible.
 * //w w  w  .j a  va 2  s  .  co m
 * @param visible
 */
public void setVisible() {
    final IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
            .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

    for (Component component : components.keySet()) {
        String policyName = this.components.get(component);

        if (authentication != null && (authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
                || authentication.hasGrantedAuthority(policyName))) {
            component.setVisible(true);
        } else {
            component.setVisible(false);
        }
    }

    for (Table table : refreshableTables) {
        table.refreshRowCache();
    }
}

From source file:org.ikasan.dashboard.ui.framework.group.VisibilityGroup.java

License:BSD License

/**
 * Method to set if the components are visible.
 * /*from  www . j ava2  s  .co  m*/
 * @param visible
 */
public void setVisible(String linkedItemType, Long linkedItemId) {
    final IkasanAuthentication authentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
            .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

    for (Component component : components.keySet()) {
        String policyName = this.components.get(component);

        if (authentication != null
                && (authentication.hasGrantedAuthority(SecurityConstants.ALL_AUTHORITY)
                        || authentication.hasGrantedAuthority(policyName))
                || authentication.canAccessLinkedItem(linkedItemType, linkedItemId)) {
            component.setVisible(true);
        } else {
            component.setVisible(false);
        }
    }

    for (Table table : refreshableTables) {
        table.refreshRowCache();
    }
}

From source file:org.ikasan.dashboard.ui.framework.panel.ProfilePanel.java

License:BSD License

@Override
public void enter(ViewChangeEvent event) {
    List<Role> roles = this.securityService.getAllRoles();

    this.dashboadActivityTable.removeAllItems();

    IkasanAuthentication ikasanAuthentication = (IkasanAuthentication) VaadinService.getCurrentRequest()
            .getWrappedSession().getAttribute(DashboardSessionValueConstants.USER);

    this.user = (User) ikasanAuthentication.getPrincipal();

    usernameField.setValue(user.getUsername());
    firstName.setValue(user.getFirstName());
    surname.setValue(user.getSurname());
    department.setValue(user.getDepartment());
    email.setValue(user.getEmail());//from www.  java  2 s  . c o m

    final IkasanPrincipal principal = securityService.findPrincipalByName(user.getUsername());

    roleTable.removeAllItems();

    for (final Role role : principal.getRoles()) {
        Button deleteButton = new Button();
        deleteButton.setIcon(VaadinIcons.TRASH);
        deleteButton.addStyleName(ValoTheme.BUTTON_ICON_ONLY);
        deleteButton.addStyleName(ValoTheme.BUTTON_BORDERLESS);

        deleteButton.addClickListener(new Button.ClickListener() {
            public void buttonClick(ClickEvent event) {
                roleTable.removeItem(role);

                principal.getRoles().remove(role);

                securityService.savePrincipal(principal);

                dashboadActivityTable.removeItem(principal.getName());
            }
        });

        roleTable.addItem(new Object[] { role.getName() }, role);

        associatedPrincipalsTable.removeAllItems();

        for (IkasanPrincipal ikasanPrincipal : user.getPrincipals()) {
            if (!ikasanPrincipal.getType().equals("user")) {
                associatedPrincipalsTable.addItem(new Object[] { ikasanPrincipal.getName() }, ikasanPrincipal);
            }
        }
    }

    ArrayList<String> subjects = new ArrayList<String>();
    subjects.add(SystemEventConstants.DASHBOARD_LOGIN_CONSTANTS);
    subjects.add(SystemEventConstants.DASHBOARD_LOGOUT_CONSTANTS);
    subjects.add(SystemEventConstants.DASHBOARD_SESSION_EXPIRED_CONSTANTS);

    List<SystemEvent> events = this.systemEventService.listSystemEvents(subjects, user.getUsername(), null,
            null);

    for (SystemEvent systemEvent : events) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");

        String date = dateFormat.format(systemEvent.getTimestamp());

        dashboadActivityTable.addItem(new Object[] { systemEvent.getAction(), date }, systemEvent);
    }

    subjects = new ArrayList<String>();
    subjects.add(SystemEventConstants.DASHBOARD_USER_ROLE_CHANGED_CONSTANTS);

    events = this.systemEventService.listSystemEvents(subjects, user.getUsername(), null, null);

    for (SystemEvent systemEvent : events) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy HH:mm:ss");

        String date = dateFormat.format(systemEvent.getTimestamp());

        this.permissionChangeTable.addItem(new Object[] { systemEvent.getAction(), date }, systemEvent);
    }
}