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

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

Introduction

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

Prototype

CookieDefaults

Source Link

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 w  w w.  jav a 2  s  .co 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  ww  w . ja  va 2s. co  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  ww  w .j  a  v  a 2s.c  o m*/
 * @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));
}

From source file:sf.wicklet.ext.auth.WxSecureAuthenticationStrategy.java

License:Apache License

/**
 * Make sure you always return a valid CookieUtils
 *
 * @return CookieUtils//from www .j  av a2 s. c o m
 */
protected CookieUtils getCookieUtils() {
    if (cookieUtils == null) {
        final CookieDefaults def = new CookieDefaults();
        def.setSecure(secure);
        cookieUtils = new CookieUtils(def);
    }
    return cookieUtils;
}