Makefile.am | 2 common/Authorization.cpp | 75 +++++++++++++++++++++++++++++++ common/Authorization.hpp | 56 +++++++++++++++++++++++ loleaflet/js/toolbar.js | 6 ++ loleaflet/src/control/Signing.js | 94 +++++++++++++++++++++++++++++++++------ test/Makefile.am | 1 test/WhiteBoxTests.cpp | 2 wsd/Admin.cpp | 1 wsd/Auth.cpp | 56 ----------------------- wsd/Auth.hpp | 34 -------------- wsd/Storage.hpp | 1 11 files changed, 224 insertions(+), 104 deletions(-)
New commits: commit 73c8fa9d095b219b87588c172c2d07c7e735654b Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Nov 22 12:03:42 2018 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Nov 29 21:47:13 2018 +0100 Extract Authorization out of Auth and put it into common This is needed so we can use this inside ChildSession. Change-Id: I88f2cc767412fd52dbb242938f0f9897d4277639 Reviewed-on: https://gerrit.libreoffice.org/63836 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/Makefile.am b/Makefile.am index 69686cec4..a70bb68a7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -91,6 +91,7 @@ shared_sources = common/FileUtil.cpp \ common/SpookyV2.cpp \ common/Unit.cpp \ common/Util.cpp \ + common/Authorization.cpp \ net/DelaySocket.cpp \ net/Socket.cpp if ENABLE_SSL @@ -196,6 +197,7 @@ shared_headers = common/Common.hpp \ common/Unit.hpp \ common/UnitHTTP.hpp \ common/Util.hpp \ + common/Authorization.hpp \ common/MessageQueue.hpp \ common/Message.hpp \ common/Png.hpp \ diff --git a/common/Authorization.cpp b/common/Authorization.cpp new file mode 100644 index 000000000..20e77acba --- /dev/null +++ b/common/Authorization.cpp @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <config.h> + +#include "Authorization.hpp" + +#include <cstdlib> +#include <cassert> + +#include <Poco/StringTokenizer.h> + +void Authorization::authorizeURI(Poco::URI& uri) const +{ + if (_type == Authorization::Type::Token) + { + static const std::string key("access_token"); + + Poco::URI::QueryParameters queryParams = uri.getQueryParameters(); + for (auto& param: queryParams) + { + if (param.first == key) + { + param.second = _data; + uri.setQueryParameters(queryParams); + return; + } + } + + // it did not exist yet + uri.addQueryParameter(key, _data); + } +} + +void Authorization::authorizeRequest(Poco::Net::HTTPRequest& request) const +{ + switch (_type) + { + case Type::Token: + request.set("Authorization", "Bearer " + _data); + break; + case Type::Header: + { + // there might be more headers in here; like + // Authorization: Basic .... + // X-Something-Custom: Huh + Poco::StringTokenizer tokens(_data, "\n\r", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); + for (const auto& token : tokens) + { + size_t i = token.find_first_of(':'); + if (i != std::string::npos) + { + size_t separator = i; + for (++i; i < token.length() && token[i] == ' ';) + ++i; + + // set the header + if (i < token.length()) + request.set(token.substr(0, separator), token.substr(i)); + } + } + break; + } + default: + assert(false); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/common/Authorization.hpp b/common/Authorization.hpp new file mode 100644 index 000000000..c8c594988 --- /dev/null +++ b/common/Authorization.hpp @@ -0,0 +1,56 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +// WOPI Authorization + +#ifndef INCLUDED_AUTHORIZATION_HPP +#define INCLUDED_AUTHORIZATION_HPP + +#include <string> + +#include <Poco/Net/HTTPRequest.h> +#include <Poco/URI.h> + +/// Class to keep the authorization data. +class Authorization +{ +public: + enum class Type + { + None, + Token, + Header + }; + +private: + Type _type; + std::string _data; + +public: + Authorization() + : _type(Type::None) + { + } + + Authorization(Type type, const std::string& data) + : _type(type) + , _data(data) + { + } + + /// Set the access_token parametr to the given uri. + void authorizeURI(Poco::URI& uri) const; + + /// Set the Authorization: header in request. + void authorizeRequest(Poco::Net::HTTPRequest& request) const; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/Makefile.am b/test/Makefile.am index 62b859bcc..c43e14dd6 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -45,6 +45,7 @@ wsd_sources = \ ../common/Session.cpp \ ../common/Util.cpp \ ../common/MessageQueue.cpp \ + ../common/Authorization.cpp \ ../kit/Kit.cpp \ ../wsd/Auth.cpp \ ../wsd/TileCache.cpp \ diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp index 30f8327bf..482a76e18 100644 --- a/test/WhiteBoxTests.cpp +++ b/test/WhiteBoxTests.cpp @@ -21,6 +21,8 @@ #include <Util.hpp> #include <JsonUtil.hpp> +#include <common/Authorization.hpp> + /// WhiteBox unit-tests. class WhiteBoxTests : public CPPUNIT_NS::TestFixture { diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp index c5f303ad0..414427027 100644 --- a/wsd/Admin.cpp +++ b/wsd/Admin.cpp @@ -38,6 +38,7 @@ #include <net/WebSocketHandler.hpp> #include <common/SigUtil.hpp> +#include <common/Authorization.hpp> using namespace LOOLProtocol; diff --git a/wsd/Auth.cpp b/wsd/Auth.cpp index 6be7eceea..f4e92907d 100644 --- a/wsd/Auth.cpp +++ b/wsd/Auth.cpp @@ -39,62 +39,6 @@ using Poco::OutputLineEndingConverter; const Poco::Crypto::RSAKey JWTAuth::_key(Poco::Crypto::RSAKey(Poco::Crypto::RSAKey::KL_2048, Poco::Crypto::RSAKey::EXP_LARGE)); -void Authorization::authorizeURI(Poco::URI& uri) const -{ - if (_type == Authorization::Type::Token) - { - static const std::string key("access_token"); - - Poco::URI::QueryParameters queryParams = uri.getQueryParameters(); - for (auto& param: queryParams) - { - if (param.first == key) - { - param.second = _data; - uri.setQueryParameters(queryParams); - return; - } - } - - // it did not exist yet - uri.addQueryParameter(key, _data); - } -} - -void Authorization::authorizeRequest(Poco::Net::HTTPRequest& request) const -{ - switch (_type) - { - case Type::Token: - request.set("Authorization", "Bearer " + _data); - break; - case Type::Header: - { - // there might be more headers in here; like - // Authorization: Basic .... - // X-Something-Custom: Huh - Poco::StringTokenizer tokens(_data, "\n\r", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); - for (const auto& token : tokens) - { - size_t i = token.find_first_of(':'); - if (i != std::string::npos) - { - size_t separator = i; - for (++i; i < token.length() && token[i] == ' ';) - ++i; - - // set the header - if (i < token.length()) - request.set(token.substr(0, separator), token.substr(i)); - } - } - break; - } - default: - assert(false); - } -} - const std::string JWTAuth::getAccessToken() { std::string encodedHeader = createHeader(); diff --git a/wsd/Auth.hpp b/wsd/Auth.hpp index 3616b0144..3659a6d38 100644 --- a/wsd/Auth.hpp +++ b/wsd/Auth.hpp @@ -21,40 +21,6 @@ #include <Poco/Net/HTTPRequest.h> #include <Poco/URI.h> -/// Class to keep the authorization data. -class Authorization -{ -public: - enum class Type - { - None, - Token, - Header - }; - -private: - Type _type; - std::string _data; - -public: - Authorization() - : _type(Type::None) - { - } - - Authorization(Type type, const std::string& data) - : _type(type) - , _data(data) - { - } - - /// Set the access_token parametr to the given uri. - void authorizeURI(Poco::URI& uri) const; - - /// Set the Authorization: header in request. - void authorizeRequest(Poco::Net::HTTPRequest& request) const; -}; - /// Base class of all Authentication/Authorization implementations. class AuthBase { diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp index 990a03adc..893fa9e35 100644 --- a/wsd/Storage.hpp +++ b/wsd/Storage.hpp @@ -21,6 +21,7 @@ #include "LOOLWSD.hpp" #include "Log.hpp" #include "Util.hpp" +#include <common/Authorization.hpp> /// Base class of all Storage abstractions. class StorageBase commit 089e58880fec6ae7615adabc4595ad0f84685526 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> AuthorDate: Thu Nov 15 10:12:16 2018 +0100 Commit: Tomaž Vajngerl <qui...@gmail.com> CommitDate: Thu Nov 29 21:47:05 2018 +0100 Add passport selection to infobar Change-Id: I9e997c22b3ecce249b33cc97acecc78fd34fae32 Reviewed-on: https://gerrit.libreoffice.org/63414 Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> Tested-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js index 15b91adeb..145d14e5e 100644 --- a/loleaflet/js/toolbar.js +++ b/loleaflet/js/toolbar.js @@ -251,6 +251,9 @@ function onClick(e, id, item, subItem) { } L.toggleFullScreen(); } + else if (id.startsWith('passport:')) { + map.setCurrentPassport(item.value, item.text); + } } function setBorders(left, right, bottom, top, horiz, vert) { @@ -955,6 +958,9 @@ function initNormalToolbar(toolItems) { {type: 'html', id: 'identity-label', html: '<b>Identity:</b>'}, {type: 'html', id: 'identity', html: 'N/A'}, {type: 'break' }, + {type: 'menu', id: 'passport', caption: _('Select passport'), items: []}, + {type: 'html', id: 'current-passport', html: 'Passport: N/A'}, + {type: 'break' }, {type: 'button', id: 'logout', caption: 'Logout', img: '', hint: _('Logout')}, {type: 'button', id: 'login', caption: 'Login', img: '', hint: _('Login')}, ], diff --git a/loleaflet/src/control/Signing.js b/loleaflet/src/control/Signing.js index ba656565f..5318b3089 100644 --- a/loleaflet/src/control/Signing.js +++ b/loleaflet/src/control/Signing.js @@ -7,11 +7,16 @@ var library = null; var identity = null; +var currentPassport = null; function isSuccess(result) { return result.code == '200'; } +function haveIdentity() { + return identity != null; +} + function updateIndentity() { if (library) { if (identity) { @@ -28,13 +33,63 @@ function updateIndentity() { } } +function addPassportToToolbar(passport, i) { + var name = null; + try { + name = passport['claims']['passportName']['tags']['notag']['value']['value']; + } + catch (exception) { + console.log(exception); + name = 'Unknown ' + (i+1); + } + + w2ui['document-signing-bar'].get('passport').items.push( + { text: name, id: 'item ' + (i+1), value: passport.uuid } + ); +} + +function updatePassportList() { + if (library) { + library.passportListPassports().then(function(result) { + if (isSuccess(result)) + { + w2ui['document-signing-bar'].get('passport').items = []; + var passports = result.data; + for (var i = 0; i < passports.length; i++) { + addPassportToToolbar(passports[i], i); + } + updateCurrentPassport(); + adjustUIState(); + } + }); + } +} + +function updateCurrentPassport() { + if (!haveIdentity()) + return; + if (currentPassport) { + w2ui['document-signing-bar'].get('current-passport').html = '<p>' + currentPassport.text + '</p>'; + } + adjustUIState(); +} + function adjustUIState() { if (library && identity) { w2ui['document-signing-bar'].hide('login'); w2ui['document-signing-bar'].show('logout'); w2ui['document-signing-bar'].show('identity-label'); w2ui['document-signing-bar'].show('identity'); - w2ui['document-signing-bar'].show('sign'); + if (currentPassport) { + w2ui['document-signing-bar'].show('passport'); + w2ui['document-signing-bar'].show('current-passport'); + w2ui['document-signing-bar'].show('sign'); + } + else { + w2ui['document-signing-bar'].show('passport'); + w2ui['document-signing-bar'].hide('current-passport'); + w2ui['document-signing-bar'].hide('sign'); + } } else { if (library) @@ -46,6 +101,8 @@ function adjustUIState() { w2ui['document-signing-bar'].hide('identity-label'); w2ui['document-signing-bar'].hide('identity'); w2ui['document-signing-bar'].hide('sign'); + w2ui['document-signing-bar'].hide('passport'); + w2ui['document-signing-bar'].hide('current-passport'); } w2ui['document-signing-bar'].refresh(); } @@ -60,18 +117,15 @@ L.Map.include({ signDocument: function() { if (library) { var map = this; - library.getCurrentlyLoggedInUUID().then(function(result) { - if (isSuccess(result)) { - var UUID = result.data; - library.getOneTimeCertificateByPassport(UUID).then(function(result) { - if (isSuccess(result)) { - var otp = result.data; - var blob = new Blob(['signdocument\n', JSON.stringify(otp)]); - map._socket.sendMessage(blob); - } - }); - } - }); + if (currentPassport) { + library.getOneTimeCertificateByPassport(currentPassport.uuid).then(function(result) { + if (isSuccess(result)) { + var otp = result.data; + var blob = new Blob(['signdocument\n', JSON.stringify(otp)]); + map._socket.sendMessage(blob); + } + }); + } } }, signingLogout: function() { @@ -79,6 +133,7 @@ L.Map.include({ library.logout().then(function(result) { if (isSuccess(result)) { identity = null; + currentPassport = null; updateIndentity(); adjustUIState(); } @@ -98,6 +153,7 @@ L.Map.include({ if (isSuccess(result)) { identity = result.data; updateIndentity(); + updatePassportList(); adjustUIState(); } }); @@ -108,11 +164,21 @@ L.Map.include({ } } }, - 'https://dev.vereign.com/api/js/iframe' + 'https://integration1.vereign.com/api/js/iframe' ).then(function(lib) { library = lib; adjustUIState(); }); + }, + setCurrentPassport: function(uuid, text) { + if (library && identity && uuid) { + currentPassport = { uuid: uuid, text: text }; + updateCurrentPassport(); + library.passportGetAvatarByPassport(uuid).then(function(result) { + console.log(result); + }); + adjustUIState(); + } } }); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits