List of usage examples for org.springframework.security.web.authentication.rememberme AbstractRememberMeServices DEFAULT_PARAMETER
String DEFAULT_PARAMETER
To view the source code for org.springframework.security.web.authentication.rememberme AbstractRememberMeServices DEFAULT_PARAMETER.
Click Source Link
From source file:org.vaadin.spring.security.shared.DefaultVaadinSharedSecurity.java
/** * Returns the name of the request parameter that enables or disables remember me authentication. If the * {@link #getRememberMeServices() RememberMeServices} extends {@link AbstractRememberMeServices}, * the parameter will be retrieved from there. Otherwise, {@link AbstractRememberMeServices#DEFAULT_PARAMETER} is * returned./*from w w w. j a v a 2s. c o m*/ */ protected String getRememberMeParameter() { if (getRememberMeServices() instanceof AbstractRememberMeServices) { return ((AbstractRememberMeServices) getRememberMeServices()).getParameter(); } else { return AbstractRememberMeServices.DEFAULT_PARAMETER; } }
From source file:org.vaadin.spring.security.GenericVaadinSecurity.java
/** * {@inheritDoc}/*from w w w .j ava 2 s .com*/ */ @Override public void login(Authentication authentication, boolean rememberMe) throws AuthenticationException, Exception { // Ensure SecurityContext is never null SecurityContext context = SecurityContextHolder.getContext(); // Retrieve HttpServletRequest / HttpServletResponse from RequestScope HttpServletRequest request = httpRequestResponseHolder.getCurrentRequest(); HttpServletResponse response = httpRequestResponseHolder.getCurrentResponse(); try { /* * Try to authenticate user */ final Authentication fullyAuthenticated = getAuthenticationManager().authenticate(authentication); /* * Store Authentication within SecurityContext */ context.setAuthentication(fullyAuthenticated); /* * Handle RememberMe */ if (rememberMe) { /* * Locate RememberMeService */ if (rememberMeService != null) { /* * Store RememberMe within HttpServletRequest */ logger.debug("Registering RememberMe in request"); request.setAttribute(AbstractRememberMeServices.DEFAULT_PARAMETER, rememberMe); /* * Signal the RememberMeService of the login */ rememberMeService.loginSuccess(request, response, authentication); } else { logger.error( "RememberMe Request while no <RememberMeServices> found within <ApplicationContext>"); } } /* * Signal the SessionAuthenticationStrategy of the login */ getSessionAuthenticationStrategy().onAuthentication(fullyAuthenticated, request, response); /* * Process AuthenticationSuccessHandler if configured */ if (hasAuthenticationSuccessHandlerConfigured()) { getAuthenticationSuccessHandler().onAuthenticationSuccess(authentication); } } catch (AuthenticationException e) { /** * {@link DisabledException} -> Optional * {@link LockedException} -> Optional * {@link BadCredentialsException} -> Required * * Clear SecurityContext and handler Authentication Failure * If AuthenticationFailureHandler is configured, use it else * throw {@link AuthenticationFailureHandler} */ context = generateNewContext(); /* * Handle RememberMe authentication Failure * No need to check if it is being used; * on failure invalidate all remember-me-tokens. */ if (rememberMeService != null) { rememberMeService.loginFail(request, response); } /* * Process AuthenticationFailureHandler if configured */ if (hasAuthenticationFailureHandlerConfigured()) { getAuthenticationFailureHandler().onAuthenticationFailure(e); } else { throw e; } } finally { /** * Store SecurityContext within the Session for the SecurityFilterChain * On error this will store an emtpy context, which will cause * the security filter chain to invalidate the authentication. * * Context needs to be stored within the HttpSession so the {@link SecurityContextPersistenceFilter} * can make a call to the default configured {@link HttpSessionSecurityContextRepository} */ HttpSession session = httpRequestResponseHolder.getCurrentRequest().getSession(); session.setAttribute(springSecurityContextKey, context); } }
From source file:org.artifactory.webapp.wicket.page.security.login.LoginPanel.java
public LoginPanel(String string, Form form) { super(string); Label defaultCredentialsLabel = new Label("defaultCredentials", " (default: admin/password)"); try {// w w w .ja v a 2 s .c o m UserInfo userInfo = userGroupService.findUser("admin"); defaultCredentialsLabel.setVisible(neverLoggedIn(userInfo) && defaultAdminPassword(userInfo)); } catch (Exception ignored) { defaultCredentialsLabel.setVisible(false); } add(defaultCredentialsLabel); // add username TextField username = new TextField("username"); username.setRequired(true); username.setMarkupId("username"); username.setOutputMarkupId(true); username.add(new AttributeModifier("autocomplete", new AbstractReadOnlyModel<String>() { @Override public String getObject() { return ConstantValues.useUserNameAutoCompleteOnLogin.getString(); } })); add(username); // add password PasswordTextField password = new PasswordTextField("password"); password.setRequired(false); password.setMarkupId("password"); password.setOutputMarkupId(true); add(password); // add login link TitledPageLink ssoLoginLink = new TitledPageLink("ssoLogin", "SSO Login", null) { @Override protected CharSequence getURL() { return addons.addonByType(SamlAddon.class).getSamlLoginIdentityProviderUrl(); } @Override public boolean isEnabled() { return addons.addonByType(SamlAddon.class).isSamlEnabled(); } @Override public boolean isVisible() { return addons.addonByType(SamlAddon.class).isSamlEnabled(); } }; add(ssoLoginLink); // add login link IFormSubmittingComponent loginLink = addons.addonByType(WebApplicationAddon.class).getLoginLink("loginLink", form); addDefaultButton(loginLink); // add remember me checkbox StyledCheckbox checkbox = new StyledCheckbox("rememberMe") { @Override protected String getCheckboxInputName(String defaultName) { // set the parameter name to springs' remember me filter default name return AbstractRememberMeServices.DEFAULT_PARAMETER; } }; checkbox.setSubmitButton((Component) loginLink); checkbox.setOutputMarkupPlaceholderTag(true); checkbox.setVisible(!ConstantValues.securityDisableRememberMe.getBoolean()); add(checkbox); // add cancel link addButton(new TitledPageLink("cancel", "Cancel", ArtifactoryApplication.get().getHomePage())); // add forgot password link if (isMailServerConfigured()) { addButton(new ForgotPasswordLink("forgotPassword")); } }
From source file:org.jtalks.jcommune.web.controller.UserController.java
/** * Activates user account with UUID-based URL * We use UUID's to be sure activation link cannot be generated from username * by script or any other tool.//from ww w . j a v a2 s .com * * @param uuid unique entity identifier * @param request Servlet request. * @param response Servlet response. * @return redirect to the login page * @throws org.jtalks.jcommune.plugin.api.exceptions.UnexpectedErrorException * @throws org.jtalks.jcommune.plugin.api.exceptions.NoConnectionException */ @RequestMapping(value = "user/activate/{uuid}") public String activateAccount(@PathVariable String uuid, HttpServletRequest request, HttpServletResponse response) throws Exception { try { userService.activateAccount(uuid); JCUser user = userService.getByUuid(uuid); MutableHttpRequest wrappedRequest = new MutableHttpRequest(request); wrappedRequest.addParameter(AbstractRememberMeServices.DEFAULT_PARAMETER, "true"); LoginUserDto loginUserDto = new LoginUserDto(user.getUsername(), user.getPassword(), true, getClientIpAddress(request)); retryTemplate .execute(new LoginRetryCallback(loginUserDto, request, response, plainPasswordUserService)); return "redirect:/"; } catch (NotFoundException e) { return "errors/activationExpired"; } catch (UserTriesActivatingAccountAgainException e) { return "redirect:/"; } }