diff --git a/.gitignore b/.gitignore index f006d39e3..ec4ccf74d 100644 --- a/.gitignore +++ b/.gitignore @@ -34,6 +34,10 @@ coverage # Compiled binary addons (http://nodejs.org/api/addons.html) build/Release +# Enterprise files +server/main/imports.go +server/enterprise + # Dependency directory # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git node_modules diff --git a/Makefile b/Makefile index bb99d62e5..e5bf85f51 100644 --- a/Makefile +++ b/Makefile @@ -11,6 +11,35 @@ ifeq ($(BUILD_NUMBER),) BUILD_NUMBER := dev endif +BUILD_ENTERPRISE_DIR ?= ../focalboard-enterprise +BUILD_ENTERPRISE ?= true +BUILD_ENTERPRISE_READY = false +BUILD_TYPE_NAME = team +BUILD_HASH_ENTERPRISE = none +ifneq ($(wildcard $(BUILD_ENTERPRISE_DIR)/.),) + ifeq ($(BUILD_ENTERPRISE),true) + BUILD_ENTERPRISE_READY = true + BUILD_TYPE_NAME = enterprise + BUILD_HASH_ENTERPRISE = $(shell cd $(BUILD_ENTERPRISE_DIR) && git rev-parse HEAD) + else + BUILD_ENTERPRISE_READY = false + BUILD_TYPE_NAME = team + endif +else + BUILD_ENTERPRISE_READY = false + BUILD_TYPE_NAME = team +endif + +ifeq ($(BUILD_ENTERPRISE_READY),true) + IGNORE:=$(shell echo Enterprise build selected, preparing) + IGNORE:=$(shell rm -f server/main/imports.go) + IGNORE:=$(shell cp $(BUILD_ENTERPRISE_DIR)/imports/imports.go server/main/) + IGNORE:=$(shell rm -f server/enterprise) + IGNORE:=$(shell ln -s ../$(BUILD_ENTERPRISE_DIR) server/enterprise) +else + IGNORE:=$(shell rm -f server/main/imports.go) +endif + LDFLAGS += -X "github.com/mattermost/focalboard/server/model.BuildNumber=$(BUILD_NUMBER)" LDFLAGS += -X "github.com/mattermost/focalboard/server/model.BuildDate=$(BUILD_DATE)" LDFLAGS += -X "github.com/mattermost/focalboard/server/model.BuildHash=$(BUILD_HASH)" diff --git a/config.json b/config.json index 1dca3d1bb..fe82c84fe 100644 --- a/config.json +++ b/config.json @@ -15,5 +15,9 @@ "session_refresh_time": 18000, "localOnly": false, "enableLocalMode": true, - "localModeSocketLocation": "/var/tmp/focalboard_local.socket" + "localModeSocketLocation": "/var/tmp/focalboard_local.socket", + "authMode": "native", + "mattermostURL": "", + "mattermostClientID": "", + "mattermostClientSecret": "" } diff --git a/server/einterfaces/einterfaces.go b/server/einterfaces/einterfaces.go new file mode 100644 index 000000000..9c45fcbc0 --- /dev/null +++ b/server/einterfaces/einterfaces.go @@ -0,0 +1,25 @@ +package einterfaces + +import ( + "github.com/gorilla/mux" + "github.com/mattermost/focalboard/server/model" +) + +type MattermostAuth interface { + RegisterRoutes(*mux.Router) + DoesUserHaveWorkspaceAccess(session *model.Session, workspaceID string) bool +} + +type MattermostAuthParameters struct { + ServerRoot string + MattermostURL string + ClientID string + ClientSecret string + UseSecureCookie bool +} + +type MattermostAuthStore interface { + GetUserById(userID string) (*model.User, error) + CreateUser(user *model.User) error + CreateSession(session *model.Session) error +} diff --git a/server/go.mod b/server/go.mod index a4fe0238d..678ec9beb 100644 --- a/server/go.mod +++ b/server/go.mod @@ -30,6 +30,7 @@ require ( github.com/tidwall/gjson v1.7.3 // indirect go.uber.org/zap v1.16.0 golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 + golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d golang.org/x/sys v0.0.0-20210324051608-47abb6519492 // indirect google.golang.org/grpc v1.35.0 gopkg.in/asn1-ber.v1 v1.0.0-20181015200546-f715ec2f112d // indirect diff --git a/server/server/enterprise.go b/server/server/enterprise.go new file mode 100644 index 000000000..2b42247fd --- /dev/null +++ b/server/server/enterprise.go @@ -0,0 +1,11 @@ +package server + +import ( + "github.com/mattermost/focalboard/server/einterfaces" +) + +var mattermostAuth func(einterfaces.MattermostAuthParameters, einterfaces.MattermostAuthStore) einterfaces.MattermostAuth + +func RegisterMattermostAuth(f func(einterfaces.MattermostAuthParameters, einterfaces.MattermostAuthStore) einterfaces.MattermostAuth) { + mattermostAuth = f +} diff --git a/server/server/initHandlers.go b/server/server/initHandlers.go index 082b888fa..0c28b1bbf 100644 --- a/server/server/initHandlers.go +++ b/server/server/initHandlers.go @@ -1,5 +1,27 @@ package server +import ( + "log" + + "github.com/mattermost/focalboard/server/einterfaces" +) + func (s *Server) initHandlers() { - // Additional init handlers go here + cfg := s.config + if cfg.AuthMode == "mattermost" && mattermostAuth != nil { + log.Println("Using Mattermost Auth") + params := einterfaces.MattermostAuthParameters{ + ServerRoot: cfg.ServerRoot, + MattermostURL: cfg.MattermostURL, + ClientID: cfg.MattermostClientID, + ClientSecret: cfg.MattermostClientSecret, + UseSecureCookie: cfg.SecureCookie, + } + mmauthHandler := mattermostAuth(params, s.store) + log.Println("CREATING AUTH") + s.webServer.AddRoutes(mmauthHandler) + log.Println("ADDING ROUTES") + s.api.WorkspaceAuthenticator = mmauthHandler + log.Println("SETTING THE AUTHENTICATOR") + } }