lemonldap-ng/lemonldap-ng-manager/lib/Lemonldap/NG/Manager/Api.pm

236 lines
7.1 KiB
Perl
Raw Normal View History

2019-11-08 18:31:50 +01:00
# This module implements all the methods that responds to '/api/*' requests
package Lemonldap::NG::Manager::Api;
2020-11-21 18:19:10 +01:00
use strict;
2019-11-08 18:31:50 +01:00
use utf8;
use Mouse;
use Lemonldap::NG::Manager::Api::2F;
use Lemonldap::NG::Manager::Api::Misc;
use Lemonldap::NG::Manager::Api::Providers::OidcRp;
use Lemonldap::NG::Manager::Api::Providers::SamlSp;
use Lemonldap::NG::Manager::Api::Providers::CasApp;
use Lemonldap::NG::Manager::Api::Menu::Cat;
use Lemonldap::NG::Manager::Api::Menu::App;
2019-11-08 18:31:50 +01:00
extends qw(
Lemonldap::NG::Manager::Plugin
Lemonldap::NG::Common::Conf::RESTServer
Lemonldap::NG::Common::Session::REST
);
2020-11-21 18:19:10 +01:00
our $VERSION = '2.0.10';
2019-11-08 18:31:50 +01:00
#############################
# I. INITIALIZATION METHODS #
#############################
use constant defaultRoute => 'api.html';
2020-01-27 18:32:59 +01:00
sub init {
2019-11-08 18:31:50 +01:00
my ( $self, $conf ) = @_;
$self->ua( Lemonldap::NG::Common::UserAgent->new($conf) );
2019-11-08 18:31:50 +01:00
# HTML template
$self->addRoute( 'api.html', undef, ['GET'] )
2019-12-04 17:50:41 +01:00
->addRoute(
api => {
v1 => {
status => 'status',
providers => {
oidc => {
rp => {
findByConfKey => {
':uPattern' => 'findOidcRpByConfKey'
},
findByClientId => {
':uClientId' => 'findOidcRpByClientId'
},
':confKey' => 'getOidcRpByConfKey'
},
},
saml => {
sp => {
findByConfKey => {
':uPattern' => 'findSamlSpByConfKey'
},
findByEntityId => {
':uEntityId' => 'findSamlSpByEntityId'
},
':confKey' => 'getSamlSpByConfKey'
},
},
cas => {
app => {
findByConfKey => {
':uPattern' => 'findCasAppByConfKey'
},
findByServiceUrl => {
':uServiceUrl' => 'findCasAppsByServiceUrl'
},
':confKey' => 'getCasAppByConfKey'
},
},
2019-12-05 12:40:03 +01:00
},
secondFactor => {
':uid' => {
id => {
':id' => 'getSecondFactorsById'
},
type => {
':type' => 'getSecondFactorsByType'
},
'*' => 'getSecondFactors'
},
},
menu => {
cat => {
findByConfKey => {
':uPattern' => 'findMenuCatByConfKey'
},
':confKey' => {
'*' => 'getMenuCatByConfKey'
}
},
app => {
':confKey' => {
findByConfKey => {
':uPattern' => 'findMenuAppByConfKey'
},
':appConfKey' => 'getMenuApp'
}
},
},
2019-12-04 17:50:41 +01:00
},
},
['GET']
)
->addRoute(
api => {
v1 => {
providers => {
oidc => {
rp => 'addOidcRp'
},
saml => {
sp => 'addSamlSp'
},
cas => {
app => 'addCasApp'
},
},
menu => {
cat => 'addMenuCat',
app => {
':confKey' => 'addMenuApp'
}
},
},
},
['POST']
)
->addRoute(
api => {
v1 => {
providers => {
oidc => {
2019-12-20 11:13:15 +01:00
rp => { ':confKey' => 'replaceOidcRp' }
},
saml => {
2019-12-20 11:13:15 +01:00
sp => { ':confKey' => 'replaceSamlSp' }
},
cas => {
app => { ':confKey' => 'replaceCasApp' }
},
},
menu => {
cat => { ':confKey' => 'replaceMenuCat' },
app => {
':confKey' => {
':appConfKey' => 'replaceMenuApp'
}
}
},
},
},
['PUT']
)
->addRoute(
api => {
v1 => {
providers => {
oidc => {
2019-12-20 11:13:15 +01:00
rp => { ':confKey' => 'updateOidcRp' }
},
saml => {
2019-12-20 11:13:15 +01:00
sp => { ':confKey' => 'updateSamlSp' }
},
cas => {
app => { ':confKey' => 'updateCasApp' }
},
},
menu => {
cat => { ':confKey' => 'updateMenuCat' },
app => {
':confKey' => {
':appConfKey' => 'updateMenuApp'
}
}
},
},
},
['PATCH']
)
->addRoute(
api => {
v1 => {
providers => {
oidc => {
2019-12-20 11:13:15 +01:00
rp => { ':confKey' => 'deleteOidcRp' }
},
saml => {
2019-12-20 11:13:15 +01:00
sp => { ':confKey' => 'deleteSamlSp' }
},
cas => {
app => { ':confKey' => 'deleteCasApp' }
},
},
secondFactor => {
':uid' => {
id => {
':id' => 'deleteSecondFactorsById'
},
type => {
':type' => 'deleteSecondFactorsByType'
},
'*' => 'deleteSecondFactors'
},
},
menu => {
cat => { ':confKey' => 'deleteMenuCat' },
app => {
':confKey' => {
':appConfKey' => 'deleteMenuApp'
}
}
},
},
},
['DELETE']
2019-11-08 18:31:50 +01:00
);
2019-12-20 11:13:15 +01:00
$self->setTypes($conf);
$self->{multiValuesSeparator} ||= '; ';
$self->{hiddenAttributes} //= "_password";
$self->{TOTPCheck} = $self->{U2FCheck} = $self->{UBKCheck} = '1';
2020-01-27 18:32:59 +01:00
return 1;
2019-12-04 17:50:41 +01:00
}
2019-11-08 18:31:50 +01:00
1;