@Test public void testUpdate() { Login login = LoginFactory.createLogin("Jarryd", "Deane"); Login logincopy = new Login.Builder(login.getUserName(), login.getPassword()) .copy(login) .password("12345") .build(); Assert.assertEquals(logincopy.getUserName(), "Jarryd"); Assert.assertEquals(logincopy.getPassword(), "12345"); }
/** * 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; } }
public void validate(Login login, String url) { if (StringUtils.isEmpty(url)) { return; } AuthenticationInfo.Type type = null; if (url.startsWith("ftp")) { type = Type.FTP; } else if (url.startsWith("http")) { type = Type.HTTP; } else { Log.L.info("Unknown Protocoll: " + url); return; } String urlHost = Browser.getHost(url, true); for (AuthenticationInfo info : list) { if (!info.isEnabled()) { continue; } String authHost = info.getHostmask(); if (info.getType().equals(type) && !StringUtils.isEmpty(authHost)) { boolean contains = false; if (authHost.length() > urlHost.length()) { /* hostMask of AuthenticationInfo is longer */ contains = authHost.contains(urlHost); } else { /* hostMask of urlHost is longer */ contains = urlHost.contains(authHost); } if (contains) { if (StringUtils.equals(info.getUsername(), login.getUsername()) && StringUtils.equals(info.getPassword(), login.getPassword())) { info.setLastValidated(System.currentTimeMillis()); } } } } }
@Test public void testCreate() { Login login = LoginFactory.createLogin("Jarryd", "Deane"); Assert.assertEquals(login.getUserName(), "Jarryd"); Assert.assertEquals(login.getPassword(), "Deane"); }