Leosac  0.8.0
Open Source Access Control
Token.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #include "core/auth/Token.hpp"
21 #include "core/auth/User_odb.h"
22 #include "tools/log.hpp"
23 
24 using namespace Leosac;
25 using namespace Leosac::Auth;
26 
28 //: version_(0)
29 {
30 }
31 
32 Token::Token(const std::string &token, UserPtr owner)
33  : token_(token)
34  , owner_(owner)
35 //, version_(0)
36 {
37  expire_in(std::chrono::milliseconds(0));
38 }
39 
40 const std::string &Token::token() const
41 {
42  return token_;
43 }
44 
45 bool Token::is_valid() const
46 {
47  auto now = boost::posix_time::second_clock::local_time();
48  return expiration_ >= now;
49 }
50 
52 {
53  return owner_;
54 }
55 
56 boost::posix_time::ptime Token::expiration() const
57 {
58  return expiration_;
59 }
60 
61 const std::string &Token::id() const
62 {
63  return token();
64 }
Leosac::Auth
Holds classes relevant to the Authentication and Authorization subsystem.
Definition: AccessPoint.hpp:27
Leosac::Auth::UserPtr
std::shared_ptr< User > UserPtr
Definition: AuthFwd.hpp:31
Leosac::Auth::Token::is_valid
bool is_valid() const
Check if the token is still active.
Definition: Token.cpp:45
Leosac::Auth::Token::id
const std::string & id() const
Return the token identifier.
Definition: Token.cpp:61
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Auth::Token::expiration
boost::posix_time::ptime expiration() const
Retrieve the unix timestamp at which the token will/has expire(d).
Definition: Token.cpp:56
Token.hpp
Leosac::Auth::Token::expire_in
void expire_in(const T &duration)
Set the expiration point of the token to be now + duration.
Definition: Token.hpp:84
log.hpp
Leosac::Auth::Token::expiration_
boost::posix_time::ptime expiration_
Definition: Token.hpp:111
Leosac::Auth::Token::owner_
UserPtr owner_
The user owning the token.
Definition: Token.hpp:108
Leosac::Auth::Token::Token
Token()
Definition: Token.cpp:27
Leosac::Auth::Token::owner
UserPtr owner() const
Retrieve a shared_ptr to the user owning the token.
Definition: Token.cpp:51
Leosac::Auth::Token::token_
std::string token_
The string representation of the token.
Definition: Token.hpp:101
Leosac::Auth::Token::token
const std::string & token() const
Retrieve the string representation of the token.
Definition: Token.cpp:40