| | |
| | | import com.gitblit.Constants.FederationStrategy;
|
| | | import com.gitblit.Constants.FederationToken;
|
| | | import com.gitblit.Constants.PermissionType;
|
| | | import com.gitblit.Constants.RegistrantType;
|
| | | import com.gitblit.models.FederationModel;
|
| | | import com.gitblit.models.FederationProposal;
|
| | | import com.gitblit.models.FederationSet;
|
| | |
| | | import com.gitblit.utils.ContainerUtils;
|
| | | import com.gitblit.utils.DeepCopier;
|
| | | import com.gitblit.utils.FederationUtils;
|
| | | import com.gitblit.utils.HttpUtils;
|
| | | import com.gitblit.utils.JGitUtils;
|
| | | import com.gitblit.utils.JsonUtils;
|
| | | import com.gitblit.utils.MetricUtils;
|
| | |
| | | * @return a user object or null
|
| | | */
|
| | | public UserModel authenticate(HttpServletRequest httpRequest) {
|
| | | boolean checkValidity = settings.getBoolean(Keys.git.enforceCertificateValidity, true);
|
| | | String [] oids = getStrings(Keys.git.certificateUsernameOIDs).toArray(new String[0]);
|
| | | UserModel model = HttpUtils.getUserModelFromCertificate(httpRequest, checkValidity, oids);
|
| | | if (model != null) {
|
| | | UserModel user = GitBlit.self().getUserModel(model.username);
|
| | | logger.info(MessageFormat.format("{0} authenticated by client certificate from {1}",
|
| | | user.username, httpRequest.getRemoteAddr()));
|
| | | return user;
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
| | | * @return a user object or null
|
| | | */
|
| | | public UserModel getUserModel(String username) {
|
| | | UserModel user = userService.getUserModel(username);
|
| | | UserModel user = userService.getUserModel(username); |
| | | return user;
|
| | | }
|
| | | |
| | | /**
|
| | | * Returns the effective list of permissions for this user, taking into account
|
| | | * team memberships, ownerships.
|
| | | * |
| | | * @param user
|
| | | * @return the effective list of permissions for the user
|
| | | */
|
| | | public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
|
| | | Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>();
|
| | | set.addAll(user.getRepositoryPermissions());
|
| | | // Flag missing repositories
|
| | | for (RegistrantAccessPermission permission : set) {
|
| | | if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
|
| | | RepositoryModel rm = GitBlit.self().getRepositoryModel(permission.registrant);
|
| | | if (rm == null) {
|
| | | permission.permissionType = PermissionType.MISSING;
|
| | | permission.mutable = false;
|
| | | continue;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // TODO reconsider ownership as a user property
|
| | | // manually specify personal repository ownerships
|
| | | for (RepositoryModel rm : repositoryListCache.values()) {
|
| | | if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
|
| | | RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND,
|
| | | PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
|
| | | // user may be owner of a repository to which they've inherited
|
| | | // a team permission, replace any existing perm with owner perm
|
| | | set.remove(rp);
|
| | | set.add(rp);
|
| | | }
|
| | | }
|
| | | |
| | | List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(set);
|
| | | Collections.sort(list);
|
| | | return list;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @return a list of RegistrantAccessPermissions
|
| | | */
|
| | | public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {
|
| | | List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(); |
| | | List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
|
| | | if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
|
| | | // no permissions needed, REWIND for everyone!
|
| | | return list;
|
| | | }
|
| | | if (AuthorizationControl.AUTHENTICATED.equals(repository.authorizationControl)) {
|
| | | // no permissions needed, REWIND for authenticated!
|
| | | return list;
|
| | | }
|
| | | // NAMED users and teams
|
| | | for (UserModel user : userService.getAllUsers()) {
|
| | | RegistrantAccessPermission ap = user.getRepositoryPermission(repository);
|
| | | if (ap.permission.exceeds(AccessPermission.NONE)) {
|
| | |
| | | public boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {
|
| | | List<UserModel> users = new ArrayList<UserModel>();
|
| | | for (RegistrantAccessPermission up : permissions) {
|
| | | if (up.isEditable) {
|
| | | if (up.mutable) {
|
| | | // only set editable defined permissions
|
| | | UserModel user = userService.getUserModel(up.registrant);
|
| | | user.setRepositoryPermission(repository.name, up.permission);
|
| | |
| | | public boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {
|
| | | List<TeamModel> teams = new ArrayList<TeamModel>();
|
| | | for (RegistrantAccessPermission tp : permissions) {
|
| | | if (tp.isEditable) {
|
| | | if (tp.mutable) {
|
| | | // only set explicitly defined access permissions
|
| | | TeamModel team = userService.getTeamModel(tp.registrant);
|
| | | team.setRepositoryPermission(repository.name, tp.permission);
|
| | |
| | | case PULL_SETTINGS:
|
| | | case PULL_SCRIPTS:
|
| | | return token.equals(all);
|
| | | default:
|
| | | break;
|
| | | }
|
| | | return false;
|
| | | }
|
| | |
| | | if (!StringUtils.isEmpty(model.origin)) {
|
| | | url = model.origin;
|
| | | }
|
| | | break;
|
| | | default:
|
| | | break;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Notify users by email of something.
|
| | | * |
| | | * @param subject
|
| | | * @param message
|
| | | * @param toAddresses
|
| | | */
|
| | | public void sendHtmlMail(String subject, String message, Collection<String> toAddresses) {
|
| | | this.sendHtmlMail(subject, message, toAddresses.toArray(new String[0]));
|
| | | }
|
| | |
|
| | | /**
|
| | | * Notify users by email of something.
|
| | | * |
| | | * @param subject
|
| | | * @param message
|
| | | * @param toAddresses
|
| | | */
|
| | | public void sendHtmlMail(String subject, String message, String... toAddresses) {
|
| | | try {
|
| | | Message mail = mailExecutor.createMessage(toAddresses);
|
| | | if (mail != null) {
|
| | | mail.setSubject(subject);
|
| | | mail.setContent(message, "text/html");
|
| | | mailExecutor.queue(mail);
|
| | | }
|
| | | } catch (MessagingException e) {
|
| | | logger.error("Messaging error", e);
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the descriptions/comments of the Gitblit config settings.
|
| | | *
|
| | | * @return SettingsModel
|
| | |
| | | public void configureContext(IStoredSettings settings, boolean startFederation) {
|
| | | logger.info("Reading configuration from " + settings.toString());
|
| | | this.settings = settings;
|
| | | |
| | |
|
| | | repositoriesFolder = getRepositoriesFolder();
|
| | | logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());
|
| | |
|
| | | // prepare service executors
|
| | | mailExecutor = new MailExecutor(settings);
|
| | | luceneExecutor = new LuceneExecutor(settings, repositoriesFolder);
|
| | | gcExecutor = new GCExecutor(settings);
|
| | |
|
| | | repositoriesFolder = getRepositoriesFolder();
|
| | | logger.info("Git repositories folder " + repositoriesFolder.getAbsolutePath());
|
| | |
|
| | | // calculate repository list settings checksum for future config changes
|
| | | repositoryListSettingsChecksum.set(getRepositoryListSettingsChecksum());
|
| | |
|