@Override protected void customizeRememberMe(HttpSecurity http) throws Exception { UserDetailsService userDetailsService = lookup("userDetailsService"); PersistentTokenRepository persistentTokenRepository = lookup("persistentTokenRepository"); AbstractRememberMeServices rememberMeServices = lookup("rememberMeServices"); RememberMeAuthenticationFilter rememberMeAuthenticationFilter = lookup("rememberMeAuthenticationFilter"); http.rememberMe() .userDetailsService(userDetailsService) .tokenRepository(persistentTokenRepository) .rememberMeServices(rememberMeServices) .key(rememberMeServices.getKey()) .and() .logout() .logoutUrl(LOGOUT_ENDPOINT) .and() .addFilterAt(rememberMeAuthenticationFilter, RememberMeAuthenticationFilter.class); }
@Override public boolean acceptFilter(ServletRequest request) { if (rememberMeDelegateFilter == null) { return false; } Cookie[] cookies = ((HttpServletRequest) request).getCookies(); if ((cookies == null) || (cookies.length == 0)) { return false; } for (Cookie cookie : cookies) { if (AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY.equals(cookie.getName())) { return true; } } return false; }
@RequestMapping(value = "/signout", method = RequestMethod.GET) public String signOut(HttpServletRequest request, HttpServletResponse response) { new SecurityContextLogoutHandler() .logout(request, response, null); new CookieClearingLogoutHandler(AbstractRememberMeServices.SPRING_SECURITY_REMEMBER_ME_COOKIE_KEY) .logout(request, response, null); return "redirect:/manager/signin"; }
@Autowired public AudienceManagerSecurityProvider(AudienceManagerService audienceManagerService, @Qualifier("authenticationManager") AuthenticationManager authenticationManager, AbstractRememberMeServices rememberMeServices) { this.audienceManagerService = audienceManagerService; this.authenticationManager = authenticationManager; this.rememberMeServices = rememberMeServices; }
/** * 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. */ protected String getRememberMeParameter() { if (getRememberMeServices() instanceof AbstractRememberMeServices) { return ((AbstractRememberMeServices) getRememberMeServices()).getParameter(); } else { return AbstractRememberMeServices.DEFAULT_PARAMETER; } }
@Override public void doSignIn(String username, String password, boolean rememberMe) { try { /* * security.login(username, password); * */ final SecurityContext securityContext = SecurityContextHolder.getContext(); UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password); final Authentication authentication = authenticationManager.authenticate(token); securityContext.setAuthentication(authentication); if (rememberMe) { HttpServletRequest request = httpRequestResponseService.getCurrentRequest(); HttpServletResponse response = httpRequestResponseService.getCurrentResponse(); request.setAttribute(AbstractRememberMeServices.DEFAULT_PARAMETER, rememberMe); rememberMeServices.loginSuccess(request, response, authentication); } getEventBus().publish(EventScope.UI, this, new UserSignedInEvent()); //Redirect to UserHome or Admin Home if (security.hasAuthority("ROLE_USER")) { UI.getCurrent().getNavigator().navigateTo(ViewToken.USER); } else { UI.getCurrent().getNavigator().navigateTo(ViewToken.ADMIN); } } catch (AuthenticationException e) { getView().setErrorMessage(e.getMessage()); } }
public LoginPanel(String string, Form form) { super(string); Label defaultCredentialsLabel = new Label("defaultCredentials", " (default: admin/password)"); try { 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")); } }
public void setRememberService(AbstractRememberMeServices rememberService) { this.rememberService = rememberService; }
public AbstractRememberMeServices getRememberService() { return rememberService; }