| 1 |
# This module implements all the methods that responds to '/api/*' requests |
| 2 |
package Lemonldap::NG::Manager::Api; |
| 3 |
|
| 4 |
use strict; |
| 5 |
use utf8; |
| 6 |
use Mouse; |
| 7 |
|
| 8 |
use Lemonldap::NG::Manager::Api::2F; |
| 9 |
use Lemonldap::NG::Manager::Api::History; |
| 10 |
use Lemonldap::NG::Manager::Api::Misc; |
| 11 |
use Lemonldap::NG::Manager::Api::Providers::OidcRp; |
| 12 |
use Lemonldap::NG::Manager::Api::Providers::SamlSp; |
| 13 |
use Lemonldap::NG::Manager::Api::Providers::CasApp; |
| 14 |
use Lemonldap::NG::Manager::Api::Menu::Cat; |
| 15 |
use Lemonldap::NG::Manager::Api::Menu::App; |
| 16 |
use Lemonldap::NG::Common::TOTP; |
| 17 |
|
| 18 |
extends qw( |
| 19 |
Lemonldap::NG::Manager::Plugin |
| 20 |
Lemonldap::NG::Common::Conf::RESTServer |
| 21 |
Lemonldap::NG::Common::Session::REST |
| 22 |
); |
| 23 |
|
| 24 |
has totp_encrypt => ( is => "rw" ); |
| 25 |
our $VERSION = '2.19.0'; |
| 26 |
|
| 27 |
############################# |
| 28 |
# I. INITIALIZATION METHODS # |
| 29 |
############################# |
| 30 |
|
| 31 |
use constant defaultRoute => 'api.html'; |
| 32 |
use constant icon => 'flash'; |
| 33 |
|
| 34 |
sub init { |
| 35 |
my ( $self, $conf ) = @_; |
| 36 |
|
| 37 |
$self->ua( Lemonldap::NG::Common::UserAgent->new($conf) ); |
| 38 |
$self->totp_encrypt( |
| 39 |
Lemonldap::NG::Common::TOTP->new( |
| 40 |
key => ( $conf->{totp2fKey} || $conf->{key} ), |
| 41 |
encryptSecret => $conf->{totp2fEncryptSecret} |
| 42 |
) |
| 43 |
); |
| 44 |
|
| 45 |
# HTML template |
| 46 |
$self->addRoute( 'api.html', undef, ['GET'] ) |
| 47 |
|
| 48 |
->addRoute( |
| 49 |
api => { |
| 50 |
v1 => { |
| 51 |
status => 'status', |
| 52 |
providers => { |
| 53 |
oidc => { |
| 54 |
rp => { |
| 55 |
findByConfKey => { |
| 56 |
':uPattern' => 'findOidcRpByConfKey' |
| 57 |
}, |
| 58 |
findByClientId => { |
| 59 |
':uClientId' => 'findOidcRpByClientId' |
| 60 |
}, |
| 61 |
':confKey' => 'getOidcRpByConfKey' |
| 62 |
}, |
| 63 |
}, |
| 64 |
saml => { |
| 65 |
sp => { |
| 66 |
findByConfKey => { |
| 67 |
':uPattern' => 'findSamlSpByConfKey' |
| 68 |
}, |
| 69 |
findByEntityId => { |
| 70 |
':uEntityId' => 'findSamlSpByEntityId' |
| 71 |
}, |
| 72 |
':confKey' => 'getSamlSpByConfKey' |
| 73 |
}, |
| 74 |
}, |
| 75 |
cas => { |
| 76 |
app => { |
| 77 |
findByConfKey => { |
| 78 |
':uPattern' => 'findCasAppByConfKey' |
| 79 |
}, |
| 80 |
findByServiceUrl => { |
| 81 |
':uServiceUrl' => 'findCasAppsByServiceUrl' |
| 82 |
}, |
| 83 |
':confKey' => 'getCasAppByConfKey' |
| 84 |
}, |
| 85 |
}, |
| 86 |
}, |
| 87 |
secondFactor => { |
| 88 |
':_uid' => { |
| 89 |
id => { |
| 90 |
':id' => 'getSecondFactorsById' |
| 91 |
}, |
| 92 |
type => { |
| 93 |
':type' => 'getSecondFactorsByType' |
| 94 |
}, |
| 95 |
'*' => 'getSecondFactors' |
| 96 |
}, |
| 97 |
}, |
| 98 |
menu => { |
| 99 |
cat => { |
| 100 |
findByConfKey => { |
| 101 |
':uPattern' => 'findMenuCatByConfKey' |
| 102 |
}, |
| 103 |
':confKey' => { |
| 104 |
'*' => 'getMenuCatByConfKey' |
| 105 |
} |
| 106 |
}, |
| 107 |
app => { |
| 108 |
':confKey' => { |
| 109 |
findByConfKey => { |
| 110 |
':uPattern' => 'findMenuAppByConfKey' |
| 111 |
}, |
| 112 |
':appConfKey' => 'getMenuApp' |
| 113 |
} |
| 114 |
}, |
| 115 |
}, |
| 116 |
history => { |
| 117 |
':uid' => 'getHistory', |
| 118 |
}, |
| 119 |
}, |
| 120 |
}, |
| 121 |
['GET'] |
| 122 |
) |
| 123 |
|
| 124 |
->addRoute( |
| 125 |
api => { |
| 126 |
v1 => { |
| 127 |
providers => { |
| 128 |
oidc => { |
| 129 |
rp => 'addOidcRp' |
| 130 |
}, |
| 131 |
saml => { |
| 132 |
sp => 'addSamlSp' |
| 133 |
}, |
| 134 |
cas => { |
| 135 |
app => 'addCasApp' |
| 136 |
}, |
| 137 |
}, |
| 138 |
menu => { |
| 139 |
cat => 'addMenuCat', |
| 140 |
app => { |
| 141 |
':confKey' => 'addMenuApp' |
| 142 |
} |
| 143 |
}, |
| 144 |
secondFactor => { |
| 145 |
':uid' => { |
| 146 |
type => { |
| 147 |
':type' => 'addSecondFactorByType' |
| 148 |
}, |
| 149 |
'*' => 'addSecondFactor' |
| 150 |
}, |
| 151 |
}, |
| 152 |
}, |
| 153 |
}, |
| 154 |
['POST'] |
| 155 |
) |
| 156 |
|
| 157 |
->addRoute( |
| 158 |
api => { |
| 159 |
v1 => { |
| 160 |
providers => { |
| 161 |
oidc => { |
| 162 |
rp => { ':confKey' => 'replaceOidcRp' } |
| 163 |
}, |
| 164 |
saml => { |
| 165 |
sp => { ':confKey' => 'replaceSamlSp' } |
| 166 |
}, |
| 167 |
cas => { |
| 168 |
app => { ':confKey' => 'replaceCasApp' } |
| 169 |
}, |
| 170 |
}, |
| 171 |
menu => { |
| 172 |
cat => { ':confKey' => 'replaceMenuCat' }, |
| 173 |
app => { |
| 174 |
':confKey' => { |
| 175 |
':appConfKey' => 'replaceMenuApp' |
| 176 |
} |
| 177 |
} |
| 178 |
}, |
| 179 |
}, |
| 180 |
}, |
| 181 |
['PUT'] |
| 182 |
) |
| 183 |
|
| 184 |
->addRoute( |
| 185 |
api => { |
| 186 |
v1 => { |
| 187 |
providers => { |
| 188 |
oidc => { |
| 189 |
rp => { ':confKey' => 'updateOidcRp' } |
| 190 |
}, |
| 191 |
saml => { |
| 192 |
sp => { ':confKey' => 'updateSamlSp' } |
| 193 |
}, |
| 194 |
cas => { |
| 195 |
app => { ':confKey' => 'updateCasApp' } |
| 196 |
}, |
| 197 |
}, |
| 198 |
menu => { |
| 199 |
cat => { ':confKey' => 'updateMenuCat' }, |
| 200 |
app => { |
| 201 |
':confKey' => { |
| 202 |
':appConfKey' => 'updateMenuApp' |
| 203 |
} |
| 204 |
} |
| 205 |
}, |
| 206 |
}, |
| 207 |
}, |
| 208 |
['PATCH'] |
| 209 |
) |
| 210 |
|
| 211 |
->addRoute( |
| 212 |
api => { |
| 213 |
v1 => { |
| 214 |
providers => { |
| 215 |
oidc => { |
| 216 |
rp => { ':confKey' => 'deleteOidcRp' } |
| 217 |
}, |
| 218 |
saml => { |
| 219 |
sp => { ':confKey' => 'deleteSamlSp' } |
| 220 |
}, |
| 221 |
cas => { |
| 222 |
app => { ':confKey' => 'deleteCasApp' } |
| 223 |
}, |
| 224 |
}, |
| 225 |
secondFactor => { |
| 226 |
':uid' => { |
| 227 |
id => { |
| 228 |
':id' => 'deleteSecondFactorsById' |
| 229 |
}, |
| 230 |
type => { |
| 231 |
':type' => 'deleteSecondFactorsByType' |
| 232 |
}, |
| 233 |
'*' => 'deleteSecondFactors' |
| 234 |
}, |
| 235 |
}, |
| 236 |
menu => { |
| 237 |
cat => { ':confKey' => 'deleteMenuCat' }, |
| 238 |
app => { |
| 239 |
':confKey' => { |
| 240 |
':appConfKey' => 'deleteMenuApp' |
| 241 |
} |
| 242 |
} |
| 243 |
}, |
| 244 |
}, |
| 245 |
}, |
| 246 |
['DELETE'] |
| 247 |
); |
| 248 |
|
| 249 |
$self->setTypes($conf); |
| 250 |
$self->{multiValuesSeparator} ||= '; '; |
| 251 |
$self->{hiddenAttributes} //= "_password"; |
| 252 |
return 1; |
| 253 |
} |
| 254 |
|
| 255 |
1; |