Java Code Examples for org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#SPRING_SECURITY_FORM_USERNAME_KEY

The following examples show how to use org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter#SPRING_SECURITY_FORM_USERNAME_KEY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LoginController.java    From airsonic-advanced with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {

    // Auto-login if "user" and "password" parameters are given.
    String username = request.getParameter("user");
    String password = request.getParameter("password");
    if (username != null && password != null) {
        username = StringUtil.urlEncode(username);
        password = StringUtil.urlEncode(password);
        return new ModelAndView(new RedirectView("/login?" +
                UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY + "=" + username +
                "&" + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + "=" + password
        ));
    }

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("logout", request.getParameter("logout") != null);
    map.put("error", request.getParameter("error") != null);
    map.put("brand", settingsService.getBrand());
    map.put("loginMessage", settingsService.getLoginMessage());

    if (securityService.checkDefaultAdminCredsPresent()) {
        map.put("insecure", true);
    }

    return new ModelAndView("login", "model", map);
}
 
Example 2
Source File: LoginController.java    From airsonic with GNU General Public License v3.0 5 votes vote down vote up
@GetMapping
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {

    // Auto-login if "user" and "password" parameters are given.
    String username = request.getParameter("user");
    String password = request.getParameter("password");
    if (username != null && password != null) {
        username = StringUtil.urlEncode(username);
        password = StringUtil.urlEncode(password);
        return new ModelAndView(new RedirectView("/login?" +
                UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_USERNAME_KEY + "=" + username +
                "&" + UsernamePasswordAuthenticationFilter.SPRING_SECURITY_FORM_PASSWORD_KEY + "=" + password
        ));
    }

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("logout", request.getParameter("logout") != null);
    map.put("error", request.getParameter("error") != null);
    map.put("brand", settingsService.getBrand());
    map.put("loginMessage", settingsService.getLoginMessage());

    User admin = securityService.getUserByName("admin");
    if (admin != null) {
        if (admin.getUsername().equals(admin.getPassword())) {
            map.put("insecure", true);
        }
    }

    return new ModelAndView("login", "model", map);
}