Example usage for org.apache.wicket.util.cookies CookieDefaults setMaxAge

List of usage examples for org.apache.wicket.util.cookies CookieDefaults setMaxAge

Introduction

In this page you can find the example usage for org.apache.wicket.util.cookies CookieDefaults setMaxAge.

Prototype

public void setMaxAge(int maxAge) 

Source Link

Document

Sets the maximum age of the cookie in seconds.

Usage

From source file:dk.frankbille.scoreboard.security.LoginPage.java

License:Open Source License

private void addLogin() {
    final LoginUser user = new LoginUser();
    final Form<Void> loginForm = new Form<Void>("loginForm") {
        private static final long serialVersionUID = 1L;

        @Override//from   ww w. j  a v  a 2 s  .c  o  m
        protected void onSubmit() {
            if (user.isLoginPersistent()) {
                CookieDefaults settings = new CookieDefaults();
                // 14 days
                settings.setMaxAge(60 * 60 * 24 * 14);
                CookieUtils cookieUtils = new CookieUtils(settings);
                cookieUtils.save("loginUsername", user.getUsername());
                cookieUtils.save("loginPassword", user.getPassword());
            }
            authenticated();
        }
    };
    add(loginForm);

    loginForm.add(new FeedbackPanel("loginMessages", new ContainerFeedbackMessageFilter(loginForm)));

    final TextField<String> usernameField = new TextField<String>("usernameField",
            new PropertyModel<String>(user, "username"));
    loginForm.add(usernameField);

    final PasswordTextField passwordField = new PasswordTextField("passwordField",
            new PropertyModel<String>(user, "password"));
    loginForm.add(passwordField);

    CheckBox persistentField = new CheckBox("persistentField",
            new PropertyModel<Boolean>(user, "loginPersistent"));
    loginForm.add(persistentField);

    loginForm.add(new AbstractFormValidator() {
        private static final long serialVersionUID = 1L;

        @Override
        public FormComponent<?>[] getDependentFormComponents() {
            return new FormComponent<?>[] { usernameField, passwordField };
        }

        @Override
        public void validate(Form<?> form) {
            boolean authenticated = ScoreBoardSession.get().authenticate(usernameField.getInput(),
                    passwordField.getInput());
            if (false == authenticated) {
                error(usernameField, "incorrectUsernamePassword");
            }
        }
    });
}

From source file:dk.teachus.frontend.pages.UnAuthenticatedBasePage.java

License:Apache License

private void signin() {
    TeachUsSession teachUsSession = TeachUsSession.get();

    teachUsSession.signIn(user.getUsername(), user.getPassword());

    if (teachUsSession.isAuthenticated()) {
        if (user.isRemember()) {
            CookieDefaults settings = new CookieDefaults();
            // 14 days
            settings.setMaxAge(60 * 60 * 24 * 14);
            CookieUtils cookieUtils = new CookieUtils(settings);
            cookieUtils.save("username", user.getUsername());
            cookieUtils.save("password", user.getPassword());
        }//from  w  w w  .ja  v  a2s.c o  m

        if (continueToOriginalDestination() == false) {
            throw new RestartResponseAtInterceptPageException(Application.get().getHomePage());
        }
    }
}

From source file:org.apache.syncope.client.console.commons.PreferenceManager.java

License:Apache License

public PreferenceManager() {
    this.mapper = new ObjectMapper();

    CookieDefaults cookieDefaults = new CookieDefaults();
    cookieDefaults.setMaxAge(ONE_YEAR_TIME);
    this.cookieUtils = new CookieUtils(cookieDefaults);
}

From source file:org.sakaiproject.profile2.tool.pages.BasePage.java

License:Educational Community License

/**
 * Set the cookie that stores the current tab index.
 * //from  w w  w. ja v a2 s .com
 * @param tabIndex the current tab index.
 */
protected void setTabCookie(int tabIndex) {

    CookieDefaults defaults = new CookieDefaults();
    defaults.setMaxAge(-1);

    CookieUtils utils = new CookieUtils(defaults);
    utils.save(ProfileConstants.TAB_COOKIE, String.valueOf(tabIndex));
}