public void login() { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); HttpServletRequest request = (HttpServletRequest) externalContext.getRequest(); try { if (StringUtils.isBlank(request.getRemoteUser())) { // request.logout(); request.login(this.username, this.password); } else if (!request.getRemoteUser().equals(this.username)) { request.logout(); request.login(this.username, this.password); } if (originalURL != null && originalURL.indexOf("service.jsf?") > 0) { externalContext.redirect(originalURL); } else { if (UserDAO.isProvider(this.username)) { String recentServiceId = serviceDAO.getProviderRecentServiceId(this.username); if (recentServiceId == null) externalContext.redirect( externalContext.getRequestContextPath() + "/provider/providerappointment.jsf"); else externalContext.redirect( externalContext.getRequestContextPath() + "/provider/serviceappointment.jsf?serviceId=" + recentServiceId); } else { String recentServiceId = serviceDAO.getUserRecentServiceId(this.username); if (recentServiceId == null) externalContext.redirect( externalContext.getRequestContextPath() + "/user/userappointment.jsf"); else externalContext.redirect( externalContext.getRequestContextPath() + "/user/appointment.jsf?serviceId=" + recentServiceId); } } } catch (Exception e) { // log.error(e.getCause(), e); WebUtil.addMessage( new FacesMessage( FacesMessage.SEVERITY_INFO, WebUtil.getMessage("login.failed.header"), WebUtil.getMessage("login.failed.message"))); // context.addMessage(null, new FacesMessage("Login failed.")); } }
@Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { UserLogin userLogin = (UserLogin) JsfUtil.getAttributeFromRequest("userLogin"); String username = userLogin.getUserId().getUserId(); String password = userLogin.getPassword(); boolean remember = "true".equals(request.getParameter("remember")); try { if (request.getUserPrincipal() == null) { request.login(username, password); // Password should already be the hashed variant. } User user = userFacade.findUser(username); if (user != null) { request.getSession().setAttribute("user", user); if (remember) { String uuid = UUID.randomUUID().toString(); userFacade.saveUUID(uuid, user); addCookie(response, COOKIE_NAME, uuid, COOKIE_AGE); } else { userFacade.deleteUUID(user); removeCookie(response, COOKIE_NAME); } } } catch (Exception se) { log.error("Error logging in", se); JsfUtil.addErrorMessage("Error logging in." + se.getMessage()); } }
@RequestMapping(value = "/login", method = RequestMethod.POST) public @ResponseBody ResponseEntity<Map<String, Object>> login( @RequestBody User usr, HttpServletRequest request) { Map<String, Object> map = new HashMap<String, Object>(); HttpStatus status = null; try { request.login(usr.getUsername(), usr.getPassword()); status = HttpStatus.OK; map.put("MESSAGE", "LOG IN SUCCESS"); map.put("STATUS", status); map.put("IS_LOGIN", isAuthenticated()); map.put("ROLE", getRole()); map.put("USERNAME", getUsername()); } catch (Exception e) { // TODO Auto-generated catch block status = HttpStatus.BAD_REQUEST; map.put("MESSAGE", e.getMessage()); map.put("STATUS", status); e.printStackTrace(); return new ResponseEntity<Map<String, Object>>(map, status); } System.out.println(isAuthenticated()); System.out.println(getRole()); System.out.println(getUsername()); return new ResponseEntity<Map<String, Object>>(map, status); }
@RequestMapping(value = "/autologin/user", method = RequestMethod.GET) public @ResponseBody ResponseEntity<Map<String, Object>> autologin1(HttpServletRequest request) { Map<String, Object> map = new HashMap<String, Object>(); HttpStatus status = null; try { request.login("author", "1"); map.put("MESSAGE", "AUTO LOG IN SUCCESS WITH DEFAULT AUTHOR ACCOUNT 'author'"); map.put("STATUS", "200"); map.put("IS_LOGIN", isAuthenticated()); map.put("ROLE", getRole()); map.put("USERNAME", getUsername()); status = HttpStatus.OK; } catch (ServletException e) { // TODO Auto-generated catch block map.put("MESSAGE", e.getMessage()); map.put("IS_LOGIN", isAuthenticated()); map.put("ROLE", getRole()); map.put("USERNAME", getUsername()); status = HttpStatus.BAD_REQUEST; e.printStackTrace(); return new ResponseEntity<Map<String, Object>>(map, status); } System.out.println(isAuthenticated()); System.out.println(getRole()); System.out.println(getUsername()); return new ResponseEntity<Map<String, Object>>(map, status); }
public ReturnStatus login(String Auth, HttpServletRequest req, HttpSession session) { System.out.println("login"); String[] result = decodeToken(Auth); System.out.println("login, result = " + result[0]); if (result[0].equals("OK")) { System.out.println("login : "******" / password = "******"user", req.getRemoteUser()); } catch (ServletException e) { System.out.println("login ServletException"); return new ReturnStatus(false, "login ServletException" + e.getMessage()); } System.out.println("Login OK, remoteuser = "******"login, RequestedSessionId = " + req.getRequestedSessionId()); System.out.println("Login OK"); return new ReturnStatus(true, getroles(result[1])); } else { System.out.println("user niet gevonden (null)"); return new ReturnStatus(false, "user niet gevonden (null)"); } } else { System.out.println("invalid"); return new ReturnStatus(false, result[1]); } }
/** Login method based on <code>HttpServletRequest</code> and security realm */ public String login() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); String result; try { request.login(this.getUsername(), this.getPassword()); JsfUtil.addSuccessMessage(JsfUtil.getStringFromBundle(BUNDLE, "Login_Success")); this.user = ejbFacade.getUserByEmail(getUsername()); this.getAuthenticatedUser(); if (isAdmin()) { result = "/admin/index"; } else { result = "/index"; } } catch (ServletException ex) { Logger.getLogger(UserController.class.getName()).log(Level.SEVERE, null, ex); JsfUtil.addErrorMessage(JsfUtil.getStringFromBundle(BUNDLE, "Login_Failed")); result = "login"; } return result; }
@POST @Path("/login/") @PermitAll public Profile login( @Context HttpServletRequest request, @Context HttpServletResponse response, @FormParam("j_username") String username, @FormParam("j_password") String password) { try { username = userManager.convertToUsernameIfEmailAddress(username); Principal principal = request.getUserPrincipal(); if (principal != null) { logger.warn("Already logged in as:{}", principal); request.logout(); } Response.Status status = userManager.checkPassword( username, password); // FIXME PREVENT DOUBLE CHECK. HERE AND CASSANDRA REALM. if (status == Response.Status.OK) { request.login(username, password); addRememberMeAuthenticationTokenIfNecessary(username, request, response); } else if (status == Response.Status .FORBIDDEN) {; // do not commit to login module or add rememberme cookie (causes auto // login from TrendOceanForwarder). } else { throw new WebApplicationException(status); } return acceptUser(request, username); } catch (ServletException e) { throw new WebApplicationException(Response.Status.UNAUTHORIZED); } }
/** * Fall back to standard basic authentication. Subclasses may implement this method if {@link * HttpServletRequest#login(String, String)} is not sufficient. * * @param username * @param password * @param request * @throws IOException */ protected SimplePrincipal doBasicLogin( String username, String password, HttpServletRequest request) throws IOException { try { request.login(username, password); return NO_PROXY; } catch (Exception e) { return null; } }
/** * Performs authentication * * @return next page */ public String authenticate() { HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { request.login(username, password); Logger.getLogger("LoginTest").log(Level.INFO, "Got username: {0}", username); } catch (Throwable t) { return null; } return NavigationRules.HOME.getRule(); }
public String login() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { request.login(this.username, this.password); } catch (ServletException e) { context.addMessage(null, new FacesMessage("Login failed.")); return null; } return BACK; }
/** * Will log the user into the web site using container managed security * * @return Will take the user to the Welcome page or will return the user back to the log in page * with an error message */ public String login() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { // If the log in is successful.. request.login(currentLogin.getUsername(), currentLogin.getPassword()); return "welcome?faces-redirect=true"; } catch (ServletException e) { // else... displayMessage("Username or password is incorrect!"); return null; } }
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try { // String username = request.getParameter("username"); // String role = request.getParameter("role"); String username = "******"; String role = "student"; Group group = groupManager.getGroup(role); if (group == null) { group = new Group(); group.setName(role); groupManager.saveGroup(group); } User user = userManager.getUser(username); if (user == null) { user = new User(); user.setName(username); user.setPassword(Encryption.digest(DUMMY_PASSWORD, EncryptionType.MD5)); Set<Group> groups = new HashSet<>(); groups.add(group); user.setGroups(groups); userManager.saveUser(user); } request.logout(); StudentInformation newStudent = new StudentInformation(); newStudent.setUserName(username); newStudent.setPassword(Encryption.digest(DUMMY_PASSWORD, EncryptionType.MD5)); HttpSession currentSession = request.getSession(); currentSession.setAttribute("currentUser", newStudent); request.login(username, DUMMY_PASSWORD); String tos = termsOfServiceManager.getTermsOfServiceById(1).getTermsOfService(); currentSession.setAttribute("tos", tos); response.sendRedirect(request.getContextPath()); } catch (ServletException e) { e.printStackTrace(); request.getRequestDispatcher("/WEB-INF/login/login_error.jsp").forward(request, response); } }
@RequestMapping(value = "/autologin/admin", method = RequestMethod.GET) public @ResponseBody ResponseEntity<Map<String, Object>> autologin(HttpServletRequest request) { Map<String, Object> map = new HashMap<String, Object>(); HttpStatus status = null; try { request.login("*****@*****.**", "1"); map.put("MESSAGE", "AUTO LOG IN SUCCESS WITH DEFAULT ADMIN ACCOUNT 'admin'"); map.put("STATUS", "200"); map.put("IS_LOGIN", isAuthenticated()); status = HttpStatus.OK; } catch (ServletException e) { map.put("MESSAGE", e.getMessage()); map.put("IS_LOGIN", isAuthenticated()); status = HttpStatus.BAD_REQUEST; e.printStackTrace(); return new ResponseEntity<Map<String, Object>>(map, status); } return new ResponseEntity<Map<String, Object>>(map, status); }
/** Performs login. */ public void login() { FacesContext context = FacesContext.getCurrentInstance(); HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); try { Principal userPrincipal = request.getUserPrincipal(); if (request.getUserPrincipal() != null) { request.logout(); } request.login(this.username, this.password); userPrincipal = request.getUserPrincipal(); // System.out.println("Prihlasen " + username); this.log.infof("Login: %s -->success", this.username); this.user = this.userManager.getUserByUsername(this.username); JsfUtil.addSuccessMessage("Přihlášení se zdařilo."); } catch (ServletException ex) { JsfUtil.addErrorMessage("Přihlášení se nezdařilo."); System.out.println("Neprihlasen, pokus byl " + this.username + " " + this.password); this.log.infof("Login: %s --> unsuccessful", this.username); } }
public void login() throws IOException { FacesContext context = FacesContext.getCurrentInstance(); ExternalContext externalContext = context.getExternalContext(); HttpServletRequest request = (HttpServletRequest) externalContext.getRequest(); try { System.out.println("Logging in"); System.out.println("UN=" + username); System.out.println("PW=" + password); // request.login(username, appUserService.encodePassword(password)); request.login(username, password); // User user = userService.find(username, password); // externalContext.getSessionMap().put("user", user); refreshUserSessionBean(username); externalContext.redirect(originalURL); } catch (ServletException e) { // Handle unknown username/password in request.login(). LOGGER.error(e); context.addMessage( null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "Unknown login", null)); System.out.println("Unknown login"); } }
@Override public void login(String arg0, String arg1) throws ServletException { request.login(arg0, arg1); }