| | |
| | | import javax.servlet.http.Cookie;
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | |
|
| | | import org.apache.wicket.RequestCycle;
|
| | | import org.apache.wicket.protocol.http.WebResponse;
|
| | | import org.apache.wicket.resource.ContextRelativeResource;
|
| | | import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
|
| | |
| | |
|
| | | import com.gitblit.Constants.AccessPermission;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AuthenticationType;
|
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.Constants.FederationRequest;
|
| | | import com.gitblit.Constants.FederationStrategy;
|
| | |
| | | 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;
|
| | | import com.gitblit.utils.ObjectCache;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.utils.TimeUtils;
|
| | | import com.gitblit.utils.X509Utils.X509Metadata;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | |
|
| | | /**
|
| | |
| | | * @param cookies
|
| | | * @return a user object or null
|
| | | */
|
| | | public UserModel authenticate(Cookie[] cookies) {
|
| | | protected UserModel authenticate(Cookie[] cookies) {
|
| | | if (userService == null) {
|
| | | return null;
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * Authenticate a user based on HTTP request paramters.
|
| | | * This method is inteded to be used as fallback when other
|
| | | * means of authentication are failing (username / password or cookies).
|
| | | * Authenticate a user based on HTTP request parameters.
|
| | | * |
| | | * Authentication by X509Certificate is tried first and then by cookie.
|
| | | * |
| | | * @param httpRequest
|
| | | * @return a user object or null
|
| | | */
|
| | | public UserModel authenticate(HttpServletRequest httpRequest) {
|
| | | // try to authenticate by certificate
|
| | | 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) {
|
| | | // grab real user model and preserve certificate serial number
|
| | | UserModel user = getUserModel(model.username);
|
| | | if (user != null) {
|
| | | RequestCycle requestCycle = RequestCycle.get();
|
| | | if (requestCycle != null) {
|
| | | // flag the Wicket session, if this is a Wicket request
|
| | | GitBlitWebSession session = GitBlitWebSession.get();
|
| | | session.authenticationType = AuthenticationType.CERTIFICATE;
|
| | | }
|
| | | X509Metadata metadata = HttpUtils.getCertificateMetadata(httpRequest);
|
| | | logger.info(MessageFormat.format("{0} authenticated by client certificate {1} from {2}",
|
| | | user.username, metadata.serialNumber, httpRequest.getRemoteAddr()));
|
| | | return user;
|
| | | }
|
| | | }
|
| | | |
| | | // try to authenticate by cookie
|
| | | Cookie[] cookies = httpRequest.getCookies();
|
| | | if (allowCookieAuthentication() && cookies != null && cookies.length > 0) {
|
| | | // Grab cookie from Browser Session
|
| | | UserModel user = authenticate(cookies);
|
| | | if (user != null) {
|
| | | RequestCycle requestCycle = RequestCycle.get();
|
| | | if (requestCycle != null) {
|
| | | // flag the Wicket session, if this is a Wicket request
|
| | | GitBlitWebSession session = GitBlitWebSession.get();
|
| | | session.authenticationType = AuthenticationType.COOKIE;
|
| | | }
|
| | | logger.info(MessageFormat.format("{0} authenticated by cookie from {1}",
|
| | | user.username, httpRequest.getRemoteAddr()));
|
| | | return user;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 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());
|
| | |
|