diff --git a/.gitignore b/.gitignore
index 38f92c2ee2bfd3265f5a3051a4210d5d48368e62..1dcbc1b245a61925f2a7879ea2e89510e6faaf92 100644
--- a/.gitignore
+++ b/.gitignore
@@ -122,4 +122,7 @@ doxygen
 
 #GO
 broker/pkg
-discovery/pkg
\ No newline at end of file
+discovery/pkg
+common/go/pkg
+authorizer/pkg
+
diff --git a/authorizer/src/asapo_authorizer/server/authorize.go b/authorizer/src/asapo_authorizer/server/authorize.go
index ad5cb4326308ef6205aa9d8b4c644b078b02ae78..334cc21b117055b0dfe7565a51f3917c186b98b6 100644
--- a/authorizer/src/asapo_authorizer/server/authorize.go
+++ b/authorizer/src/asapo_authorizer/server/authorize.go
@@ -3,6 +3,11 @@ package server
 import (
 	"net/http"
 	"encoding/json"
+	"asapo_common/utils"
+	"path/filepath"
+	"strings"
+	log "asapo_common/logger"
+	"github.com/pkg/errors"
 )
 
 type authorizationRequest struct {
@@ -10,32 +15,98 @@ type authorizationRequest struct {
 	OriginHost string
 }
 
-func extractRequest(r *http.Request)(request authorizationRequest,err error) {
+func extractRequest(r *http.Request) (request authorizationRequest, err error) {
 	decoder := json.NewDecoder(r.Body)
 	err = decoder.Decode(&request)
 	return
 }
 
-func authorize(request authorizationRequest) bool {
-	// todo: implement real check
-	if (request.BeamtimeId != "asapo_test") {
+func splitHost(hostPort string) string {
+	s := strings.Split(hostPort, ":")
+	return s[0]
+}
+
+func getBeamlineFromIP(ip string) (string, error) {
+	host := splitHost(ip)
+	lines, err := utils.ReadStringsFromFile(settings.IpBeamlineMappingFolder + string(filepath.Separator) + host)
+	if err != nil {
+		return "", err
+	}
+
+	if len(lines) < 1 || len(lines[0]) == 0 {
+		return "", errors.New("file is empty")
+	}
+
+	return lines[0], nil
+}
+
+func checkBeamtimeExistsInStrings(info beamtimeInfo, lines []string) bool {
+	for _, line := range lines {
+		words := strings.Fields(line)
+		if len(words) < 3 {
+			continue
+		}
+		if words[1] == info.Beamline && words[2] == info.BeamtimeId {
+			return true
+		}
+	}
+	return false
+}
+
+func beamtimeExists(info beamtimeInfo) bool {
+	lines, err := utils.ReadStringsFromFile(settings.BeamtimeBeamlineMappingFile)
+
+	if err != nil || len(lines) < 3 {
 		return false
 	}
+	lines = lines[2:]
+	return checkBeamtimeExistsInStrings(info, lines)
+}
+
+func authorize(request authorizationRequest) (bool, beamtimeInfo) {
+	for _, pair := range settings.AlwaysAllowedBeamtimes {
+		if pair.BeamtimeId == request.BeamtimeId {
+			return true, pair
+		}
+	}
+	var answer beamtimeInfo
+
+	beamline, err := getBeamlineFromIP(request.OriginHost)
+	if err != nil {
+		log.Error("cannot find beamline for " + request.OriginHost + " - " + err.Error())
+		return false, beamtimeInfo{}
+	}
+
+	answer.Beamline = beamline
+	answer.BeamtimeId = request.BeamtimeId
+	if (!beamtimeExists(answer)) {
+		log.Error("cannot authorize beamtime " + answer.BeamtimeId + " for " + request.OriginHost + " in " + answer.Beamline)
+		return false, beamtimeInfo{}
+	}
+	log.Debug("authorized beamtime " + answer.BeamtimeId + " for " + request.OriginHost + " in " + answer.Beamline)
+
+	return true, answer
 
-	return true
 }
 
 func routeAuthorize(w http.ResponseWriter, r *http.Request) {
-	request,err := extractRequest(r)
+	request, err := extractRequest(r)
 	if err != nil {
 		w.WriteHeader(http.StatusBadRequest)
 		return
 	}
-	if (!authorize(request)) {
+	ok, beamtimeInfo := authorize(request)
+	if (!ok) {
 		w.WriteHeader(http.StatusUnauthorized)
 		return
 	}
 
+	res, err := utils.MapToJson(&beamtimeInfo)
+	if err != nil {
+		w.WriteHeader(http.StatusInternalServerError)
+		return
+
+	}
 	w.WriteHeader(http.StatusOK)
-	w.Write([]byte(request.BeamtimeId))
+	w.Write([]byte(res))
 }
diff --git a/authorizer/src/asapo_authorizer/server/authorize_test.go b/authorizer/src/asapo_authorizer/server/authorize_test.go
index 81e1df983406e5a820ba5d74d3417d6efb8154e2..1c1b39b34d524afc951e03fbdd71d981bceba919 100644
--- a/authorizer/src/asapo_authorizer/server/authorize_test.go
+++ b/authorizer/src/asapo_authorizer/server/authorize_test.go
@@ -8,6 +8,7 @@ import (
 	"strings"
 	"testing"
 	"io/ioutil"
+	"os"
 )
 
 type request struct {
@@ -17,6 +18,11 @@ type request struct {
 	message string
 }
 
+func allowBeamlines(beamlines []beamtimeInfo) {
+	settings.AlwaysAllowedBeamtimes=beamlines
+}
+
+
 func containsMatcher(substr string) func(str string) bool {
 	return func(str string) bool { return strings.Contains(str, substr) }
 }
@@ -35,12 +41,14 @@ func doAuthorizeRequest(path string,buf string) *httptest.ResponseRecorder {
 }
 
 func TestAuthorizeOK(t *testing.T) {
+	allowBeamlines([]beamtimeInfo{{"asapo_test","beamline"}})
 	request :=  makeRequest(authorizationRequest{"asapo_test","host"})
 	w := doAuthorizeRequest("/authorize",request)
 
 	body, _ := ioutil.ReadAll(w.Body)
 
-	assert.Equal(t, string(body), "asapo_test", "")
+	assert.Contains(t, string(body), "asapo_test", "")
+	assert.Contains(t, string(body), "beamline", "")
 	assert.Equal(t, http.StatusOK, w.Code, "")
 }
 
@@ -62,5 +70,93 @@ func TestAuthorizeWrongPath(t *testing.T) {
 	assert.Equal(t, http.StatusNotFound, w.Code, "")
 }
 
+func TestAlwaysAuthorizeAllowed(t *testing.T) {
+	allowBeamlines([]beamtimeInfo{{"test","beamline"}})
+	request :=  authorizationRequest{"asapo_test","host"}
+	ok,_ := authorize(request)
+	assert.Equal(t,false, ok, "")
+}
+
+func TestSplitHost(t *testing.T) {
+	host := splitHost("127.0.0.1:112")
+	assert.Equal(t,"127.0.0.1", host, "")
+}
+
+
+func TestSplitHostNoPort(t *testing.T) {
+	host := splitHost("127.0.0.1")
+	assert.Equal(t,"127.0.0.1", host, "")
+}
+
+func TestGetBeamlineFromIP(t *testing.T) {
+	beamline, err := getBeamlineFromIP("127.0.0.1:112")
+	assert.NotNil(t,err, "")
+	assert.Empty(t,beamline, "")
+
+}
+func TestCheckBeamtimeExistsInStringsFalse(t *testing.T) {
+	beamInfo := beamtimeInfo{"123","bl"}
+	lines:=[]string{"111","flash	pg2	11003932		beamtime	start: 2018-06-11","petra3	p01	c20180508-000-COM20181	commissioning"}
+	ok := checkBeamtimeExistsInStrings(beamInfo,lines)
+	assert.False(t,ok, "")
+}
+
+
+func TestCheckBeamtimeExistsInStringsOk(t *testing.T) {
+	beamInfo := beamtimeInfo{"11003932","pg2"}
+	lines:=[]string{"111","flash	pg2	11003932		beamtime	start: 2018-06-11","petra3	p01	c20180508-000-COM20181	commissioning"}
+	ok := checkBeamtimeExistsInStrings(beamInfo,lines)
+	assert.True(t,ok, "")
+}
+
+func TestAuthorizeWithFile(t *testing.T) {
+	settings.IpBeamlineMappingFolder="."
+	settings.BeamtimeBeamlineMappingFile="file.tmp"
+
+	lines :=`
+Open beam times as of  Thursday, 2018/06/21 11:32
+Faclty	BL	BeamTime Id		kind
+flash	bl1	11003924		beamtime	start: 2018-04-24
+flash	bl2	11003921		beamtime	start: 2018-06-08
+flash	fl24	11001734		beamtime	start: 2018-06-13
+flash	pg2	11003932		beamtime	start: 2018-06-11
+flash	thz	11005667		beamtime	start: 2018-05-24
+petra3	ext	50000181		beamtime	start: 2017-04-12
+petra3	ext	50000193		beamtime	start: 2017-10-12
+petra3	ext	50000202		beamtime	start: 2017-12-06
+petra3	ext	50000209		beamtime	start: 2018-02-19
+petra3	ext	50000211		beamtime	start: 2018-02-19
+petra3	ext	50000214		beamtime	start: 2018-04-23
+petra3	ext	50000215		beamtime	start: 2018-03-23
+petra3	ext	50000216		beamtime	start: 2018-03-23
+petra3	ext	50000217		beamtime	start: 2018-03-23
+petra3	ext	50000218		beamtime	start: 2018-03-23
+petra3	ext	50000219		beamtime	start: 2018-04-24
+petra3	ext	50000221		beamtime	start: 2018-06-14
+petra3	p01	11004172		beamtime	start: 2018-06-20
+petra3	p01	c20180508-000-COM20181	commissioning
+petra3	p02.1	11004341		beamtime	start: 2018-06-18
+`
+
+	ioutil.WriteFile("file.tmp", []byte(lines), 0644)
+	ioutil.WriteFile("127.0.0.1", []byte("bl1"), 0644)
+
+
+	request := authorizationRequest{"11003924","127.0.0.1"}
+	w := doAuthorizeRequest("/authorize",makeRequest(request))
+
+	body, _ := ioutil.ReadAll(w.Body)
+	assert.Contains(t, string(body), request.BeamtimeId, "")
+	assert.Contains(t, string(body), "bl1", "")
+	assert.Equal(t, http.StatusOK, w.Code, "")
+
+	request = authorizationRequest{"wrong","127.0.0.1"}
+	w = doAuthorizeRequest("/authorize",makeRequest(request))
+	assert.Equal(t, http.StatusUnauthorized, w.Code, "")
+
+	os.Remove("127.0.0.1")
+	os.Remove("file.tmp")
+
+}
 
 
diff --git a/authorizer/src/asapo_authorizer/server/server.go b/authorizer/src/asapo_authorizer/server/server.go
index 088339d07a4c83456087bb9ebfbcd0c98bf9cefa..4215eecec92af09406642566126b4ca964893e22 100644
--- a/authorizer/src/asapo_authorizer/server/server.go
+++ b/authorizer/src/asapo_authorizer/server/server.go
@@ -1,9 +1,17 @@
 package server
 
 
+type  beamtimeInfo struct {
+	BeamtimeId string
+	Beamline string
+}
+
 type serverSettings struct {
 	Port             int
 	LogLevel         string
+	IpBeamlineMappingFolder string
+	BeamtimeBeamlineMappingFile string
+	AlwaysAllowedBeamtimes []beamtimeInfo
 }
 
 var settings serverSettings
diff --git a/common/go/src/asapo_common/utils/helpers.go b/common/go/src/asapo_common/utils/helpers.go
index f1d0da4dc985d0231cbe34602f1942ce01fde362..9f02ac4263ae8f69f0839bb3c204f2374bce4415 100644
--- a/common/go/src/asapo_common/utils/helpers.go
+++ b/common/go/src/asapo_common/utils/helpers.go
@@ -3,6 +3,7 @@ package utils
 import (
 	json "encoding/json"
 	"io/ioutil"
+	"strings"
 )
 
 func StringInSlice(a string, list []string) bool {
@@ -36,3 +37,14 @@ func ReadJsonFromFile(fname string, config interface{}) error {
 
 	return nil
 }
+
+
+func ReadStringsFromFile(fname string) ([]string, error) {
+	content, err := ioutil.ReadFile(fname)
+	if err != nil {
+		return []string{},err
+	}
+	lines := strings.Split(string(content), "\n")
+
+	return lines,nil
+}
\ No newline at end of file
diff --git a/receiver/src/request.cpp b/receiver/src/request.cpp
index d8ebd140aafa0588a849d4edb5f45558c6081f64..8c10e991f71b4590f3c700ce4b31bf92dd50c4b5 100644
--- a/receiver/src/request.cpp
+++ b/receiver/src/request.cpp
@@ -95,6 +95,14 @@ const char* Request::GetMessage() const {
     return request_header_.message;
 }
 
+void Request::SetBeamline(std::string beamline) {
+    beamline_ = std::move(beamline);
+}
+
+const std::string& Request::GetBeamline() const {
+    return beamline_;
+}
+
 std::unique_ptr<Request> RequestFactory::GenerateRequest(const GenericRequestHeader&
         request_header, SocketDescriptor socket_fd, std::string origin_uri,
         Error* err) const noexcept {
diff --git a/receiver/src/request.h b/receiver/src/request.h
index ecacb9bcd3e6de21dbc304c419f5f17693754d6e..b9350a9b6226bbf468031ccc614589d8fc12646e 100644
--- a/receiver/src/request.h
+++ b/receiver/src/request.h
@@ -35,6 +35,8 @@ class Request {
     const std::string& GetOriginUri() const;
     VIRTUAL const std::string& GetBeamtimeId() const;
     VIRTUAL void SetBeamtimeId(std::string beamtime_id);
+    VIRTUAL void SetBeamline(std::string beamline);
+    VIRTUAL const std::string& GetBeamline() const;
     std::unique_ptr<IO> io__;
   private:
     Error AllocateDataBuffer();
@@ -45,6 +47,7 @@ class Request {
     RequestHandlerList handlers_;
     std::string origin_uri_;
     std::string beamtime_id_;
+    std::string beamline_;
 };
 
 class RequestFactory {
diff --git a/receiver/src/request_handler_authorize.cpp b/receiver/src/request_handler_authorize.cpp
index 7b2be86d315370b3f5110a08eddb5cf75f29d0c6..597584601c01f0646920239b85a55574c2418418 100644
--- a/receiver/src/request_handler_authorize.cpp
+++ b/receiver/src/request_handler_authorize.cpp
@@ -3,6 +3,7 @@
 #include "receiver_logger.h"
 #include "request.h"
 
+#include "json_parser/json_parser.h"
 
 using std::chrono::high_resolution_clock;
 
@@ -41,7 +42,14 @@ Error RequestHandlerAuthorize::Authorize(Request* request, const char* beamtime_
     }
 
     last_updated_ = high_resolution_clock::now();
-    beamtime_id_ = response;
+
+    JsonStringParser parser{response};
+    (err = parser.GetString("BeamtimeId", &beamtime_id_)) ||
+    (err = parser.GetString("Beamline", &beamline_));
+    if (err) {
+        return ErrorFromServerResponse(err, code);
+    }
+
     return nullptr;
 }
 
@@ -71,6 +79,7 @@ Error RequestHandlerAuthorize::ProcessOtherRequest(Request* request) const {
         }
     }
     request->SetBeamtimeId(beamtime_id_);
+    request->SetBeamline(beamline_);
     return nullptr;
 }
 
diff --git a/receiver/src/request_handler_authorize.h b/receiver/src/request_handler_authorize.h
index ee21db88049d9364604eb0a7796910242f9c35c2..59069240cbe2988e48bed21c7d78672f75aa62f2 100644
--- a/receiver/src/request_handler_authorize.h
+++ b/receiver/src/request_handler_authorize.h
@@ -21,6 +21,7 @@ class RequestHandlerAuthorize final: public RequestHandler {
     std::unique_ptr<HttpClient>http_client__;
   private:
     mutable std::string beamtime_id_;
+    mutable std::string beamline_;
     mutable std::chrono::high_resolution_clock::time_point last_updated_;
     Error ProcessAuthorizationRequest(Request* request) const;
     Error ProcessOtherRequest(Request* request) const;
diff --git a/receiver/src/request_handler_file_write.cpp b/receiver/src/request_handler_file_write.cpp
index 1702fc1618f6d03d277b4352fc00aee2b38b1e38..552393f76dbb4ad0cec55feb6435f163614a9c5e 100644
--- a/receiver/src/request_handler_file_write.cpp
+++ b/receiver/src/request_handler_file_write.cpp
@@ -16,7 +16,9 @@ Error RequestHandlerFileWrite::ProcessRequest(Request* request) const {
     const FileData& data = request->GetData();
 
     auto fname = request->GetFileName();
-    auto root_folder = GetReceiverConfig()->root_folder + kPathSeparator + request->GetBeamtimeId() + kPathSeparator;
+    auto root_folder = GetReceiverConfig()->root_folder + kPathSeparator
+                       + request->GetBeamline() + kPathSeparator
+                       + request->GetBeamtimeId() + kPathSeparator;
     auto err =  io__->WriteDataToFile(root_folder + fname, data, fsize);
     if (!err) {
         log__->Debug("saved file of size " + std::to_string(fsize) + " to " + root_folder + fname);
diff --git a/receiver/unittests/receiver_mocking.h b/receiver/unittests/receiver_mocking.h
index 6187243e842bc8852413fa562850f410bdda9505..6881a0b51428d83b4a4fa2ccf9ce2e7edd522334 100644
--- a/receiver/unittests/receiver_mocking.h
+++ b/receiver/unittests/receiver_mocking.h
@@ -53,9 +53,11 @@ class MockRequest: public Request {
     MOCK_CONST_METHOD0(GetDataID, uint64_t());
     MOCK_CONST_METHOD0(GetData, const asapo::FileData & ());
     MOCK_CONST_METHOD0(GetBeamtimeId, const std::string & ());
+    MOCK_CONST_METHOD0(GetBeamline, const std::string & ());
     MOCK_CONST_METHOD0(GetOpCode, asapo::Opcode ());
     MOCK_CONST_METHOD0(GetMessage, const char* ());
     MOCK_METHOD1(SetBeamtimeId, void (std::string));
+    MOCK_METHOD1(SetBeamline, void (std::string));
 };
 
 
diff --git a/receiver/unittests/test_request.cpp b/receiver/unittests/test_request.cpp
index c6e84575db94524dbc690ab889995c0aa9cdf9da..429a5b8e5ae28bef83c7e5a24761aa81432fb829 100644
--- a/receiver/unittests/test_request.cpp
+++ b/receiver/unittests/test_request.cpp
@@ -217,5 +217,19 @@ TEST_F(RequestTests, GetFileName) {
     ASSERT_THAT(fname, Eq(s));
 }
 
+TEST_F(RequestTests, SetGetBeamtimeId) {
+    request->SetBeamtimeId("beamtime");
+
+    ASSERT_THAT(request->GetBeamtimeId(), "beamtime");
+}
+
+
+TEST_F(RequestTests, SetGetBeamline) {
+    request->SetBeamline("beamline");
+
+    ASSERT_THAT(request->GetBeamline(), "beamline");
+}
+
+
 
 }
diff --git a/receiver/unittests/test_request_handler_authorizer.cpp b/receiver/unittests/test_request_handler_authorizer.cpp
index 1b2d7b423329fe262862b740119a8c09a1342283..3fabc8000510bdcf6a569771144b35a612e29231 100644
--- a/receiver/unittests/test_request_handler_authorizer.cpp
+++ b/receiver/unittests/test_request_handler_authorizer.cpp
@@ -15,7 +15,6 @@
 #include "receiver_mocking.h"
 
 #include "../src/receiver_config.h"
-#include "mock_receiver_config.h"
 
 
 using ::testing::Test;
@@ -65,6 +64,7 @@ class AuthorizerHandlerTests : public Test {
 
     NiceMock<asapo::MockLogger> mock_logger;
     std::string expected_beamtime_id = "beamtime_id";
+    std::string expected_beamline = "beamline";
     std::string expected_producer_uri = "producer_uri";
     std::string expected_authorization_server = "authorizer_host";
     std::string expect_request_string = std::string("{\"BeamtimeId\":\"") + expected_beamtime_id + "\",\"OriginHost\":\"" +
@@ -101,7 +101,7 @@ class AuthorizerHandlerTests : public Test {
             WillOnce(
                 DoAll(SetArgPointee<3>(nullptr),
                       SetArgPointee<2>(code),
-                      Return(expected_beamtime_id)
+                      Return("{\"BeamtimeId\":\"" + expected_beamtime_id + "\",\"Beamline\":" + "\"" + expected_beamline + "\"}")
                      ));
             if (code != HttpCode::OK) {
                 EXPECT_CALL(mock_logger, Error(AllOf(HasSubstr("failure authorizing"),
@@ -133,6 +133,7 @@ class AuthorizerHandlerTests : public Test {
         ;
         if (!error && code == HttpCode::OK) {
             EXPECT_CALL(*mock_request, SetBeamtimeId(expected_beamtime_id));
+            EXPECT_CALL(*mock_request, SetBeamline(expected_beamline));
         }
 
         MockAuthRequest(error, code);
@@ -225,6 +226,7 @@ TEST_F(AuthorizerHandlerTests, DataTransferRequestAuthorizeUsesCachedValue) {
     .WillOnce(Return(asapo::kOpcodeTransferData));
     EXPECT_CALL(mock_http_client, Post_t(_, _, _, _)).Times(0);
     EXPECT_CALL(*mock_request, SetBeamtimeId(expected_beamtime_id));
+    EXPECT_CALL(*mock_request, SetBeamline(expected_beamline));
 
     auto err =  handler.ProcessRequest(mock_request.get());
 
diff --git a/receiver/unittests/test_request_handler_file_write.cpp b/receiver/unittests/test_request_handler_file_write.cpp
index 2ae3aeddef87d518a5e4f66d5eaf5de2537de885..5a999e0681aecb1009088bcf92d60b842dec515e 100644
--- a/receiver/unittests/test_request_handler_file_write.cpp
+++ b/receiver/unittests/test_request_handler_file_write.cpp
@@ -57,6 +57,7 @@ class FileWriteHandlerTests : public Test {
     NiceMock<asapo::MockLogger> mock_logger;
     std::string expected_file_name = "2.bin";
     std::string expected_beamtime_id = "beamtime_id";
+    std::string expected_beamline = "beamline";
     uint64_t expected_file_size = 10;
     void MockRequestData();
     void SetUp() override {
@@ -112,6 +113,11 @@ void FileWriteHandlerTests::MockRequestData() {
     .WillOnce(ReturnRef(expected_beamtime_id))
     ;
 
+    EXPECT_CALL(*mock_request, GetBeamline())
+    .WillOnce(ReturnRef(expected_beamline))
+    ;
+
+
     EXPECT_CALL(*mock_request, GetFileName())
     .WillOnce(Return(expected_file_name))
     ;
@@ -125,7 +131,8 @@ TEST_F(FileWriteHandlerTests, CallsWriteFile) {
 
     MockRequestData();
 
-    std::string expected_path = std::string("test_folder") + asapo::kPathSeparator + expected_beamtime_id
+    std::string expected_path = std::string("test_folder") + asapo::kPathSeparator + expected_beamline
+                                + asapo::kPathSeparator + expected_beamtime_id
                                 + asapo::kPathSeparator + expected_file_name;
 
     EXPECT_CALL(mock_io, WriteDataToFile_t(expected_path.c_str(), _, expected_file_size))
diff --git a/tests/automatic/CMakeLists.txt b/tests/automatic/CMakeLists.txt
index bc93ec01b6892abb9614505a95823fd7e90a3b9b..8377afd4aafa7681b21b0900119db67032fb1073 100644
--- a/tests/automatic/CMakeLists.txt
+++ b/tests/automatic/CMakeLists.txt
@@ -15,6 +15,7 @@ if(BUILD_BROKER)
     add_subdirectory(broker)
 endif()
 
+add_subdirectory(authorizer)
 
 add_subdirectory(worker)
 
diff --git a/tests/automatic/authorizer/CMakeLists.txt b/tests/automatic/authorizer/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..db373a3122354e2403384f26cdfb4ddcbd964860
--- /dev/null
+++ b/tests/automatic/authorizer/CMakeLists.txt
@@ -0,0 +1,2 @@
+add_subdirectory(check_authorize)
+
diff --git a/tests/automatic/authorizer/check_authorize/CMakeLists.txt b/tests/automatic/authorizer/check_authorize/CMakeLists.txt
new file mode 100644
index 0000000000000000000000000000000000000000..4eeea11316dee109499f51773470d1ee330aca40
--- /dev/null
+++ b/tests/automatic/authorizer/check_authorize/CMakeLists.txt
@@ -0,0 +1,10 @@
+set(TARGET_NAME asapo-authorizer)
+
+################################
+# Testing
+################################
+file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/OpenBeamTimes.txt BEAMTIMES_FILE )
+file(TO_NATIVE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/ip_bl_mapping BEAMLINES_FOLDER )
+configure_file(${CMAKE_CURRENT_SOURCE_DIR}/settings.json.in settings.json @ONLY)
+add_script_test("${TARGET_NAME}-authorize" "$<TARGET_PROPERTY:${TARGET_NAME},EXENAME>" nomem
+        )
diff --git a/tests/automatic/authorizer/check_authorize/OpenBeamTimes.txt b/tests/automatic/authorizer/check_authorize/OpenBeamTimes.txt
new file mode 100644
index 0000000000000000000000000000000000000000..b218c3ec6a28d10fd6e94d86d61992eb79bdbf65
--- /dev/null
+++ b/tests/automatic/authorizer/check_authorize/OpenBeamTimes.txt
@@ -0,0 +1,22 @@
+Open beam times as of  Thursday, 2018/06/21 11:32
+Faclty	BL	BeamTime Id		kind
+flash	bl1	11003924		beamtime	start: 2018-04-24
+flash	bl2	11003921		beamtime	start: 2018-06-08
+flash	fl24	11001734		beamtime	start: 2018-06-13
+flash	pg2	11003932		beamtime	start: 2018-06-11
+flash	thz	11005667		beamtime	start: 2018-05-24
+petra3	ext	50000181		beamtime	start: 2017-04-12
+petra3	ext	50000193		beamtime	start: 2017-10-12
+petra3	ext	50000202		beamtime	start: 2017-12-06
+petra3	ext	50000209		beamtime	start: 2018-02-19
+petra3	ext	50000211		beamtime	start: 2018-02-19
+petra3	ext	50000214		beamtime	start: 2018-04-23
+petra3	ext	50000215		beamtime	start: 2018-03-23
+petra3	ext	50000216		beamtime	start: 2018-03-23
+petra3	ext	50000217		beamtime	start: 2018-03-23
+petra3	ext	50000218		beamtime	start: 2018-03-23
+petra3	ext	50000219		beamtime	start: 2018-04-24
+petra3	ext	50000221		beamtime	start: 2018-06-14
+petra3	p01	11004172		beamtime	start: 2018-06-20
+petra3	p01	c20180508-000-COM20181	commissioning
+petra3	p02.1	11004341		beamtime	start: 2018-06-18
diff --git a/tests/automatic/authorizer/check_authorize/check_linux.sh b/tests/automatic/authorizer/check_authorize/check_linux.sh
new file mode 100644
index 0000000000000000000000000000000000000000..38c9bcf333a68ddd19ebb0174c59bd48b62efb16
--- /dev/null
+++ b/tests/automatic/authorizer/check_authorize/check_linux.sh
@@ -0,0 +1,18 @@
+#!/usr/bin/env bash
+
+set -e
+
+trap Cleanup EXIT
+
+Cleanup() {
+	echo cleanup
+	kill -9 $authorizeid
+}
+
+$@ -config settings.json  > authorizer.log &
+
+sleep 0.3
+authorizeid=`echo $!`
+
+curl -v --silent --data '{"BeamtimeId":"c20180508-000-COM20181","OriginHost":"127.0.0.1:5555"}' 127.0.0.1:5007/authorize --stderr -
+
diff --git a/tests/automatic/authorizer/check_authorize/check_windows.bat b/tests/automatic/authorizer/check_authorize/check_windows.bat
new file mode 100644
index 0000000000000000000000000000000000000000..443c05422d74a9c346e72ca65cfd5c5535a1f964
--- /dev/null
+++ b/tests/automatic/authorizer/check_authorize/check_windows.bat
@@ -0,0 +1,26 @@
+SET database_name=data
+SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe"
+
+echo db.data.insert({"_id":1}) | %mongo_exe% %database_name%  || goto :error
+echo db.data.insert({"_id":2}) | %mongo_exe% %database_name%  || goto :error
+
+set full_name="%1"
+set short_name="%~nx1"
+
+start /B "" "%full_name%" -config settings.json
+
+ping 1.0.0.0 -n 1 -w 100 > nul
+
+C:\Curl\curl.exe -v  --silent 127.0.0.1:5005/database/data/next --stderr - | findstr /c:\"_id\":1  || goto :error
+C:\Curl\curl.exe -v  --silent 127.0.0.1:5005/database/data/next --stderr - | findstr /c:\"_id\":2  || goto :error
+C:\Curl\curl.exe -v  --silent 127.0.0.1:5005/database/data/next --stderr - | findstr  /c:"not found"  || goto :error
+
+goto :clean
+
+:error
+call :clean
+exit /b 1
+
+:clean
+Taskkill /IM "%short_name%" /F
+echo db.dropDatabase() | %mongo_exe% %database_name%
diff --git a/tests/automatic/authorizer/check_authorize/ip_bl_mapping/127.0.0.1 b/tests/automatic/authorizer/check_authorize/ip_bl_mapping/127.0.0.1
new file mode 100644
index 0000000000000000000000000000000000000000..9b9883faf44d6f232627e1047d327ea91a47ae08
--- /dev/null
+++ b/tests/automatic/authorizer/check_authorize/ip_bl_mapping/127.0.0.1
@@ -0,0 +1 @@
+p01
diff --git a/tests/automatic/authorizer/check_authorize/settings.json.in b/tests/automatic/authorizer/check_authorize/settings.json.in
new file mode 100644
index 0000000000000000000000000000000000000000..0d8670b99c17a60fddcc8f1d06d4481ce8374aa6
--- /dev/null
+++ b/tests/automatic/authorizer/check_authorize/settings.json.in
@@ -0,0 +1,8 @@
+{
+  "Port": 5007,
+  "LogLevel":"debug",
+  "BeamtimeBeamlineMappingFile":"@BEAMTIMES_FILE@",
+  "IpBeamlineMappingFolder":"@BEAMLINES_FOLDER@"
+}
+
+
diff --git a/tests/automatic/full_chain/simple_chain/check_linux.sh b/tests/automatic/full_chain/simple_chain/check_linux.sh
index ef79fadbaa39d90ec22ca88018f72ba7a11835c7..22b61d6e01dec2b23a28db2fbf737aded47a6d24 100644
--- a/tests/automatic/full_chain/simple_chain/check_linux.sh
+++ b/tests/automatic/full_chain/simple_chain/check_linux.sh
@@ -8,11 +8,13 @@ beamtime_id=asapo_test
 monitor_database_name=db_test
 proxy_address=127.0.0.1:8400
 
-receiver_folder=/tmp/asapo/receiver/files/${beamtime_id}
+beamline=test
+receiver_root_folder=/tmp/asapo/receiver/files
+receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id}
 
 Cleanup() {
     echo cleanup
-    rm -rf ${receiver_folder}
+    rm -rf ${receiver_root_folder}
     nomad stop nginx
     nomad stop receiver
     nomad stop discovery
diff --git a/tests/automatic/full_chain/simple_chain/check_windows.bat b/tests/automatic/full_chain/simple_chain/check_windows.bat
index 35ecdb57ddd5e9330947d697013774809a4543e4..8461997c0a222cd06497fcb6f5bb41d3a97615ba 100644
--- a/tests/automatic/full_chain/simple_chain/check_windows.bat
+++ b/tests/automatic/full_chain/simple_chain/check_windows.bat
@@ -1,6 +1,10 @@
 SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe"
-SET beamtime_id=asapo_test
-SET receiver_folder="c:\tmp\asapo\receiver\files\%beamtime_id%"
+SET beamline=test
+SET receiver_root_folder="c:\tmp\asapo\receiver\files"
+SET receiver_folder="%receiver_root_folder%\%beamline%\%beamtime_id%"
+
+
+
 set proxy_address="127.0.0.1:8400"
 
 echo db.%beamtime_id%.insert({dummy:1}) | %mongo_exe% %beamtime_id%
@@ -34,7 +38,7 @@ c:\opt\consul\nomad stop discovery
 c:\opt\consul\nomad stop broker
 c:\opt\consul\nomad stop authorizer
 c:\opt\consul\nomad stop nginx
-rmdir /S /Q %receiver_folder%
+rmdir /S /Q %receiver_root_folder%
 echo db.dropDatabase() | %mongo_exe% %beamtime_id%
 
 
diff --git a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh
index 8a5a5e517d0c435e44d5aee083e0f453b0f4bdbe..ff0af0589a529b76b0afaf0522aca3be4f701645 100644
--- a/tests/automatic/producer_receiver/check_monitoring/check_linux.sh
+++ b/tests/automatic/producer_receiver/check_monitoring/check_linux.sh
@@ -2,7 +2,9 @@
 
 database_name=db_test
 beamtime_id=asapo_test
-receiver_folder=/tmp/asapo/receiver/files/${beamtime_id}
+beamline=test
+receiver_root_folder=/tmp/asapo/receiver/files
+receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id}
 set -e
 
 trap Cleanup EXIT
@@ -15,7 +17,7 @@ Cleanup() {
     nomad stop authorizer
     nomad stop nginx
     echo "db.dropDatabase()" | mongo ${beamtime_id}
-    rm -rf ${receiver_folder}
+    rm -rf ${receiver_root_folder}
 }
 
 mkdir -p ${receiver_folder}
diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh
index a5e357400d76b3f54dabada7c96d0fb2df84c586..972324483c226905c385cb6d51031366f4b52555 100644
--- a/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh
+++ b/tests/automatic/producer_receiver/transfer_single_file/check_linux.sh
@@ -6,11 +6,13 @@ trap Cleanup EXIT
 
 database_name=db_test
 beamtime_id=asapo_test
-receiver_folder=/tmp/asapo/receiver/files/${beamtime_id}
+beamline=test
+receiver_root_folder=/tmp/asapo/receiver/files
+receiver_folder=${receiver_root_folder}/${beamline}/${beamtime_id}
 
 Cleanup() {
 	echo cleanup
-	rm -rf ${receiver_folder}
+	rm -rf ${receiver_root_folder}
     nomad stop receiver
     nomad stop discovery
     nomad stop authorizer
diff --git a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat
index 64c39dcc94409bea1ac1e9ae5485b55a88d0b262..ea1dff5cd8bffdbe6aa6e9006531d6ce62870f70 100644
--- a/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat
+++ b/tests/automatic/producer_receiver/transfer_single_file/check_windows.bat
@@ -1,6 +1,9 @@
 SET mongo_exe="c:\Program Files\MongoDB\Server\3.6\bin\mongo.exe"
 SET beamtime_id=asapo_test
-SET receiver_folder="c:\tmp\asapo\receiver\files\%beamtime_id%"
+SET beamline=test
+SET receiver_root_folder="c:\tmp\asapo\receiver\files"
+SET receiver_folder="%receiver_root_folder%\%beamline%\%beamtime_id%"
+
 
 echo db.%beamtime_id%.insert({dummy:1})" | %mongo_exe% %beamtime_id%
 
@@ -34,7 +37,7 @@ c:\opt\consul\nomad stop receiver
 c:\opt\consul\nomad stop discovery
 c:\opt\consul\nomad stop nginx
 c:\opt\consul\nomad stop authorizer
-rmdir /S /Q %receiver_folder%
+rmdir /S /Q %receiver_root_folder%
 echo db.dropDatabase() | %mongo_exe% %beamtime_id%
 
 
diff --git a/tests/automatic/settings/authorizer_settings.json.tpl b/tests/automatic/settings/authorizer_settings.json.tpl
index a1b6b310333a32403df4e700830851c85649e3fa..052462d535427c936717390da210fd9df3867e7e 100644
--- a/tests/automatic/settings/authorizer_settings.json.tpl
+++ b/tests/automatic/settings/authorizer_settings.json.tpl
@@ -1,6 +1,7 @@
 {
   "Port": {{ env "NOMAD_PORT_authorizer" }},
-  "LogLevel":"debug"
+  "LogLevel":"debug",
+  "AlwaysAllowedBeamtimes":[{"BeamtimeId":"asapo_test","Beamline":"test"}]
 }
 
 
diff --git a/tests/manual/performance_full_chain_simple/authorizer.json b/tests/manual/performance_full_chain_simple/authorizer.json
index 4018a0ba239fd5d8311a3d75c861a7bded6cb0d1..64db1880ddfa86e7d478b7fbc8825744e4cfcb1d 100644
--- a/tests/manual/performance_full_chain_simple/authorizer.json
+++ b/tests/manual/performance_full_chain_simple/authorizer.json
@@ -1,6 +1,7 @@
 {
   "Port": 5007,
-  "LogLevel":"info"
+  "LogLevel":"info",
+  "AlwaysAllowedBeamtimes":[{"BeamtimeId":"asapo_test","Beamline":"test"}]
 }
 
 
diff --git a/tests/manual/performance_full_chain_simple/test.sh b/tests/manual/performance_full_chain_simple/test.sh
index 8e546b72325c72587b87af46a87e84f4c53595ac..78263578bb4da26624fafb765851eaa7466cc3fc 100755
--- a/tests/manual/performance_full_chain_simple/test.sh
+++ b/tests/manual/performance_full_chain_simple/test.sh
@@ -7,7 +7,7 @@ trap Cleanup EXIT
 #clean-up
 Cleanup() {
 set +e
-ssh ${receiver_node} rm -f ${receiver_dir}/files/${beamtime_id}/*
+ssh ${receiver_node} rm -f ${receiver_dir}/files/${beamline}/${beamtime_id}/*
 ssh ${receiver_node} killall receiver
 ssh ${receiver_node} killall asapo-discovery
 ssh ${receiver_node} killall asapo-authorizer
@@ -16,6 +16,7 @@ ssh ${broker_node} docker rm -f -v mongo
 }
 
 beamtime_id=asapo_test
+beamline=test
 
 
 #monitoring_setup
@@ -38,7 +39,7 @@ echo filesize: ${file_size}K, filenum: $file_num
 receiver_node=max-wgs
 receiver_port=4201
 receiver_dir=/gpfs/petra3/scratch/yakubov/receiver_tests
-ssh ${receiver_node} mkdir -p ${receiver_dir}/files/${beamtime_id}
+ssh ${receiver_node} mkdir -p ${receiver_dir}/files/${beamline}/${beamtime_id}
 scp ../../../cmake-build-release/receiver/receiver ${receiver_node}:${receiver_dir}
 cat receiver.json |
   jq "to_entries |
diff --git a/tests/manual/performance_producer_receiver/authorizer.json b/tests/manual/performance_producer_receiver/authorizer.json
index 4018a0ba239fd5d8311a3d75c861a7bded6cb0d1..64db1880ddfa86e7d478b7fbc8825744e4cfcb1d 100644
--- a/tests/manual/performance_producer_receiver/authorizer.json
+++ b/tests/manual/performance_producer_receiver/authorizer.json
@@ -1,6 +1,7 @@
 {
   "Port": 5007,
-  "LogLevel":"info"
+  "LogLevel":"info",
+  "AlwaysAllowedBeamtimes":[{"BeamtimeId":"asapo_test","Beamline":"test"}]
 }
 
 
diff --git a/tests/manual/performance_producer_receiver/test.sh b/tests/manual/performance_producer_receiver/test.sh
index f8b4a25f870125f4f006cd5542d4973505a9d3fe..eef1d5dd4c724636fe8a6327931ac091d9c1d06a 100755
--- a/tests/manual/performance_producer_receiver/test.sh
+++ b/tests/manual/performance_producer_receiver/test.sh
@@ -6,7 +6,7 @@ trap Cleanup EXIT
 
 Cleanup() {
 set +e
-ssh ${service_node} rm -f ${service_dir}/files/${beamtime_id}/*
+ssh ${service_node} rm -f ${service_dir}/files/${beamline}/${beamtime_id}/*
 ssh ${service_node} killall receiver
 ssh ${service_node} killall asapo-discovery
 ssh ${service_node} killall asapo-authorizer
@@ -23,6 +23,7 @@ service_ip=`resolveip -s ${service_node}`
 discovery_port=5006
 receiver_port=4201
 beamtime_id=asapo_test
+beamline=test
 
 
 monitor_node=zitpcx27016
@@ -95,7 +96,7 @@ echo ===================================================================
 ssh ${worker_node} ${worker_dir}/dummy-data-producer ${service_ip}:8400 ${beamtime_id} ${size} 1000 8 0 100
 if [ "$1" == "true" ]
 then
-    ssh ${service_node} rm -f ${service_dir}/files/${beamtime_id}/*
+    ssh ${service_node} rm -f ${service_dir}/files/${beamline}/${beamtime_id}/*
 fi
 ssh ${service_node} docker rm -f -v mongo
 done