@Test public void testAuthenticateWithSuperAdminWithWhiteSpacesWhenSuperAdminPasswordIsTurnedOff() throws Exception { Principal principal = this.authService.authenticate(" " + XWikiRightService.SUPERADMIN_USER + " ", "whatever", this.oldcore.getXWikiContext()); assertNull(principal); }
@Override public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException { if (username == null) { return null; } if (StringUtils.isBlank(username)) { context.put("message", "nousername"); return null; } if (password == null || password.isEmpty()) { context.put("message", "nopassword"); return null; } String cannonicalUsername = username.replaceAll(" ", ""); if (isSuperAdmin(cannonicalUsername)) { return authenticateSuperAdmin(password, context); } if (context != null) { String susername = cannonicalUsername; String virtualXwikiName = null; int i = cannonicalUsername.indexOf("."); int j = cannonicalUsername.indexOf(":"); if (j > 0) { virtualXwikiName = cannonicalUsername.substring(0, j); } if (i != -1) { susername = cannonicalUsername.substring(i + 1); } else if (j > 0) { susername = cannonicalUsername.substring(j + 1); } String db = context.getWikiId(); try { if (virtualXwikiName != null) { context.setWikiId(virtualXwikiName); } try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(virtualXwikiName != null ? context.getWikiId() + ":" + user : user); } } catch (Exception e) { } if (!context.isMainWiki()) { context.setWikiId(context.getMainXWiki()); try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(context.getWikiId() + ":" + user); } } catch (Exception e) { context.put("message", "loginfailed"); return null; } } context.put("message", "invalidcredentials"); return null; } finally { context.setWikiId(db); } } else { LOGGER.error("XWikiContext is null"); return null; } }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { @Override public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException { if (username == null) { return null; } if (StringUtils.isBlank(username)) { context.put("message", "nousername"); return null; } if (password == null || password.isEmpty()) { context.put("message", "nopassword"); return null; } String cannonicalUsername = username.replaceAll(" ", ""); if (isSuperAdmin(cannonicalUsername)) { return authenticateSuperAdmin(password, context); } if (context != null) { String susername = cannonicalUsername; String virtualXwikiName = null; int i = cannonicalUsername.indexOf("."); int j = cannonicalUsername.indexOf(":"); if (j > 0) { virtualXwikiName = cannonicalUsername.substring(0, j); } if (i != -1) { susername = cannonicalUsername.substring(i + 1); } else if (j > 0) { susername = cannonicalUsername.substring(j + 1); } String db = context.getWikiId(); try { if (virtualXwikiName != null) { context.setWikiId(virtualXwikiName); } try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(virtualXwikiName != null ? context.getWikiId() + ":" + user : user); } } catch (Exception e) { } if (!context.isMainWiki()) { context.setWikiId(context.getMainXWiki()); try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(context.getWikiId() + ":" + user); } } catch (Exception e) { context.put("message", "loginfailed"); return null; } } context.put("message", "invalidcredentials"); return null; } finally { context.setWikiId(db); } } else { LOGGER.error("XWikiContext is null"); return null; } } }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { @Override public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException { if (username == null) { return null; } if (StringUtils.isBlank(username)) { context.put("message", "nousername"); return null; } if (password == null || password.isEmpty()) { context.put("message", "nopassword"); return null; } String cannonicalUsername = username.replaceAll(" ", ""); if (isSuperAdmin(cannonicalUsername)) { return authenticateSuperAdmin(password, context); } if (context != null) { String susername = cannonicalUsername; String virtualXwikiName = null; int i = cannonicalUsername.indexOf("."); int j = cannonicalUsername.indexOf(":"); if (j > 0) { virtualXwikiName = cannonicalUsername.substring(0, j); } if (i != -1) { susername = cannonicalUsername.substring(i + 1); } else if (j > 0) { susername = cannonicalUsername.substring(j + 1); } String db = context.getWikiId(); try { if (virtualXwikiName != null) { context.setWikiId(virtualXwikiName); } try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(virtualXwikiName != null ? context.getWikiId() + ":" + user : user); } } catch (Exception e) { } if (!context.isMainWiki()) { context.setWikiId(context.getMainXWiki()); try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(context.getWikiId() + ":" + user); } } catch (Exception e) { context.put("message", "loginfailed"); return null; } } context.put("message", "invalidcredentials"); return null; } finally { context.setWikiId(db); } } else { LOGGER.error("XWikiContext is null"); return null; } }  }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { @Override public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException { if (username == null) { return null; } if (StringUtils.isBlank(username)) { context.put("message", "nousername"); return null; } if (password == null || password.isEmpty()) { context.put("message", "nopassword"); return null; } String cannonicalUsername = username.replaceAll(" ", ""); if (isSuperAdmin(cannonicalUsername)) { return authenticateSuperAdmin(password, context); } if (context != null) { String susername = cannonicalUsername; String virtualXwikiName = null; int i = cannonicalUsername.indexOf("."); int j = cannonicalUsername.indexOf(":"); if (j > 0) { virtualXwikiName = cannonicalUsername.substring(0, j); } if (i != -1) { susername = cannonicalUsername.substring(i + 1); } else if (j > 0) { susername = cannonicalUsername.substring(j + 1); } String db = context.getWikiId(); try { if (virtualXwikiName != null) { context.setWikiId(virtualXwikiName); } try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(virtualXwikiName != null ? context.getWikiId() + ":" + user : user); } } catch (Exception e) { } if (!context.isMainWiki()) { context.setWikiId(context.getMainXWiki()); try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(context.getWikiId() + ":" + user); } } catch (Exception e) { context.put("message", "loginfailed"); return null; } } context.put("message", "invalidcredentials"); return null; } finally { context.setWikiId(db); } } else { LOGGER.error("XWikiContext is null"); return null; } }  @Override XWikiUser checkAuth(XWikiContext context); @Override XWikiUser checkAuth(String username, String password, String rememberme, XWikiContext context); @Override void showLogin(XWikiContext context); @Override Principal authenticate(String username, String password, XWikiContext context); }
XWikiAuthServiceImpl extends AbstractXWikiAuthService { @Override public Principal authenticate(String username, String password, XWikiContext context) throws XWikiException { if (username == null) { return null; } if (StringUtils.isBlank(username)) { context.put("message", "nousername"); return null; } if (password == null || password.isEmpty()) { context.put("message", "nopassword"); return null; } String cannonicalUsername = username.replaceAll(" ", ""); if (isSuperAdmin(cannonicalUsername)) { return authenticateSuperAdmin(password, context); } if (context != null) { String susername = cannonicalUsername; String virtualXwikiName = null; int i = cannonicalUsername.indexOf("."); int j = cannonicalUsername.indexOf(":"); if (j > 0) { virtualXwikiName = cannonicalUsername.substring(0, j); } if (i != -1) { susername = cannonicalUsername.substring(i + 1); } else if (j > 0) { susername = cannonicalUsername.substring(j + 1); } String db = context.getWikiId(); try { if (virtualXwikiName != null) { context.setWikiId(virtualXwikiName); } try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(virtualXwikiName != null ? context.getWikiId() + ":" + user : user); } } catch (Exception e) { } if (!context.isMainWiki()) { context.setWikiId(context.getMainXWiki()); try { String user = findUser(susername, context); if (user != null && checkPassword(user, password, context)) { return new SimplePrincipal(context.getWikiId() + ":" + user); } } catch (Exception e) { context.put("message", "loginfailed"); return null; } } context.put("message", "invalidcredentials"); return null; } finally { context.setWikiId(db); } } else { LOGGER.error("XWikiContext is null"); return null; } }  @Override XWikiUser checkAuth(XWikiContext context); @Override XWikiUser checkAuth(String username, String password, String rememberme, XWikiContext context); @Override void showLogin(XWikiContext context); @Override Principal authenticate(String username, String password, XWikiContext context);  }