| | |
| | |
|
| | | import javax.mail.Message;
|
| | | import javax.mail.MessagingException;
|
| | | import javax.mail.internet.MimeBodyPart;
|
| | | import javax.mail.internet.MimeMultipart;
|
| | | import javax.servlet.ServletContext;
|
| | | import javax.servlet.ServletContextEvent;
|
| | | import javax.servlet.ServletContextListener;
|
| | |
| | | * advertise alternative urls for Git client repository access.
|
| | | *
|
| | | * @param repositoryName
|
| | | * @param userName
|
| | | * @return list of non-gitblit clone urls
|
| | | */
|
| | | public List<String> getOtherCloneUrls(String repositoryName) {
|
| | | public List<String> getOtherCloneUrls(String repositoryName, String username) {
|
| | | List<String> cloneUrls = new ArrayList<String>();
|
| | | for (String url : settings.getStrings(Keys.web.otherUrls)) {
|
| | | cloneUrls.add(MessageFormat.format(url, repositoryName));
|
| | | cloneUrls.add(MessageFormat.format(url, repositoryName, username));
|
| | | }
|
| | | return cloneUrls;
|
| | | }
|
| | |
| | | X509Metadata metadata = HttpUtils.getCertificateMetadata(httpRequest);
|
| | | if (user != null) {
|
| | | flagWicketSession(AuthenticationType.CERTIFICATE);
|
| | | logger.info(MessageFormat.format("{0} authenticated by client certificate {1} from {2}",
|
| | | logger.debug(MessageFormat.format("{0} authenticated by client certificate {1} from {2}",
|
| | | user.username, metadata.serialNumber, httpRequest.getRemoteAddr()));
|
| | | return user;
|
| | | } else {
|
| | |
| | | UserModel user = getUserModel(principal.getName());
|
| | | if (user != null) {
|
| | | flagWicketSession(AuthenticationType.CONTAINER);
|
| | | logger.info(MessageFormat.format("{0} authenticated by servlet container principal from {1}",
|
| | | logger.debug(MessageFormat.format("{0} authenticated by servlet container principal from {1}",
|
| | | user.username, httpRequest.getRemoteAddr()));
|
| | | return user;
|
| | | } else {
|
| | |
| | | UserModel user = authenticate(httpRequest.getCookies());
|
| | | if (user != null) {
|
| | | flagWicketSession(AuthenticationType.COOKIE);
|
| | | logger.info(MessageFormat.format("{0} authenticated by cookie from {1}",
|
| | | logger.debug(MessageFormat.format("{0} authenticated by cookie from {1}",
|
| | | user.username, httpRequest.getRemoteAddr()));
|
| | | return user;
|
| | | }
|
| | |
| | | UserModel user = authenticate(username, password);
|
| | | if (user != null) {
|
| | | flagWicketSession(AuthenticationType.CREDENTIALS);
|
| | | logger.info(MessageFormat.format("{0} authenticated by BASIC request header from {1}",
|
| | | logger.debug(MessageFormat.format("{0} authenticated by BASIC request header from {1}",
|
| | | user.username, httpRequest.getRemoteAddr()));
|
| | | return user;
|
| | | } else {
|
| | |
| | | } else {
|
| | | model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory().getParentFile());
|
| | | }
|
| | | if (StringUtils.isEmpty(model.name)) {
|
| | | // Repository is NOT located relative to the base folder because it
|
| | | // is symlinked. Use the provided repository name.
|
| | | model.name = repositoryName;
|
| | | }
|
| | | model.hasCommits = JGitUtils.hasCommits(r);
|
| | | model.lastChange = JGitUtils.getLastChange(r);
|
| | | model.projectPath = StringUtils.getFirstPathElement(repositoryName);
|
| | |
| | | } else {
|
| | | // not caching
|
| | | ProjectModel project = getProjectModel(userProject);
|
| | | if (project == null) {
|
| | | return null;
|
| | | }
|
| | | for (String repository : project.repositories) {
|
| | | if (repository.startsWith(userProject)) {
|
| | | RepositoryModel model = getRepositoryModel(repository);
|
| | |
| | | }
|
| | |
|
| | | // send an email, if possible
|
| | | try {
|
| | | Message message = mailExecutor.createMessageForAdministrators();
|
| | | if (message != null) {
|
| | | message.setSubject("Federation proposal from " + proposal.url);
|
| | | message.setText("Please review the proposal @ " + gitblitUrl + "/proposal/"
|
| | | + proposal.token);
|
| | | mailExecutor.queue(message);
|
| | | }
|
| | | } catch (Throwable t) {
|
| | | logger.error("Failed to notify administrators of proposal", t);
|
| | | }
|
| | | sendMailToAdministrators("Federation proposal from " + proposal.url,
|
| | | "Please review the proposal @ " + gitblitUrl + "/proposal/" + proposal.token);
|
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | * @param message
|
| | | */
|
| | | public void sendMailToAdministrators(String subject, String message) {
|
| | | try {
|
| | | Message mail = mailExecutor.createMessageForAdministrators();
|
| | | if (mail != null) {
|
| | | mail.setSubject(subject);
|
| | | mail.setText(message);
|
| | | mailExecutor.queue(mail);
|
| | | }
|
| | | } catch (MessagingException e) {
|
| | | logger.error("Messaging error", e);
|
| | | }
|
| | | List<String> toAddresses = settings.getStrings(Keys.mail.adminAddresses);
|
| | | sendMail(subject, message, toAddresses);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param toAddresses
|
| | | */
|
| | | public void sendMail(String subject, String message, String... toAddresses) {
|
| | | if (toAddresses == null || toAddresses.length == 0) {
|
| | | logger.debug(MessageFormat.format("Dropping message {0} because there are no recipients", subject));
|
| | | return;
|
| | | }
|
| | | try {
|
| | | Message mail = mailExecutor.createMessage(toAddresses);
|
| | | if (mail != null) {
|
| | | mail.setSubject(subject);
|
| | | mail.setText(message);
|
| | | |
| | | MimeBodyPart messagePart = new MimeBodyPart(); |
| | | messagePart.setText(message, "utf-8");
|
| | | messagePart.setHeader("Content-Type", "text/plain; charset=\"utf-8\"");
|
| | | messagePart.setHeader("Content-Transfer-Encoding", "quoted-printable");
|
| | | |
| | | MimeMultipart multiPart = new MimeMultipart();
|
| | | multiPart.addBodyPart(messagePart);
|
| | | mail.setContent(multiPart);
|
| | | |
| | | mailExecutor.queue(mail);
|
| | | }
|
| | | } catch (MessagingException e) {
|
| | |
| | | * @param toAddresses
|
| | | */
|
| | | public void sendHtmlMail(String subject, String message, String... toAddresses) {
|
| | | if (toAddresses == null || toAddresses.length == 0) {
|
| | | logger.debug(MessageFormat.format("Dropping message {0} because there are no recipients", subject));
|
| | | return;
|
| | | }
|
| | | try {
|
| | | Message mail = mailExecutor.createMessage(toAddresses);
|
| | | if (mail != null) {
|
| | | mail.setSubject(subject);
|
| | | mail.setContent(message, "text/html");
|
| | | |
| | | MimeBodyPart messagePart = new MimeBodyPart(); |
| | | messagePart.setText(message, "utf-8");
|
| | | messagePart.setHeader("Content-Type", "text/html; charset=\"utf-8\"");
|
| | | messagePart.setHeader("Content-Transfer-Encoding", "quoted-printable");
|
| | | |
| | | MimeMultipart multiPart = new MimeMultipart();
|
| | | multiPart.addBodyPart(messagePart);
|
| | | mail.setContent(multiPart);
|
| | |
|
| | | mailExecutor.queue(mail);
|
| | | }
|
| | | } catch (MessagingException e) {
|
| | |
| | | if (!StringUtils.isEmpty(openShift)) {
|
| | | // Gitblit is running in OpenShift/JBoss
|
| | | File base = new File(openShift);
|
| | | logger.info("EXPRESS contextFolder is " + contextFolder.getAbsolutePath());
|
| | |
|
| | | // gitblit.properties setting overrides
|
| | | File overrideFile = new File(base, "gitblit.properties");
|
| | | webxmlSettings.applyOverrides(overrideFile);
|
| | |
|
| | | // Copy the included scripts to the configured groovy folder
|
| | | File localScripts = new File(base, webxmlSettings.getString(Keys.groovy.scriptsFolder, "groovy"));
|
| | | String path = webxmlSettings.getString(Keys.groovy.scriptsFolder, "groovy");
|
| | | File localScripts = com.gitblit.utils.FileUtils.resolveParameter(Constants.baseFolder$, base, path);
|
| | | if (!localScripts.exists()) {
|
| | | File warScripts = new File(contextFolder, "/WEB-INF/data/groovy");
|
| | | if (!warScripts.equals(localScripts)) {
|