private void loginUserForThisRequest(String username, HttpServletRequest request) { try { UserLogin user = userManager.createTrustedUserLogin(username, true, false); request.setAttribute(UserManager.USER_ATTR_KEY, user); } catch (LicensePolicyException e) { log.error("License problem authenticating request", e); } catch (DbException e) { log.error("Problem authenticating request", e); } }
public void loginUserForThisRequest(String username, HttpServletRequest request) { try { UserLogin user = getUserManager().createTrustedUserLogin(username, true, false); request.setAttribute(UserManager.USER_ATTR_KEY, user); } catch (LicensePolicyException e) { log.error("License problem authenticating request", e); } catch (DbException e) { log.error("Problem authenticating request", e); } } }
private boolean hasPermissionToView(String username, Review review) { Principal userLogin; //if no username was supplied use an anonymous user. if (username == null) { userLogin = Principal.Anonymous.ANON; } else { try { final UserManager um = AppConfig.getsConfig().getUserManager(); userLogin = um.createTrustedUserLogin(username); } catch (DbException e) { log.warn("Invalid user '" + username + "' tried to view review. Access denied."); return false; } catch (LicensePolicyException e) { log.warn("License exception when user '" + username + "' tried to view review. Access denied."); return false; } } return ReviewUtil.principalCanDoReviewAction(userLogin, UserActionManager.ACTION_VIEW, review); } }
private boolean hasPermissionToView(final String username, final RepositoryHandle handle) { final UserManager um = AppConfig.getsConfig().getUserManager(); UserLogin userLogin; if (username == null) { userLogin = null; } else { try { userLogin = um.createTrustedUserLogin(username); } catch (final DbException e) { log.warn("Invalid user '" + username + "' tried to view review. Access denied."); return false; } catch (final LicensePolicyException e) { log.warn("License exception when user '" + username + "' tried to view review. Access denied."); return false; } } return um.hasPermissionToAccess(userLogin, handle); }
private boolean hasPermissionToView(final String username, final RepositoryHandle handle) { final UserManager um = AppConfig.getsConfig().getUserManager(); UserLogin userLogin; if (username == null) { userLogin = null; } else { try { userLogin = um.createTrustedUserLogin(username); } catch (final DbException e) { log.warn("Invalid user '" + username + "' tried to view review. Access denied."); return false; } catch (final LicensePolicyException e) { log.warn("License exception when user '" + username + "' tried to view review. Access denied."); return false; } } return um.hasPermissionToAccess(userLogin, handle); }
private List<Review> getReviews(String searchQuery, String projectKey, String username, int maxHits) { Principal principal; try { if (username == null) { principal = Principal.Anonymous.ANON; } else { UserManager um = AppConfig.getsConfig().getUserManager(); principal = um.createTrustedUserLogin(username); } } catch (DbException e) { log.warn("Error retrieving user '" + username + "'."); return Collections.emptyList(); } catch (LicensePolicyException e) { log.warn("License exception when user '" + username + "' tried to view review. Access denied."); return Collections.emptyList(); } ReviewSearchTerms terms = new ReviewSearchTerms(searchQuery); return reviewManager.searchReviewForTerms(principal, terms.getAllTerms(), "review", null, maxHits, projectKey); }