/** * Authenticate a user. * * @param username a username * @param password a plain text password, as entered by the user * * @return a Principal object representing the user if successful, false otherwise */ public Principal authenticate(String username, String password) { if (booleanAuthenticate(username, password)) { return new SimplePrincipal(username); } else { return null; } }
/** * Compares this principal to the specified object. * * @param obj object to compare with. * * @return true if the object passed in is a SimplePrincipal with the same name. */ public boolean equals(Object obj) { if (obj instanceof SimplePrincipal) { return name.equals(((SimplePrincipal)obj).getName()); } return false; }
/** * Test for role membership. * * Use Principal.getName() to get the username from the principal object. * * @param principal Principal object representing a user * @param rolename name of a role to test for membership * * @return true if the user is in the role, false otherwise */ public boolean isUserInRole(Principal principal, String rolename) { String username = null; if (principal != null) { username = principal.getName(); } return isUserInRole(username, rolename); } }
if ((superadminpassword != null) && (superadminpassword.equals(password))) { if (context.isMainWiki()) { principal = new SimplePrincipal(XWikiRightService.SUPERADMIN_USER_FULLNAME); } else { principal = new SimplePrincipal(context.getMainXWiki() + ":" + XWikiRightService.SUPERADMIN_USER_FULLNAME);
/** * Check if a user is in a role. * * @param role name of role to check */ public boolean isUserInRole(String role) { return realm.isUserInRole(getUserPrincipal(), role); }
String username = parseUsername(decoded); String password = parsePassword(decoded); Principal principal = realm.authenticate(username, password); if (principal != null) {
public boolean processLogin(String username, String password, String rememberme, SecurityRequestWrapper request, HttpServletResponse response, XWikiContext context) throws Exception { Principal principal = authenticate(username, password, context); if (principal != null) { // login successful request.getSession().removeAttribute(LOGIN_ATTEMPTS); // make sure the Principal contains wiki name information if (!StringUtils.contains(principal.getName(), ':')) { principal = new SimplePrincipal(context.getDatabase() + ":" + principal.getName()); } request.setUserPrincipal(principal); return false; } else { // login failed // show the basic authentication window again. showLogin(request.getCurrentRequest(), response); return true; } }
if ("*".equals(role) || realm.isUserInRole(principal, role)) { authorized = true;
String username = persistentLoginManager.getRememberedUsername(request, response); String password = persistentLoginManager.getRememberedPassword(request, response); Principal principal = realm.authenticate(username, password); if (principal != null) { request.setUserPrincipal(principal); String username = request.getParameter(FORM_USERNAME); String password = request.getParameter(FORM_PASSWORD); Principal principal = realm.authenticate(username, password); if (principal != null) {
public static Principal checkLogin(SecurityRequestWrapper request, HttpServletResponse response, XWikiContext context) throws Exception { // Always verify authentication String authorizationHeader = request.getHeader("Authorization"); if (authorizationHeader != null) { String decoded = decodeBasicAuthorizationString(authorizationHeader); String username = convertUsername(parseUsername(decoded), context); String password = parsePassword(decoded); Principal principal = authenticate(username, password, context); if (principal != null) { // login successful request.getSession().removeAttribute(LOGIN_ATTEMPTS); // make sure the Principal contains wiki name information if (!StringUtils.contains(principal.getName(), ':')) { principal = new SimplePrincipal(context.getDatabase() + ":" + principal.getName()); } request.setUserPrincipal(principal); return principal; } } return null; }
if (user != null) { if (checkPassword(user, password, context)) { return new SimplePrincipal(virtualXwikiName != null ? context.getDatabase() + ":" + user : user); } else { if (user != null) { if (checkPassword(user, password, context)) { return new SimplePrincipal(context.getDatabase() + ":" + user); } else { context.put("message", "invalidcredentials");
principal = new SimplePrincipal(context.getDatabase() + ":" + principal.getName());
principal = new SimplePrincipal(context.getDatabase() + ":" + principal.getName());
principal = new SimplePrincipal(userProfile.getFullName()); } else { principal = new SimplePrincipal(userProfile.getPrefixedFullName());
principal = new SimplePrincipal(userProfile.getFullName()); } else { principal = new SimplePrincipal(context.getDatabase() + ":" + userProfile.getFullName());