feat: simplify architecture
This commit is contained in:
parent
133fa840e7
commit
362ab2b4c1
34 changed files with 1997 additions and 3236 deletions
|
@ -1 +1 @@
|
|||
{"php":"7.3.33","version":"3.4.0:v3.4.0#47177af1cfb9dab5d1cc4daf91b7179c2efe7fad","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces":{"position_after_anonymous_constructs":"same","position_after_control_structures":"same","position_after_functions_and_oop_constructs":"same"},"class_definition":true,"constant_case":true,"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"no_break_comment":true,"no_closing_tag":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["property","method","const"]},"align_multiline_comment":true,"array_indentation":true,"binary_operator_spaces":{"default":"single_space"},"blank_line_after_opening_tag":true,"no_unused_imports":true},"hashes":{"appinfo\/routes.php":3044887257,"lib\/Responses\/SCIMJSONResponse.php":2876810868,"lib\/Responses\/SCIMListResponse.php":76345573,"lib\/Responses\/SCIMErrorResponse.php":1118832559,"lib\/Controller\/ASCIMGroup.php":3712028548,"lib\/Controller\/UserController.php":2528458696,"lib\/Controller\/ASCIMUser.php":430477040,"lib\/Controller\/GroupController.php":3769468563}}
|
||||
{"php":"8.3.2","version":"3.48.0","indent":"\t","lineEnding":"\n","rules":{"encoding":true,"full_opening_tag":true,"blank_line_after_namespace":true,"braces_position":true,"class_definition":true,"constant_case":true,"control_structure_braces":true,"control_structure_continuation_position":true,"elseif":true,"function_declaration":{"closure_function_spacing":"one"},"indentation_type":true,"line_ending":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ignore"},"no_break_comment":true,"no_closing_tag":true,"no_multiple_statements_per_line":true,"no_space_around_double_colon":true,"no_spaces_after_function_name":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"spaces_inside_parentheses":true,"statement_indentation":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":{"elements":["property","method","const"]},"align_multiline_comment":true,"array_indentation":true,"binary_operator_spaces":{"default":"single_space"},"blank_line_after_opening_tag":true,"curly_braces_position":{"classes_opening_brace":"same_line","functions_opening_brace":"same_line"},"no_spaces_inside_parenthesis":true,"no_unused_imports":true,"ordered_imports":{"imports_order":["class","function","const"],"sort_algorithm":"alpha"}},"hashes":{"appinfo\/routes.php":"a6daac024d42530db25f8a0ef4e4b8fc","lib\/Controller\/GroupController.php":"c43793525f75ed56acbcdebae283ef1d","lib\/Controller\/ServiceProviderConfigurationController.php":"23f9ec133052c11f256873834d9e9a37","lib\/Controller\/UserController.php":"ce6845e793cb2d8af28ee9c411530b37","lib\/Responses\/SCIMJSONResponse.php":"7218478fc8e0eb92ce29236825a8c17a","lib\/Responses\/SCIMListResponse.php":"bccc6e1cb2ef0be0745c89dfe9c50635","lib\/Responses\/SCIMErrorResponse.php":"4b57fdb473f7172c748ed7baeae5f425","lib\/Service\/GroupService.php":"150281b6627a71fa5880992346575210","lib\/Service\/UserService.php":"4d9ed2664130e74d688acc2f3c364ebf","lib\/AppInfo\/Application.php":"6f51c1b09b83ffea7a7bebf34fc45aa9","lib\/Exception\/AuthException.php":"74af2c0e26c689eb5718d43f6bfcf0a0","lib\/Exception\/ContentTypeException.php":"38395fd6b2287f4a8eead0584133f194","lib\/Middleware\/ContentTypeMiddleware.php":"4b947c369e511e4bd6be652827393aa5","lib\/Middleware\/AuthMiddleware.php":"dd7b9c27697ce77f6c4284f822b1a815","lib\/Middleware\/ErrorMiddleware.php":"ccb5c3a607517e9e98386a58a2ae63b5","lib\/Util\/Util.php":"75a45e4c37bcc6dfbcdcdd4387662a8d"}}
|
661
LICENSE
Normal file
661
LICENSE
Normal file
|
@ -0,0 +1,661 @@
|
|||
GNU AFFERO GENERAL PUBLIC LICENSE
|
||||
Version 3, 19 November 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU Affero General Public License is a free, copyleft license for
|
||||
software and other kinds of works, specifically designed to ensure
|
||||
cooperation with the community in the case of network server software.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
our General Public Licenses are intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
Developers that use our General Public Licenses protect your rights
|
||||
with two steps: (1) assert copyright on the software, and (2) offer
|
||||
you this License which gives you legal permission to copy, distribute
|
||||
and/or modify the software.
|
||||
|
||||
A secondary benefit of defending all users' freedom is that
|
||||
improvements made in alternate versions of the program, if they
|
||||
receive widespread use, become available for other developers to
|
||||
incorporate. Many developers of free software are heartened and
|
||||
encouraged by the resulting cooperation. However, in the case of
|
||||
software used on network servers, this result may fail to come about.
|
||||
The GNU General Public License permits making a modified version and
|
||||
letting the public access it on a server without ever releasing its
|
||||
source code to the public.
|
||||
|
||||
The GNU Affero General Public License is designed specifically to
|
||||
ensure that, in such cases, the modified source code becomes available
|
||||
to the community. It requires the operator of a network server to
|
||||
provide the source code of the modified version running there to the
|
||||
users of that server. Therefore, public use of a modified version, on
|
||||
a publicly accessible server, gives the public access to the source
|
||||
code of the modified version.
|
||||
|
||||
An older license, called the Affero General Public License and
|
||||
published by Affero, was designed to accomplish similar goals. This is
|
||||
a different license, not a version of the Affero GPL, but Affero has
|
||||
released a new version of the Affero GPL which permits relicensing under
|
||||
this license.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU Affero General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Remote Network Interaction; Use with the GNU General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, if you modify the
|
||||
Program, your modified version must prominently offer all users
|
||||
interacting with it remotely through a computer network (if your version
|
||||
supports such interaction) an opportunity to receive the Corresponding
|
||||
Source of your version by providing access to the Corresponding Source
|
||||
from a network server at no charge, through some standard or customary
|
||||
means of facilitating copying of software. This Corresponding Source
|
||||
shall include the Corresponding Source for any work covered by version 3
|
||||
of the GNU General Public License that is incorporated pursuant to the
|
||||
following paragraph.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the work with which it is combined will remain governed by version
|
||||
3 of the GNU General Public License.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU Affero General Public License from time to time. Such new versions
|
||||
will be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU Affero General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU Affero General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU Affero General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If your software can interact with users remotely through a computer
|
||||
network, you should also make sure that it provides a way for users to
|
||||
get its source. For example, if your program is a web application, its
|
||||
interface could display a "Source" link that leads users to an archive
|
||||
of the code. There are many ways you could offer source, and different
|
||||
solutions will be better for different programs; see section 13 for the
|
||||
specific requirements.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU AGPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
|
@ -5,13 +5,14 @@
|
|||
<name>SCIM Service Provider</name>
|
||||
<summary>Implements SCIM protocol as a Service Provider</summary>
|
||||
<description><![CDATA[This app allows to sync users and groups from a scim client.]]></description>
|
||||
<version>0.0.1</version>
|
||||
<version>1.0.0-alpha.0</version>
|
||||
<licence>agpl</licence>
|
||||
<author mail="pierre@ozoux.net" >Pierre Ozoux</author>
|
||||
<author mail="contact@indiehosters.net" homepage="https://indiehosters.net/">IndieHosters</author>
|
||||
<author homepage="https://www.audriga.com/">Audriga</author>
|
||||
<namespace>SCIMServiceProvider</namespace>
|
||||
<category>integration</category>
|
||||
<bugs>https://lab.libreho.st/libre.sh/docker/nextcloud/</bugs>
|
||||
<bugs>https://lab.libreho.st/libre.sh/scim/scimserviceprovider</bugs>
|
||||
<dependencies>
|
||||
<nextcloud min-version="22" max-version="22"/>
|
||||
<nextcloud min-version="26" max-version="28"/>
|
||||
</dependencies>
|
||||
</info>
|
||||
|
|
|
@ -1,46 +1,21 @@
|
|||
<?php
|
||||
|
||||
$routes = [
|
||||
return [
|
||||
'routes' => [
|
||||
['name' => 'service_provider_configuration#resource_types', 'url' => '/ResourceTypes', 'verb' => 'GET'],
|
||||
['name' => 'service_provider_configuration#schemas', 'url' => '/Schemas', 'verb' => 'GET'],
|
||||
['name' => 'service_provider_configuration#service_provider_config', 'url' => '/ServiceProviderConfig', 'verb' => 'GET'],
|
||||
|
||||
['name' => 'user#index', 'url' => '/Users', 'verb' => 'GET'],
|
||||
['name' => 'user#show', 'url' => '/Users/{id}', 'verb' => 'GET'],
|
||||
['name' => 'user#create', 'url' => '/Users', 'verb' => 'POST'],
|
||||
['name' => 'user#update', 'url' => '/Users/{id}', 'verb' => 'PUT'],
|
||||
['name' => 'user#destroy', 'url' => '/Users/{id}', 'verb' => 'DELETE'],
|
||||
|
||||
['name' => 'group#index', 'url' => '/Groups', 'verb' => 'GET'],
|
||||
['name' => 'group#show', 'url' => '/Groups/{id}', 'verb' => 'GET'],
|
||||
['name' => 'group#create', 'url' => '/Groups', 'verb' => 'POST'],
|
||||
['name' => 'group#update', 'url' => '/Groups/{id}', 'verb' => 'PUT'],
|
||||
['name' => 'group#destroy', 'url' => '/Groups/{id}', 'verb' => 'DELETE'],
|
||||
]
|
||||
];
|
||||
|
||||
$config = require dirname(__DIR__) . '/lib/Config/config.php';
|
||||
$userAndGroupRoutes = [];
|
||||
|
||||
if (isset($config['auth_type']) && !empty($config['auth_type']) && (strcmp($config['auth_type'], 'bearer') === 0)) {
|
||||
$userAndGroupRoutes = [
|
||||
['name' => 'user_bearer#index', 'url' => '/bearer/Users', 'verb' => 'GET'],
|
||||
['name' => 'user_bearer#show', 'url' => '/bearer/Users/{id}', 'verb' => 'GET'],
|
||||
['name' => 'user_bearer#create', 'url' => '/bearer/Users', 'verb' => 'POST'],
|
||||
['name' => 'user_bearer#update', 'url' => '/bearer/Users/{id}', 'verb' => 'PUT'],
|
||||
['name' => 'user_bearer#destroy', 'url' => '/bearer/Users/{id}', 'verb' => 'DELETE'],
|
||||
|
||||
['name' => 'group_bearer#index', 'url' => '/bearer/Groups', 'verb' => 'GET'],
|
||||
['name' => 'group_bearer#show', 'url' => '/bearer/Groups/{id}', 'verb' => 'GET'],
|
||||
['name' => 'group_bearer#create', 'url' => '/bearer/Groups', 'verb' => 'POST'],
|
||||
['name' => 'group_bearer#update', 'url' => '/bearer/Groups/{id}', 'verb' => 'PUT'],
|
||||
['name' => 'group_bearer#destroy', 'url' => '/bearer/Groups/{id}', 'verb' => 'DELETE'],
|
||||
];
|
||||
} else if (!isset($config['auth_type']) || empty($config['auth_type']) || (strcmp($config['auth_type'], 'basic') === 0)) {
|
||||
$userAndGroupRoutes = [
|
||||
['name' => 'user#index', 'url' => '/Users', 'verb' => 'GET'],
|
||||
['name' => 'user#show', 'url' => '/Users/{id}', 'verb' => 'GET'],
|
||||
['name' => 'user#create', 'url' => '/Users', 'verb' => 'POST'],
|
||||
['name' => 'user#update', 'url' => '/Users/{id}', 'verb' => 'PUT'],
|
||||
['name' => 'user#destroy', 'url' => '/Users/{id}', 'verb' => 'DELETE'],
|
||||
|
||||
['name' => 'group#index', 'url' => '/Groups', 'verb' => 'GET'],
|
||||
['name' => 'group#show', 'url' => '/Groups/{id}', 'verb' => 'GET'],
|
||||
['name' => 'group#create', 'url' => '/Groups', 'verb' => 'POST'],
|
||||
['name' => 'group#update', 'url' => '/Groups/{id}', 'verb' => 'PUT'],
|
||||
['name' => 'group#destroy', 'url' => '/Groups/{id}', 'verb' => 'DELETE'],
|
||||
];
|
||||
}
|
||||
|
||||
$routes['routes'] = array_merge($routes['routes'], $userAndGroupRoutes);
|
||||
|
||||
return $routes;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{
|
||||
"require-dev": {
|
||||
"vimeo/psalm": "^4.23",
|
||||
"christophwurst/nextcloud": "v22.1.1",
|
||||
"nextcloud/coding-standard": "^1.0"
|
||||
"nextcloud/ocp": "v26.0.9",
|
||||
"nextcloud/coding-standard": "^1.1"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
|
|
1644
composer.lock
generated
1644
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -1,110 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Adapter\Groups;
|
||||
|
||||
use OCP\IGroup;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use Opf\Adapters\AbstractAdapter;
|
||||
use Opf\Models\SCIM\Standard\Groups\CoreGroup;
|
||||
use Opf\Models\SCIM\Standard\MultiValuedAttribute;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class NextcloudGroupAdapter extends AbstractAdapter
|
||||
{
|
||||
/** @var Psr\Log\LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
$this->userManager = $container->get(IUserManager::class);
|
||||
$this->request = $container->get(IRequest::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an NC group into a SCIM group
|
||||
*/
|
||||
public function getCoreGroup(?IGroup $ncGroup): ?CoreGroup
|
||||
{
|
||||
$this->logger->debug(
|
||||
"[" . NextcloudGroupAdapter::class . "] entering getCoreGroup() method"
|
||||
);
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . "/index.php/apps/scimserviceprovider";
|
||||
|
||||
if (!isset($ncGroup)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupAdapter::class . "] passed NC group in getCoreGroup() method is null"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$coreGroup = new CoreGroup();
|
||||
$coreGroup->setId($ncGroup->getGID());
|
||||
$coreGroup->setDisplayName($ncGroup->getDisplayName());
|
||||
|
||||
$ncGroupMembers = $ncGroup->getUsers();
|
||||
|
||||
if (isset($ncGroupMembers) && !empty($ncGroupMembers)) {
|
||||
$coreGroupMembers = [];
|
||||
|
||||
foreach ($ncGroupMembers as $ncGroupMember) {
|
||||
$coreGroupMember = new MultiValuedAttribute();
|
||||
$coreGroupMember->setValue($ncGroupMember->getUID());
|
||||
$coreGroupMember->setRef($baseUrl . "/Users/" . $ncGroupMember->getUID());
|
||||
$coreGroupMember->setDisplay($ncGroupMember->getDisplayName());
|
||||
|
||||
$coreGroupMembers[] = $coreGroupMember;
|
||||
}
|
||||
|
||||
$coreGroup->setMembers($coreGroupMembers);
|
||||
}
|
||||
|
||||
return $coreGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a SCIM group into an NC group
|
||||
*
|
||||
* Note: the second parameter is needed, since we can't instantiate an NC group
|
||||
* ourselves and need to receive an instance, passed from somewhere
|
||||
*/
|
||||
public function getNCGroup(?CoreGroup $coreGroup, IGroup $ncGroup): ?IGroup
|
||||
{
|
||||
$this->logger->debug(
|
||||
"[" . NextcloudGroupAdapter::class . "] entering getNCGroup() method"
|
||||
);
|
||||
|
||||
if (!isset($coreGroup) || !isset($ncGroup)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupAdapter::class . "] passed Core Group in getNCGroup() method is null"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$ncGroup->setDisplayName($coreGroup->getDisplayName());
|
||||
|
||||
if ($coreGroup->getMembers() !== null && !empty($coreGroup->getMembers())) {
|
||||
foreach ($coreGroup->getMembers() as $coreGroupMember) {
|
||||
// If user with this uid exists, then add it as a member of the group
|
||||
if ($coreGroupMember->getValue() !== null && !empty($coreGroupMember->getValue())) {
|
||||
if ($this->userManager->userExists($coreGroupMember->getValue())) {
|
||||
$ncGroup->addUser($this->userManager->get($coreGroupMember->getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ncGroup;
|
||||
}
|
||||
}
|
|
@ -1,125 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Adapter\Users;
|
||||
|
||||
use OCA\SCIMServiceProvider\AppInfo\Application;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Opf\Adapters\AbstractAdapter;
|
||||
use Opf\Models\SCIM\Standard\MultiValuedAttribute;
|
||||
use Opf\Models\SCIM\Standard\Users\CoreUser;
|
||||
use Opf\Models\SCIM\Standard\Users\Name;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class NextcloudUserAdapter extends AbstractAdapter
|
||||
{
|
||||
/** @var Psr\Log\LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var ISecureRandom */
|
||||
private $secureRandom;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
$this->config = $container->get(IConfig::class);
|
||||
$this->userManager = $container->get(IUserManager::class);
|
||||
$this->secureRandom = $container->get(ISecureRandom::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform an NC User into a SCIM user
|
||||
*/
|
||||
public function getCoreUser(?IUser $ncUser): ?CoreUser
|
||||
{
|
||||
$this->logger->debug(
|
||||
"[" . NextcloudUserAdapter::class . "] entering getCoreUser() method"
|
||||
);
|
||||
|
||||
if (!isset($ncUser)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserAdapter::class . "] passed NC user in getCoreUser() method is null"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$coreUser = new CoreUser();
|
||||
$coreUser->setId($ncUser->getUID());
|
||||
|
||||
$coreUserName = new Name();
|
||||
$coreUserName->setFormatted($ncUser->getDisplayName());
|
||||
$coreUser->setName($coreUserName);
|
||||
|
||||
$coreUser->setUserName($ncUser->getUID());
|
||||
$coreUser->setDisplayName($ncUser->getDisplayName());
|
||||
$coreUser->setActive($ncUser->isEnabled());
|
||||
|
||||
$ncUserExternalId = $this->config->getUserValue($ncUser->getUID(), Application::APP_ID, 'externalId', '');
|
||||
$coreUser->setExternalId($ncUserExternalId);
|
||||
|
||||
if ($ncUser->getEMailAddress() !== null && !empty($ncUser->getEMailAddress())) {
|
||||
$coreUserEmail = new MultiValuedAttribute();
|
||||
$coreUserEmail->setValue($ncUser->getEMailAddress());
|
||||
$coreUserEmail->setPrimary(true);
|
||||
|
||||
$coreUser->setEmails(array($coreUserEmail));
|
||||
}
|
||||
|
||||
return $coreUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transform a SCIM user into an NC User
|
||||
*
|
||||
* Note: we need the second parameter, since we can't instantiate an NC user in PHP
|
||||
* ourselves and need to receive an instance that we can populate with data from the SCIM user
|
||||
*/
|
||||
public function getNCUser(?CoreUser $coreUser, IUser $ncUser): ?IUser
|
||||
{
|
||||
$this->logger->debug(
|
||||
"[" . NextcloudUserAdapter::class . "] entering getNCUser() method"
|
||||
);
|
||||
|
||||
if (!isset($coreUser) || !isset($ncUser)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserAdapter::class . "] passed Core User in getNCUser() method is null"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($coreUser->getDisplayName() !== null && !empty($coreUser->getDisplayName())) {
|
||||
$ncUser->setDisplayName($coreUser->getDisplayName());
|
||||
}
|
||||
|
||||
if ($coreUser->getActive() !== null) {
|
||||
$ncUser->setEnabled($coreUser->getActive());
|
||||
}
|
||||
|
||||
if ($coreUser->getExternalId() !== null && !empty($coreUser->getExternalId())) {
|
||||
$this->config->setUserValue($ncUser->getUID(), Application::APP_ID, 'externalId', $coreUser->getExternalId());
|
||||
}
|
||||
|
||||
if ($coreUser->getEmails() !== null && !empty($coreUser->getEmails())) {
|
||||
// Here, we use the first email of the SCIM user to set as the NC user's email
|
||||
// TODO: is this ok or should we rather first iterate and search for a primary email of the SCIM user
|
||||
if ($coreUser->getEmails()[0] !== null && !empty($coreUser->getEmails()[0])) {
|
||||
if ($coreUser->getEmails()[0]->getValue() !== null && !empty($coreUser->getEmails()[0]->getValue())) {
|
||||
$ncUser->setEMailAddress($coreUser->getEmails()[0]->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ncUser;
|
||||
}
|
||||
}
|
|
@ -2,160 +2,43 @@
|
|||
|
||||
namespace OCA\SCIMServiceProvider\AppInfo;
|
||||
|
||||
use Error;
|
||||
use OCA\SCIMServiceProvider\Adapter\Groups\NextcloudGroupAdapter;
|
||||
use OCA\SCIMServiceProvider\Adapter\Users\NextcloudUserAdapter;
|
||||
use OCA\SCIMServiceProvider\Controller\GroupBearerController;
|
||||
use OCA\SCIMServiceProvider\Controller\GroupController;
|
||||
use OCA\SCIMServiceProvider\Controller\UserBearerController;
|
||||
use OCA\SCIMServiceProvider\Controller\UserController;
|
||||
use OCA\SCIMServiceProvider\DataAccess\Groups\NextcloudGroupDataAccess;
|
||||
use OCA\SCIMServiceProvider\DataAccess\Users\NextcloudUserDataAccess;
|
||||
use OCA\SCIMServiceProvider\Middleware\BearerAuthMiddleware;
|
||||
use OCA\SCIMServiceProvider\Repositories\Groups\NextcloudGroupRepository;
|
||||
use OCA\SCIMServiceProvider\Repositories\Users\NextcloudUserRepository;
|
||||
use OCA\SCIMServiceProvider\Service\GroupService;
|
||||
use OCA\SCIMServiceProvider\Service\SCIMGroup;
|
||||
use OCA\SCIMServiceProvider\Service\SCIMUser;
|
||||
use OCA\SCIMServiceProvider\Service\UserService;
|
||||
use OCA\SCIMServiceProvider\Util\Authentication\BearerAuthenticator;
|
||||
use OCA\SCIMServiceProvider\Middleware\AuthMiddleware;
|
||||
use OCA\SCIMServiceProvider\Middleware\ContentTypeMiddleware;
|
||||
use OCA\SCIMServiceProvider\Middleware\ErrorMiddleware;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\AppFramework\Bootstrap\IBootContext;
|
||||
use OCP\AppFramework\Bootstrap\IBootstrap;
|
||||
use OCP\AppFramework\Bootstrap\IRegistrationContext;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Opf\Util\Util;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
/**
|
||||
* The main entry point of the entire application
|
||||
*/
|
||||
class Application extends App implements IBootstrap
|
||||
{
|
||||
public const APP_ID = 'scimserviceprovider';
|
||||
class Application extends App implements IBootstrap {
|
||||
public const APP_ID = 'scimserviceprovider';
|
||||
public const APP_NAME = 'SCIM';
|
||||
|
||||
public function __construct(array $urlParams = [])
|
||||
{
|
||||
parent::__construct(self::APP_ID, $urlParams);
|
||||
}
|
||||
public function __construct() {
|
||||
parent::__construct(self::APP_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is used for registering services, needed as dependencies via dependency injection (DI)
|
||||
*
|
||||
* Note: "service" here means simply a class that is needed as a dependency somewhere
|
||||
* and needs to be injected as such via a DI container (as per PSR-11)
|
||||
*/
|
||||
public function register(IRegistrationContext $context): void
|
||||
{
|
||||
require realpath(dirname(__DIR__) . '/../vendor/autoload.php');
|
||||
$config = require dirname(__DIR__) . '/Config/config.php';
|
||||
$context->registerService('SCIMUser', function(ContainerInterface $c) {
|
||||
return new SCIMUser(
|
||||
$c->get(IUserManager::class),
|
||||
$c->get(IConfig::class)
|
||||
);
|
||||
});
|
||||
/**
|
||||
* This method is used for registering services, needed as dependencies via dependency injection (DI)
|
||||
*
|
||||
* Note: "service" here means simply a class that is needed as a dependency somewhere
|
||||
* and needs to be injected as such via a DI container (as per PSR-11)
|
||||
*/
|
||||
public function register(IRegistrationContext $context): void {
|
||||
require_once(__DIR__ . '/../../vendor/autoload.php');
|
||||
$context->registerMiddleware(ErrorMiddleware::class);
|
||||
$context->registerMiddleware(AuthMiddleware::class);
|
||||
$context->registerMiddleware(ContentTypeMiddleware::class);
|
||||
}
|
||||
|
||||
$context->registerService(UserService::class, function(ContainerInterface $c) {
|
||||
return new UserService($c);
|
||||
});
|
||||
|
||||
$context->registerService(GroupService::class, function(ContainerInterface $c) {
|
||||
return new GroupService($c);
|
||||
});
|
||||
|
||||
$context->registerService('UserRepository', function(ContainerInterface $c) {
|
||||
return new NextcloudUserRepository($c);
|
||||
});
|
||||
|
||||
$context->registerService('UserAdapter', function(ContainerInterface $c) {
|
||||
return new NextcloudUserAdapter($c);
|
||||
});
|
||||
|
||||
$context->registerService('UserDataAccess', function(ContainerInterface $c) {
|
||||
return new NextcloudUserDataAccess($c);
|
||||
});
|
||||
|
||||
|
||||
$context->registerService('SCIMGroup', function(ContainerInterface $c) {
|
||||
return new SCIMGroup(
|
||||
$c->get(IGroupManager::class)
|
||||
);
|
||||
});
|
||||
|
||||
$context->registerService('GroupRepository', function(ContainerInterface $c) {
|
||||
return new NextcloudGroupRepository($c);
|
||||
});
|
||||
|
||||
$context->registerService('GroupAdapter', function(ContainerInterface $c) {
|
||||
return new NextcloudGroupAdapter($c);
|
||||
});
|
||||
|
||||
$context->registerService('GroupDataAccess', function(ContainerInterface $c) {
|
||||
return new NextcloudGroupDataAccess($c);
|
||||
});
|
||||
|
||||
if (isset($config['auth_type']) && !empty($config['auth_type']) && (strcmp($config['auth_type'], 'bearer') === 0)) {
|
||||
// If the auth_type is set to "bearer", then use Bearer token endpoints
|
||||
// For bearer tokens, we also need to register the bearer token auth middleware
|
||||
$context->registerService(BearerAuthenticator::class, function(ContainerInterface $c) {
|
||||
return new BearerAuthenticator($c);
|
||||
});
|
||||
|
||||
$context->registerService(BearerAuthMiddleware::class, function(ContainerInterface $c) {
|
||||
return new BearerAuthMiddleware($c);
|
||||
});
|
||||
|
||||
$context->registerMiddleware(BearerAuthMiddleware::class);
|
||||
|
||||
$context->registerService(UserBearerController::class, function (ContainerInterface $c) {
|
||||
return new UserBearerController(
|
||||
self::APP_ID,
|
||||
$c->get(IRequest::class),
|
||||
$c->get(UserService::class)
|
||||
);
|
||||
});
|
||||
|
||||
$context->registerService(GroupBearerController::class, function (ContainerInterface $c) {
|
||||
return new GroupBearerController(
|
||||
self::APP_ID,
|
||||
$c->get(IRequest::class),
|
||||
$c->get(GroupService::class)
|
||||
);
|
||||
});
|
||||
} else if (!isset($config['auth_type']) || empty($config['auth_type']) || (strcmp($config['auth_type'], 'basic') === 0)) {
|
||||
// Otherwise, if auth_type is set to "basic" or if it's not set at all, use Basic auth
|
||||
$context->registerService(UserController::class, function (ContainerInterface $c) {
|
||||
return new UserController(
|
||||
self::APP_ID,
|
||||
$c->get(IRequest::class),
|
||||
$c->get(UserService::class)
|
||||
);
|
||||
});
|
||||
|
||||
$context->registerService(GroupController::class, function (ContainerInterface $c) {
|
||||
return new GroupController(
|
||||
self::APP_ID,
|
||||
$c->get(IRequest::class),
|
||||
$c->get(GroupService::class)
|
||||
);
|
||||
});
|
||||
} else {
|
||||
// In the case of any other auth_type value, complain with an error message
|
||||
throw new Error("Unknown auth type was set in config file");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called for starting (i.e., booting) the application
|
||||
*
|
||||
* Note: here the method body is empty, since we don't need to do any extra work in it
|
||||
*/
|
||||
public function boot(IBootContext $context): void
|
||||
{
|
||||
}
|
||||
/**
|
||||
* This method is called for starting (i.e., booting) the application
|
||||
*
|
||||
* Note: here the method body is empty, since we don't need to do any extra work in it
|
||||
*/
|
||||
public function boot(IBootContext $context): void {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,14 +0,0 @@
|
|||
<?php
|
||||
|
||||
return [
|
||||
/**
|
||||
* Allowed value are 'basic' (for Basic Auth) and 'bearer' (for Bearer Token Auth)
|
||||
* The value 'basic' can be considered the default one
|
||||
*/
|
||||
'auth_type' => 'bearer',
|
||||
|
||||
// Config values for JWTs
|
||||
'jwt' => [
|
||||
'secret' => 'secret'
|
||||
]
|
||||
];
|
|
@ -1,99 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IRequest;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Service\GroupService;
|
||||
|
||||
class GroupBearerController extends ApiController
|
||||
{
|
||||
/** @var GroupService */
|
||||
private $groupService;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
GroupService $groupService
|
||||
) {
|
||||
parent::__construct(
|
||||
$appName,
|
||||
$request
|
||||
);
|
||||
|
||||
$this->groupService = $groupService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $filter
|
||||
* @return SCIMListResponse
|
||||
* returns a list of groups and their data
|
||||
*/
|
||||
public function index(string $filter = ''): SCIMListResponse
|
||||
{
|
||||
return $this->groupService->getAll($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* gets group info
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
// TODO: Add filtering support here as well
|
||||
public function show(string $id): SCIMJSONResponse
|
||||
{
|
||||
return $this->groupService->getOneById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $displayName
|
||||
* @param array $members
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function create(string $displayName = '', array $members = []): SCIMJSONResponse
|
||||
{
|
||||
return $this->groupService->create($displayName, $members);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @param string $displayName
|
||||
* @param array $members
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function update(string $id, string $displayName = '', array $members = []): SCIMJSONResponse
|
||||
{
|
||||
return $this->groupService->update($id, $displayName, $members);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(string $id): Response
|
||||
{
|
||||
return $this->groupService->destroy($id);
|
||||
}
|
||||
}
|
|
@ -4,91 +4,107 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Service\GroupService;
|
||||
use OCA\SCIMServiceProvider\Util\Util;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IRequest;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Service\GroupService;
|
||||
use Opf\Models\SCIM\Standard\Groups\CoreGroup;
|
||||
|
||||
class GroupController extends ApiController
|
||||
{
|
||||
/** @var GroupService */
|
||||
private $groupService;
|
||||
class GroupController extends ApiController {
|
||||
private GroupService $groupService;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
GroupService $groupService
|
||||
) {
|
||||
parent::__construct(
|
||||
$appName,
|
||||
$request
|
||||
);
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
GroupService $groupService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->groupService = $groupService;
|
||||
}
|
||||
$this->groupService = $groupService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $filter
|
||||
* @return SCIMListResponse
|
||||
* returns a list of groups and their data
|
||||
*/
|
||||
public function index(string $filter = ''): SCIMListResponse
|
||||
{
|
||||
return $this->groupService->getAll($filter);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @return SCIMListResponse
|
||||
*/
|
||||
public function index(): SCIMJSONResponse {
|
||||
$params = $this->request->getParams();
|
||||
$params = Util::parsePagination($params);
|
||||
$scimGroups = $this->groupService->getAll($params["startIndex"], $params["count"]);
|
||||
$list = [];
|
||||
foreach ($scimGroups as $scimGroup) {
|
||||
$list[] = $scimGroup->toSCIM(false, Util::getBaseUrl($this->request));
|
||||
}
|
||||
$total = $this->groupService->countAll();
|
||||
return new SCIMListResponse($list, $params["startIndex"], $total);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* gets group info
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
// TODO: Add filtering support here as well
|
||||
public function show(string $id): SCIMJSONResponse
|
||||
{
|
||||
return $this->groupService->getOneById($id);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
// TODO: Add filtering support here as well
|
||||
public function show(string $id): SCIMJSONResponse {
|
||||
$scimGroup = $this->groupService->get($id);
|
||||
return new SCIMJSONResponse($scimGroup->toSCIM(false, Util::getBaseUrl($this->request)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $displayName
|
||||
* @param array $members
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function create(string $displayName = '', array $members = []): SCIMJSONResponse
|
||||
{
|
||||
return $this->groupService->create($displayName, $members);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $displayName
|
||||
* @param array $members
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
// public function create(string $displayName, array $members = []): SCIMJSONResponse
|
||||
public function create(): SCIMJSONResponse {
|
||||
$params = $this->request->getParams();
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @param string $displayName
|
||||
* @param array $members
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function update(string $id, string $displayName = '', array $members = []): SCIMJSONResponse
|
||||
{
|
||||
return $this->groupService->update($id, $displayName, $members);
|
||||
}
|
||||
$scimGroup = new CoreGroup();
|
||||
$scimGroup->fromSCIM($params);
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(string $id): Response
|
||||
{
|
||||
return $this->groupService->destroy($id);
|
||||
}
|
||||
$scimGroup = $this->groupService->create($scimGroup);
|
||||
return new SCIMJSONResponse($scimGroup->toSCIM(false, Util::getBaseUrl($this->request)), 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function update(string $id): SCIMJSONResponse {
|
||||
$params = $this->request->getParams();
|
||||
|
||||
$scimGroup = new CoreGroup();
|
||||
$scimGroup->fromSCIM($params);
|
||||
|
||||
$scimGroup = $this->groupService->update($id, $scimGroup);
|
||||
return new SCIMJSONResponse($scimGroup->toSCIM(false, Util::getBaseUrl($this->request)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(string $id): Response {
|
||||
$this->groupService->destroy($id);
|
||||
|
||||
$response = new Response();
|
||||
$response->setStatus(204);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,50 +12,46 @@ use OCP\IRequest;
|
|||
use Opf\Util\Util as SCIMUtil;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class ServiceProviderConfigurationController extends ApiController
|
||||
{
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
class ServiceProviderConfigurationController extends ApiController {
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
LoggerInterface $logger) {
|
||||
parent::__construct($appName,
|
||||
$request);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
LoggerInterface $logger,
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*/
|
||||
public function resourceTypes(): SCIMListResponse
|
||||
{
|
||||
$baseUrl =
|
||||
$this->request->getServerProtocol() . "://"
|
||||
. $this->request->getServerHost() . "/"
|
||||
. Util::SCIM_APP_URL_PATH;
|
||||
$resourceTypes = SCIMUtil::getResourceTypes($baseUrl);
|
||||
return new SCIMListResponse($resourceTypes);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*/
|
||||
public function resourceTypes(): SCIMListResponse {
|
||||
$baseUrl =
|
||||
$this->request->getServerProtocol() . "://"
|
||||
. $this->request->getServerHost() . "/"
|
||||
. Util::SCIM_APP_URL_PATH;
|
||||
$resourceTypes = SCIMUtil::getResourceTypes($baseUrl);
|
||||
return new SCIMListResponse($resourceTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*/
|
||||
public function schemas(): SCIMListResponse
|
||||
{
|
||||
$schemas = SCIMUtil::getSchemas();
|
||||
return new SCIMListResponse($schemas);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*/
|
||||
public function schemas(): SCIMListResponse {
|
||||
$schemas = SCIMUtil::getSchemas();
|
||||
return new SCIMListResponse($schemas);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*/
|
||||
public function serviceProviderConfig(): SCIMJSONResponse
|
||||
{
|
||||
$serviceProviderConfig = SCIMUtil::getServiceProviderConfig();
|
||||
return new SCIMJSONResponse($serviceProviderConfig);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*/
|
||||
public function serviceProviderConfig(): SCIMJSONResponse {
|
||||
$serviceProviderConfig = SCIMUtil::getServiceProviderConfig();
|
||||
return new SCIMJSONResponse($serviceProviderConfig);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IRequest;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Service\UserService;
|
||||
|
||||
class UserBearerController extends ApiController
|
||||
{
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
UserService $userService
|
||||
) {
|
||||
parent::__construct(
|
||||
$appName,
|
||||
$request
|
||||
);
|
||||
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $filter
|
||||
* @return SCIMListResponse
|
||||
* returns a list of users and their data
|
||||
*/
|
||||
public function index(string $filter = ''): SCIMListResponse
|
||||
{
|
||||
return $this->userService->getAll($filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* gets user info
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
// TODO: Add filtering support here as well
|
||||
public function show(string $id): SCIMJSONResponse
|
||||
{
|
||||
return $this->userService->getOneById($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param bool $active
|
||||
* @param string $displayName
|
||||
* @param array $emails
|
||||
* @param string $externalId
|
||||
* @param string $userName
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function create(
|
||||
bool $active = true,
|
||||
string $displayName = '',
|
||||
array $emails = [],
|
||||
string $externalId = '',
|
||||
string $userName = ''
|
||||
): SCIMJSONResponse
|
||||
{
|
||||
return $this->userService->create(
|
||||
$active,
|
||||
$displayName,
|
||||
$emails,
|
||||
$externalId,
|
||||
$userName
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @param bool $active
|
||||
* @param string $displayName
|
||||
* @param array $emails
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function update(
|
||||
string $id,
|
||||
bool $active,
|
||||
string $displayName = '',
|
||||
array $emails = []
|
||||
): SCIMJSONResponse
|
||||
{
|
||||
return $this->userService->update($id, $active, $displayName, $emails);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(string $id): Response
|
||||
{
|
||||
return $this->userService->destroy($id);
|
||||
}
|
||||
}
|
|
@ -4,112 +4,106 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Controller;
|
||||
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Service\UserService;
|
||||
use OCA\SCIMServiceProvider\Util\Util;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IRequest;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Service\UserService;
|
||||
use Opf\Models\SCIM\Standard\Users\CoreUser;
|
||||
|
||||
class UserController extends ApiController
|
||||
{
|
||||
/** @var UserService */
|
||||
private $userService;
|
||||
class UserController extends ApiController {
|
||||
private UserService $userService;
|
||||
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
UserService $userService
|
||||
) {
|
||||
parent::__construct(
|
||||
$appName,
|
||||
$request
|
||||
);
|
||||
public function __construct(
|
||||
string $appName,
|
||||
IRequest $request,
|
||||
UserService $userService
|
||||
) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->userService = $userService;
|
||||
}
|
||||
$this->userService = $userService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $filter
|
||||
* @return SCIMListResponse
|
||||
* returns a list of users and their data
|
||||
*/
|
||||
public function index(string $filter = ''): SCIMListResponse
|
||||
{
|
||||
return $this->userService->getAll($filter);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @return SCIMListResponse
|
||||
*/
|
||||
public function index(): SCIMJSONResponse {
|
||||
$params = $this->request->getParams();
|
||||
$params = Util::parsePagination($params);
|
||||
$scimUsers = $this->userService->getAll($params["startIndex"], $params["count"]);
|
||||
$list = [];
|
||||
foreach ($scimUsers as $scimUser) {
|
||||
$list[] = $scimUser->toSCIM(false, Util::getBaseUrl($this->request));
|
||||
}
|
||||
$total = $this->userService->countAll();
|
||||
return new SCIMListResponse($list, $params["startIndex"], $total);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* gets user info
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
// TODO: Add filtering support here as well
|
||||
public function show(string $id): SCIMJSONResponse
|
||||
{
|
||||
return $this->userService->getOneById($id);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
// TODO: Add filtering support here as well
|
||||
public function show(string $id): SCIMJSONResponse {
|
||||
$scimUser = $this->userService->get($id);
|
||||
return new SCIMJSONResponse($scimUser->toSCIM(false, Util::getBaseUrl($this->request)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param bool $active
|
||||
* @param string $displayName
|
||||
* @param array $emails
|
||||
* @param string $externalId
|
||||
* @param string $userName
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function create(
|
||||
bool $active = true,
|
||||
string $displayName = '',
|
||||
array $emails = [],
|
||||
string $externalId = '',
|
||||
string $userName = ''
|
||||
): SCIMJSONResponse
|
||||
{
|
||||
return $this->userService->create(
|
||||
$active,
|
||||
$displayName,
|
||||
$emails,
|
||||
$externalId,
|
||||
$userName
|
||||
);
|
||||
}
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $displayName
|
||||
* @param array $members
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function create(): SCIMJSONResponse {
|
||||
$params = $this->request->getParams();
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $id
|
||||
*
|
||||
* @param bool $active
|
||||
* @param string $displayName
|
||||
* @param array $emails
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function update(
|
||||
string $id,
|
||||
bool $active,
|
||||
string $displayName = '',
|
||||
array $emails = []
|
||||
): SCIMJSONResponse
|
||||
{
|
||||
return $this->userService->update($id, $active, $displayName, $emails);
|
||||
}
|
||||
$scimUser = new CoreUser();
|
||||
$scimUser->fromSCIM($params);
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
*
|
||||
* @param string $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(string $id): Response
|
||||
{
|
||||
return $this->userService->destroy($id);
|
||||
}
|
||||
$scimGroup = $this->userService->create($scimUser);
|
||||
return new SCIMJSONResponse($scimGroup->toSCIM(false, Util::getBaseUrl($this->request)), 201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return SCIMJSONResponse
|
||||
*/
|
||||
public function update(string $id): SCIMJSONResponse {
|
||||
$params = $this->request->getParams();
|
||||
|
||||
$scimUser = new CoreUser();
|
||||
$scimUser->fromSCIM($params);
|
||||
|
||||
$scimUser = $this->userService->update($id, $scimUser);
|
||||
return new SCIMJSONResponse($scimUser->toSCIM(false, Util::getBaseUrl($this->request)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoCSRFRequired
|
||||
* @PublicPage
|
||||
*
|
||||
* @param string $id
|
||||
* @return Response
|
||||
*/
|
||||
public function destroy(string $id): Response {
|
||||
$this->userService->destroy($id);
|
||||
|
||||
$response = new Response();
|
||||
$response->setStatus(204);
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,173 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SCIMServiceProvider\DataAccess\Groups;
|
||||
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IUserManager;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class NextcloudGroupDataAccess
|
||||
{
|
||||
/** @var Psr\Log\LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var \OCP\IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var \OCP\IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
$this->userManager = $container->get(IUserManager::class);
|
||||
$this->groupManager = $container->get(IGroupManager::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all groups
|
||||
*/
|
||||
public function getAll(): ?array
|
||||
{
|
||||
$ncGroups = $this->groupManager->search('', null, 0);
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupDataAccess::class . "] fetched " . count($ncGroups) . " groups"
|
||||
);
|
||||
|
||||
return $ncGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a single group by ID
|
||||
*/
|
||||
public function getOneById($id): ?IGroup
|
||||
{
|
||||
$ncGroup = $this->groupManager->get($id);
|
||||
|
||||
if (!isset($ncGroup)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupDataAccess::class . "] group with ID: " . $id . " is null"
|
||||
);
|
||||
} else {
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupDataAccess::class . "] fetched group with ID: " . $id
|
||||
);
|
||||
}
|
||||
|
||||
return $ncGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new group
|
||||
*/
|
||||
public function create($displayName): ?IGroup
|
||||
{
|
||||
// Note: the createGroup() function requires a $gid parameter
|
||||
// However, looking at the NC DB, it seems that the gid of a group
|
||||
// and its displayName can have the same value, hence here we pass the
|
||||
// displayName parameter to createGroup() and don't need to generate
|
||||
// a unique gid for a given group during creation
|
||||
$createdNcGroup = $this->groupManager->createGroup($displayName);
|
||||
|
||||
if (!isset($createdNcGroup)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupDataAccess::class . "] creation of group with displayName: " . $displayName . " failed"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return $createdNcGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing group by ID
|
||||
*
|
||||
* Note: here, we pass the second parameter, since it carries the data to be updated
|
||||
* and we need to pass this data to the group that is to be updated
|
||||
*/
|
||||
public function update(string $id, IGroup $newGroupData): ?IGroup
|
||||
{
|
||||
$ncGroupToUpdate = $this->groupManager->get($id);
|
||||
|
||||
if (!isset($ncGroupToUpdate)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupDataAccess::class . "] group to be updated with ID: " . $id . " doesn't exist"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($newGroupData->getDisplayName() !== null) {
|
||||
$ncGroupToUpdate->setDisplayName($newGroupData->getDisplayName());
|
||||
}
|
||||
|
||||
if ($newGroupData->getUsers() !== null && !empty($newGroupData->getUsers())) {
|
||||
$newNcGroupMembers = [];
|
||||
|
||||
foreach ($newGroupData->getUsers() as $newNcGroupMember) {
|
||||
// First check if the user is an existing one and only then try to place it as a member of the group
|
||||
if ($this->userManager->userExists($newNcGroupMember->getUID())) {
|
||||
$ncUserToAdd = $this->userManager->get($newNcGroupMember->getUID());
|
||||
$newNcGroupMembers[] = $ncUserToAdd;
|
||||
} else {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupDataAccess::class . "] user from new group data with ID: " . $id . " doesn't exist"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$currentNcGroupMembers = $ncGroupToUpdate->getUsers();
|
||||
if (isset($currentNcGroupMembers) && !empty($currentNcGroupMembers)) {
|
||||
// If the group can't remove users from itself, then we abort and return null
|
||||
if (!$ncGroupToUpdate->canRemoveUser()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Else, if we can remove users, then we remove all current users
|
||||
foreach ($currentNcGroupMembers as $currentNcGroupMember) {
|
||||
$ncGroupToUpdate->removeUser($currentNcGroupMember);
|
||||
}
|
||||
}
|
||||
|
||||
// After having deleted the current members, we try to replace them with the new ones
|
||||
if (!$ncGroupToUpdate->canAddUser()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach ($newNcGroupMembers as $newNcGroupMember) {
|
||||
$ncGroupToUpdate->addUser($newNcGroupMember);
|
||||
}
|
||||
}
|
||||
|
||||
// Return the now updated NC group
|
||||
return $this->groupManager->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing group by ID
|
||||
*/
|
||||
public function delete($id): bool
|
||||
{
|
||||
$ncGroupToDelete = $this->groupManager->get($id);
|
||||
|
||||
if (!isset($ncGroupToDelete)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupDataAccess::class . "] group to be deleted with ID: " . $id . " doesn't exist"
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($ncGroupToDelete->delete()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupDataAccess::class . "] couldn't delete group with ID: " . $id
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,144 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SCIMServiceProvider\DataAccess\Users;
|
||||
|
||||
use OCP\IConfig;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class NextcloudUserDataAccess
|
||||
{
|
||||
/** @var Psr\Log\LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var \OCP\IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var \OCP\Security\ISecureRandom */
|
||||
private $secureRandom;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
$this->secureRandom = $container->get(ISecureRandom::class);
|
||||
$this->userManager = $container->get(IUserManager::class);
|
||||
$this->config = $container->get(IConfig::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all users
|
||||
*/
|
||||
public function getAll(): ?array
|
||||
{
|
||||
$ncUsers = $this->userManager->search('', null, 0);
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserDataAccess::class . "] fetched " . count($ncUsers) . " users"
|
||||
);
|
||||
|
||||
return $ncUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a single user by ID
|
||||
*/
|
||||
public function getOneById($id): ?IUser
|
||||
{
|
||||
$ncUser = $this->userManager->get($id);
|
||||
|
||||
if (!isset($ncUser)) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserDataAccess::class . "] user with ID: " . $id . " is null"
|
||||
);
|
||||
} else {
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserDataAccess::class . "] fetched user with ID: " . $id
|
||||
);
|
||||
}
|
||||
|
||||
return $ncUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new user
|
||||
*/
|
||||
public function create($username): ?IUser
|
||||
{
|
||||
$createdNcUser = $this->userManager->createUser($username, $this->secureRandom->generate(64));
|
||||
|
||||
if ($createdNcUser === false) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserDataAccess::class . "] creation of user with userName: " . $username . " failed"
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return $createdNcUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing user by ID
|
||||
*
|
||||
* Note: here, we pass the second parameter, since it carries the data to be updated
|
||||
* and we need to pass this data to the user that is to be updated
|
||||
*/
|
||||
public function update(string $id, IUser $newUserData): ?IUser
|
||||
{
|
||||
$ncUserToUpdate = $this->userManager->get($id);
|
||||
|
||||
if ($ncUserToUpdate === null) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserDataAccess::class . "] user to be updated with ID: " . $id . " doesn't exist"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($newUserData->getDisplayName() !== null) {
|
||||
$ncUserToUpdate->setDisplayName($newUserData->getDisplayName());
|
||||
}
|
||||
|
||||
if ($newUserData->isEnabled() !== null && $newUserData->isEnabled()) {
|
||||
$ncUserToUpdate->setEnabled($newUserData->isEnabled());
|
||||
}
|
||||
|
||||
if ($newUserData->getEMailAddress() !== null && !empty($newUserData->getEMailAddress())) {
|
||||
$ncUserToUpdate->setEMailAddress($newUserData->getEMailAddress());
|
||||
}
|
||||
|
||||
// Return the now updated NC user
|
||||
return $this->userManager->get($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing user by ID
|
||||
*/
|
||||
public function delete($id): bool
|
||||
{
|
||||
$ncUserToDelete = $this->userManager->get($id);
|
||||
|
||||
if ($ncUserToDelete === null) {
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserDataAccess::class . "] user to be deleted with ID: " . $id . " doesn't exist"
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($ncUserToDelete->delete()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserDataAccess::class . "] couldn't delete user with ID: " . $id
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,8 @@ namespace OCA\SCIMServiceProvider\Exception;
|
|||
|
||||
use Exception;
|
||||
|
||||
class AuthException extends Exception
|
||||
{
|
||||
class AuthException extends Exception {
|
||||
public function __construct(string $message) {
|
||||
parent::__construct($message, 401);
|
||||
}
|
||||
}
|
|
@ -4,6 +4,5 @@ namespace OCA\SCIMServiceProvider\Exception;
|
|||
|
||||
use Exception;
|
||||
|
||||
class ContentTypeException extends Exception
|
||||
{
|
||||
class ContentTypeException extends Exception {
|
||||
}
|
||||
|
|
110
lib/Middleware/AuthMiddleware.php
Normal file
110
lib/Middleware/AuthMiddleware.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Middleware;
|
||||
|
||||
use Exception;
|
||||
use OCA\SCIMServiceProvider\AppInfo\Application;
|
||||
use OCA\SCIMServiceProvider\Exception\AuthException;
|
||||
use OCP\AppFramework\Middleware;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
use Opf\ScimServerPhp\Firebase\JWT\JWT;
|
||||
use Opf\ScimServerPhp\Firebase\JWT\Key;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class AuthMiddleware extends Middleware {
|
||||
private IRequest $request;
|
||||
private IUserSession $userSession;
|
||||
private IUserManager $userManager;
|
||||
private IGroupManager $groupManager;
|
||||
private IConfig $config;
|
||||
private LoggerInterface $logger;
|
||||
|
||||
public function __construct(IRequest $request, IUserSession $userSession, IUserManager $userManager, IGroupManager $groupManager, IConfig $config, LoggerInterface $logger) {
|
||||
$this->request = $request;
|
||||
$this->userSession = $userSession;
|
||||
$this->userManager = $userManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->config = $config;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
public function beforeController($controller, $methodName) {
|
||||
$currentRoute = $this->request->getParams()["_route"];
|
||||
$publicRoutes = [
|
||||
"scimserviceprovider.service_provider_configuration.resource_types",
|
||||
"scimserviceprovider.service_provider_configuration.schemas",
|
||||
"scimserviceprovider.service_provider_configuration.service_provider_config"
|
||||
];
|
||||
|
||||
// Don't require an auth header for public routes
|
||||
if (in_array($currentRoute, $publicRoutes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$authHeader = $this->request->getHeader('Authorization');
|
||||
|
||||
if (empty($authHeader)) {
|
||||
throw new AuthException("No Authorization header supplied");
|
||||
}
|
||||
|
||||
$authHeaderSplit = explode(' ', $authHeader);
|
||||
if (count($authHeaderSplit) !== 2) {
|
||||
throw new AuthException("Incorrect authorization header");
|
||||
}
|
||||
|
||||
switch ($authHeaderSplit[0]) {
|
||||
case 'Basic':
|
||||
$user = $this->userSession->getUser();
|
||||
if ($user == null) {
|
||||
throw new AuthException("Not logged-in");
|
||||
}
|
||||
break;
|
||||
case 'Bearer':
|
||||
$user = $this->authenticateBearerToken($authHeaderSplit[1]);
|
||||
break;
|
||||
default:
|
||||
throw new AuthException("Incorrect authorization type");
|
||||
break;
|
||||
}
|
||||
|
||||
// For now only allow admin users
|
||||
if (!$this->groupManager->isAdmin($user->getUID())) {
|
||||
throw new AuthException("Not admin");
|
||||
}
|
||||
}
|
||||
|
||||
private function authenticateBearerToken(string $token): ?IUser {
|
||||
$e = new AuthException("Bearer token is invalid");
|
||||
$jwtPayload = [];
|
||||
$jwtSecret = $this->config->getAppValue(Application::APP_ID, "jwt-secret");
|
||||
if (empty($jwtSecret)) {
|
||||
$this->logger->error("jwt-secret not configued");
|
||||
throw $e;
|
||||
}
|
||||
try {
|
||||
$jwtPayload = (array) JWT::decode($token, new Key($jwtSecret, 'HS256'));
|
||||
} catch (Exception $e2) {
|
||||
$this->logger->error($e2->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$username = $jwtPayload['sub'];
|
||||
|
||||
// If we managed to find a user with that username, then auth succeeded
|
||||
$user = $this->userManager->get($username);
|
||||
if ($user === null) {
|
||||
$this->logger->error("User with this username doesn't exist");
|
||||
throw $e;
|
||||
}
|
||||
|
||||
$this->userSession->setUser($user);
|
||||
return $user;
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Middleware;
|
||||
|
||||
use Exception;
|
||||
use OCA\SCIMServiceProvider\Controller\UserController;
|
||||
use OCA\SCIMServiceProvider\Exception\AuthException;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
|
||||
use OCA\SCIMServiceProvider\Util\Authentication\BearerAuthenticator;
|
||||
use OCP\AppFramework\Middleware;
|
||||
use OCP\IRequest;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class BearerAuthMiddleware extends Middleware
|
||||
{
|
||||
/** @var IRequest */
|
||||
private IRequest $request;
|
||||
|
||||
/** @var \OCA\SCIMServiceProvider\Util\Authentication\BearerAuthenticator */
|
||||
private BearerAuthenticator $bearerAuthenticator;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->request = $container->get(IRequest::class);
|
||||
$this->bearerAuthenticator = $container->get(BearerAuthenticator::class);
|
||||
}
|
||||
|
||||
public function beforeController($controller, $methodName)
|
||||
{
|
||||
$currentRoute = $this->request->getParams()["_route"];
|
||||
$publicRoutes = [
|
||||
"scimserviceprovider.service_provider_configuration.resource_types",
|
||||
"scimserviceprovider.service_provider_configuration.schemas",
|
||||
"scimserviceprovider.service_provider_configuration.service_provider_config"
|
||||
];
|
||||
|
||||
// Don't require an auth header for public routes
|
||||
if (in_array($currentRoute, $publicRoutes)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$authHeader = $this->request->getHeader('Authorization');
|
||||
|
||||
if (empty($authHeader)) {
|
||||
throw new AuthException("No Authorization header supplied");
|
||||
}
|
||||
|
||||
$authHeaderSplit = explode(' ', $authHeader);
|
||||
if (count($authHeaderSplit) !== 2 || strcmp($authHeaderSplit[0], "Bearer") !== 0) {
|
||||
throw new AuthException("Incorrect Bearer token format");
|
||||
}
|
||||
|
||||
$token = $authHeaderSplit[1];
|
||||
|
||||
// Currently the second parameter to authenticate() is an empty array
|
||||
// (the second parameter is meant to carry authorization information)
|
||||
if (!$this->bearerAuthenticator->authenticate($token, [])) {
|
||||
throw new AuthException("Bearer token is invalid");
|
||||
}
|
||||
}
|
||||
|
||||
public function afterException($controller, $methodName, Exception $exception)
|
||||
{
|
||||
if ($exception instanceof AuthException) {
|
||||
return new SCIMErrorResponse(['message' => $exception->getMessage()], 401);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,57 +4,47 @@ declare(strict_types=1);
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Middleware;
|
||||
|
||||
use Exception;
|
||||
use OCA\SCIMServiceProvider\Exception\ContentTypeException;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
|
||||
use OCP\AppFramework\Middleware;
|
||||
use OCP\IRequest;
|
||||
use Psr\Container\ContainerInterface;
|
||||
|
||||
class ContentTypeMiddleware extends Middleware
|
||||
{
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
class ContentTypeMiddleware extends Middleware {
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->request = $container->get(IRequest::class);
|
||||
}
|
||||
public function __construct(ContainerInterface $container) {
|
||||
$this->request = $container->get(IRequest::class);
|
||||
}
|
||||
|
||||
public function beforeController($controller, $methodName)
|
||||
{
|
||||
$requestMethod = $this->request->getMethod();
|
||||
public function beforeController($controller, $methodName) {
|
||||
$requestMethod = $this->request->getMethod();
|
||||
|
||||
// If the incoming request is POST or PUT => check the Content-Type header and the request body
|
||||
if (in_array(strtolower($requestMethod), array("post", "put"))) {
|
||||
$contentTypeHeader = $this->request->getHeader("Content-Type");
|
||||
if (!isset($contentTypeHeader) || empty($contentTypeHeader)) {
|
||||
throw new ContentTypeException("Content-Type header not set");
|
||||
}
|
||||
// If the incoming request is POST or PUT => check the Content-Type header and the request body
|
||||
if (in_array(strtolower($requestMethod), array("post", "put"))) {
|
||||
$contentTypeHeader = $this->request->getHeader("Content-Type");
|
||||
if (!isset($contentTypeHeader) || empty($contentTypeHeader)) {
|
||||
throw new ContentTypeException("Content-Type header not set");
|
||||
}
|
||||
|
||||
// Accept both "application/scim+json" and "application/json" as valid headers
|
||||
// See https://www.rfc-editor.org/rfc/rfc7644.html#section-3.8
|
||||
if (
|
||||
strpos($contentTypeHeader, "application/scim+json") === false
|
||||
&& strpos($contentTypeHeader, "application/json") === false
|
||||
) {
|
||||
throw new ContentTypeException("Content-Type header is not application/scim+json or application/json");
|
||||
}
|
||||
// Accept both "application/scim+json" and "application/json" as valid headers
|
||||
// See https://www.rfc-editor.org/rfc/rfc7644.html#section-3.8
|
||||
if (
|
||||
strpos($contentTypeHeader, "application/scim+json") === false
|
||||
&& strpos($contentTypeHeader, "application/json") === false
|
||||
) {
|
||||
throw new ContentTypeException("Content-Type header is not application/scim+json or application/json");
|
||||
}
|
||||
|
||||
// Verify that the request body is indeed valid JSON
|
||||
$requestBody = $this->request->getParams();
|
||||
if (isset($requestBody) && !empty($requestBody)) {
|
||||
$requestBody = array_keys($requestBody)[0];
|
||||
// Verify that the request body is indeed valid JSON
|
||||
$requestBody = $this->request->getParams();
|
||||
if (isset($requestBody) && !empty($requestBody)) {
|
||||
$requestBody = array_keys($requestBody)[0];
|
||||
|
||||
if (json_decode($requestBody) === false) {
|
||||
throw new ContentTypeException("Request body is not valid JSON");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function afterException($controller, $methodName, Exception $exception)
|
||||
{
|
||||
return new SCIMErrorResponse(['message' => $exception->getMessage()], 400);
|
||||
}
|
||||
if (json_decode($requestBody) === false) {
|
||||
throw new ContentTypeException("Request body is not valid JSON");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
lib/Middleware/ErrorMiddleware.php
Normal file
16
lib/Middleware/ErrorMiddleware.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Middleware;
|
||||
|
||||
use Exception;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
|
||||
use OCP\AppFramework\Controller;
|
||||
use OCP\AppFramework\Middleware;
|
||||
|
||||
class ErrorMiddleware extends Middleware {
|
||||
public function afterException(Controller $controller, string $methodName, Exception $exception) {
|
||||
return new SCIMErrorResponse($exception);
|
||||
}
|
||||
}
|
|
@ -1,164 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Repositories\Groups;
|
||||
|
||||
use Opf\Models\SCIM\Standard\Groups\CoreGroup;
|
||||
use Opf\Repositories\Repository;
|
||||
use Opf\Util\Filters\FilterUtil;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class NextcloudGroupRepository extends Repository
|
||||
{
|
||||
/** @var Psr\Log\LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->dataAccess = $container->get('GroupDataAccess');
|
||||
$this->adapter = $container->get('GroupAdapter');
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all groups in SCIM format
|
||||
*/
|
||||
public function getAll(
|
||||
$filter = '',
|
||||
$startIndex = 0,
|
||||
$count = 0,
|
||||
$attributes = [],
|
||||
$excludedAttributes = []
|
||||
): array {
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupRepository::class . "] reading all groups"
|
||||
);
|
||||
|
||||
// Read all NC groups
|
||||
$ncGroups = $this->dataAccess->getAll();
|
||||
$scimGroups = [];
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupRepository::class . "] fetched " . count($ncGroups) . " NC groups"
|
||||
);
|
||||
|
||||
foreach ($ncGroups as $ncGroup) {
|
||||
$scimGroup = $this->adapter->getCoreGroup($ncGroup);
|
||||
$scimGroups[] = $scimGroup;
|
||||
}
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupRepository::class . "] transformed " . count($scimGroups) . " SCIM groups"
|
||||
);
|
||||
|
||||
if (isset($filter) && !empty($filter)) {
|
||||
$scimGroupsToFilter = [];
|
||||
foreach ($scimGroups as $scimGroup) {
|
||||
$scimGroupsToFilter[] = $scimGroup->toSCIM(false);
|
||||
}
|
||||
|
||||
$filteredScimData = FilterUtil::performFiltering($filter, $scimGroupsToFilter);
|
||||
|
||||
$scimGroups = [];
|
||||
foreach ($filteredScimData as $filteredScimGroup) {
|
||||
$scimGroup = new CoreGroup();
|
||||
$scimGroup->fromSCIM($filteredScimGroup);
|
||||
$scimGroups[] = $scimGroup;
|
||||
}
|
||||
|
||||
return $scimGroups;
|
||||
}
|
||||
|
||||
return $scimGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a single group by ID in SCIM format
|
||||
*/
|
||||
public function getOneById(
|
||||
string $id,
|
||||
$filter = '',
|
||||
$startIndex = 0,
|
||||
$count = 0,
|
||||
$attributes = [],
|
||||
$excludedAttributes = []
|
||||
): ?CoreGroup {
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupRepository::class . "] reading group with ID: " . $id
|
||||
);
|
||||
|
||||
$ncGroup = $this->dataAccess->getOneById($id);
|
||||
return $this->adapter->getCoreGroup($ncGroup);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a group from SCIM data
|
||||
*/
|
||||
public function create($object): ?CoreGroup
|
||||
{
|
||||
$scimGroupToCreate = new CoreGroup();
|
||||
$scimGroupToCreate->fromSCIM($object);
|
||||
|
||||
$displayName = $scimGroupToCreate->getDisplayName();
|
||||
$ncGroupCreated = $this->dataAccess->create($displayName);
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupRepository::class . "] creating group with displayName: " . $displayName
|
||||
);
|
||||
|
||||
if (isset($ncGroupCreated)) {
|
||||
// Set the rest of the properties of the NC group with the adapter
|
||||
$ncGroupCreated = $this->adapter->getNCGroup($scimGroupToCreate, $ncGroupCreated);
|
||||
return $this->adapter->getCoreGroup($ncGroupCreated);
|
||||
}
|
||||
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupRepository::class . "] creation of group with displayName: " . $displayName . " failed"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a group by ID from SCIM data
|
||||
*/
|
||||
public function update(string $id, $object): ?CoreGroup
|
||||
{
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupRepository::class . "] updating group with ID: " . $id
|
||||
);
|
||||
|
||||
$scimGroupToUpdate = new CoreGroup();
|
||||
$scimGroupToUpdate->fromSCIM($object);
|
||||
|
||||
$ncGroup = $this->dataAccess->getOneById($id);
|
||||
|
||||
if (isset($ncGroup)) {
|
||||
$ncGroupToUpdate = $this->adapter->getNCGroup($scimGroupToUpdate, $ncGroup);
|
||||
$ncGroupUpdated = $this->dataAccess->update($id, $ncGroupToUpdate);
|
||||
|
||||
if (isset($ncGroupUpdated)) {
|
||||
return $this->adapter->getCoreGroup($ncGroupUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger->error(
|
||||
"[" . NextcloudGroupRepository::class . "] update of group with ID: " . $id . " failed"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a group by ID
|
||||
*/
|
||||
public function delete(string $id): bool
|
||||
{
|
||||
$this->logger->info(
|
||||
"[" . NextcloudGroupRepository::class . "] deleting group with ID: " . $id
|
||||
);
|
||||
|
||||
return $this->dataAccess->delete($id);
|
||||
}
|
||||
}
|
|
@ -1,177 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Repositories\Users;
|
||||
|
||||
use Opf\Models\SCIM\Standard\Users\CoreUser;
|
||||
use Opf\Repositories\Repository;
|
||||
use Opf\Util\Filters\FilterUtil;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class NextcloudUserRepository extends Repository
|
||||
{
|
||||
/** @var Psr\Log\LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
parent::__construct($container);
|
||||
$this->dataAccess = $container->get('UserDataAccess');
|
||||
$this->adapter = $container->get('UserAdapter');
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Read all users in SCIM format
|
||||
*/
|
||||
public function getAll(
|
||||
$filter = '',
|
||||
$startIndex = 0,
|
||||
$count = 0,
|
||||
$attributes = [],
|
||||
$excludedAttributes = []
|
||||
): array {
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserRepository::class . "] reading all users"
|
||||
);
|
||||
|
||||
// Read all NC users
|
||||
$ncUsers = $this->dataAccess->getAll();
|
||||
$scimUsers = [];
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserRepository::class . "] fetched " . count($ncUsers) . " NC users"
|
||||
);
|
||||
|
||||
foreach ($ncUsers as $ncUser) {
|
||||
$scimUser = $this->adapter->getCoreUser($ncUser);
|
||||
$scimUsers[] = $scimUser;
|
||||
}
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserRepository::class . "] transformed " . count($scimUsers) . " SCIM users"
|
||||
);
|
||||
|
||||
if (isset($filter) && !empty($filter)) {
|
||||
$scimUsersToFilter = [];
|
||||
foreach ($scimUsers as $scimUser) {
|
||||
$scimUsersToFilter[] = $scimUser->toSCIM(false);
|
||||
}
|
||||
|
||||
$filteredScimData = FilterUtil::performFiltering($filter, $scimUsersToFilter);
|
||||
|
||||
$scimUsers = [];
|
||||
foreach ($filteredScimData as $filteredScimUser) {
|
||||
$scimUser = new CoreUser();
|
||||
$scimUser->fromSCIM($filteredScimUser);
|
||||
$scimUsers[] = $scimUser;
|
||||
}
|
||||
|
||||
return $scimUsers;
|
||||
}
|
||||
|
||||
return $scimUsers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read a single user by ID in SCIM format
|
||||
*/
|
||||
public function getOneById(
|
||||
string $id,
|
||||
$filter = '',
|
||||
$startIndex = 0,
|
||||
$count = 0,
|
||||
$attributes = [],
|
||||
$excludedAttributes = []
|
||||
): ?CoreUser {
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserRepository::class . "] reading user with ID: " . $id
|
||||
);
|
||||
|
||||
$ncUser = $this->dataAccess->getOneById($id);
|
||||
$scimUser = $this->adapter->getCoreUser($ncUser);
|
||||
|
||||
if (isset($filter) && !empty($filter)) {
|
||||
$scimUsersToFilter = array($scimUser->toSCIM(false));
|
||||
$filteredScimData = FilterUtil::performFiltering($filter, $scimUsersToFilter);
|
||||
|
||||
if (!empty($filteredScimData)) {
|
||||
$scimUser = new CoreUser();
|
||||
$scimUser->fromSCIM($filteredScimData[0]);
|
||||
return $scimUser;
|
||||
}
|
||||
}
|
||||
|
||||
return $scimUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a user from SCIM data
|
||||
*/
|
||||
public function create($object): ?CoreUser
|
||||
{
|
||||
$scimUserToCreate = new CoreUser();
|
||||
$scimUserToCreate->fromSCIM($object);
|
||||
|
||||
$username = $scimUserToCreate->getUserName();
|
||||
$ncUserCreated = $this->dataAccess->create($username);
|
||||
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserRepository::class . "] creating user with userName: " . $username
|
||||
);
|
||||
|
||||
if (isset($ncUserCreated)) {
|
||||
// Set the rest of the properties of the NC user via the adapter
|
||||
$ncUserCreated = $this->adapter->getNCUser($scimUserToCreate, $ncUserCreated);
|
||||
return $this->adapter->getCoreUser($ncUserCreated);
|
||||
}
|
||||
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserRepository::class . "] creation of user with username: " . $username . " failed"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a user by ID from SCIM data
|
||||
*/
|
||||
public function update(string $id, $object): ?CoreUser
|
||||
{
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserRepository::class . "] updating user with ID: " . $id
|
||||
);
|
||||
|
||||
$scimUserToUpdate = new CoreUser();
|
||||
$scimUserToUpdate->fromSCIM($object);
|
||||
|
||||
$ncUser = $this->dataAccess->getOneById($id);
|
||||
|
||||
if (isset($ncUser)) {
|
||||
$ncUserToUpdate = $this->adapter->getNCUser($scimUserToUpdate, $ncUser);
|
||||
$ncUserUpdated = $this->dataAccess->update($id, $ncUserToUpdate);
|
||||
|
||||
if (isset($ncUserUpdated)) {
|
||||
return $this->adapter->getCoreUser($ncUserUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
$this->logger->error(
|
||||
"[" . NextcloudUserRepository::class . "] update of user with ID: " . $id . " failed"
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a user by ID
|
||||
*/
|
||||
public function delete(string $id): bool
|
||||
{
|
||||
$this->logger->info(
|
||||
"[" . NextcloudUserRepository::class . "] deleting user with ID: " . $id
|
||||
);
|
||||
|
||||
return $this->dataAccess->delete($id);
|
||||
}
|
||||
}
|
|
@ -2,39 +2,21 @@
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Responses;
|
||||
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* Class SCIMErrorResponse
|
||||
*
|
||||
*/
|
||||
class SCIMErrorResponse extends SCIMJSONResponse {
|
||||
/**
|
||||
* response data
|
||||
* @var array|object
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Returns the rendered json
|
||||
* @return string the rendered json
|
||||
* @since 6.0.0
|
||||
* @throws \Exception If data could not get encoded
|
||||
*/
|
||||
public function render() {
|
||||
$message = [
|
||||
public function __construct(Exception $e) {
|
||||
$data = [
|
||||
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:Error'],
|
||||
'detail' => $this->data['message'],
|
||||
'detail' => $e->getMessage(),
|
||||
'scimType' => '',
|
||||
'status' => $this->getStatus()
|
||||
'status' => $e->getCode(),
|
||||
];
|
||||
$response = json_encode($message, JSON_UNESCAPED_SLASHES);
|
||||
|
||||
if ($response === false) {
|
||||
throw new Exception(sprintf('Could not json_encode due to invalid ' .
|
||||
'non UTF-8 characters in the array: %s', var_export($this->data, true)));
|
||||
}
|
||||
|
||||
return $response;
|
||||
parent::__construct($data, $e->getCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Responses;
|
||||
|
||||
use Exception;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,56 +2,27 @@
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Responses;
|
||||
|
||||
use OCP\AppFramework\Http\Response;
|
||||
|
||||
use OCA\SCIMServiceProvider\Exceptions\SCIMException;
|
||||
|
||||
/**
|
||||
* Class SCIMListResponse
|
||||
*
|
||||
*/
|
||||
class SCIMListResponse extends Response {
|
||||
/**
|
||||
* response data
|
||||
* @var array|object
|
||||
*/
|
||||
protected $data;
|
||||
|
||||
|
||||
class SCIMListResponse extends SCIMJSONResponse {
|
||||
/**
|
||||
* constructor of SCIMListResponse
|
||||
* @param array|object $data the object or array that should be transformed
|
||||
* @param int $statusCode the Http status code, defaults to 200
|
||||
* @param array $items array that should be transformed
|
||||
* @since 6.0.0
|
||||
*/
|
||||
public function __construct($data = [], $statusCode = 200) {
|
||||
parent::__construct();
|
||||
|
||||
$this->data = $data;
|
||||
$this->setStatus($statusCode);
|
||||
$this->addHeader('Content-Type', 'application/scim+json; charset=utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the rendered json
|
||||
* @return string the rendered json
|
||||
* @since 6.0.0
|
||||
* @throws \Exception If data could not get encoded
|
||||
*/
|
||||
public function render() {
|
||||
$scimReponse = [
|
||||
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:ListResponse'],
|
||||
'startIndex' => 1, // todo pagination
|
||||
'Resources' => $this->data,
|
||||
'totalResults' => sizeof($this->data)
|
||||
];
|
||||
$response = json_encode($scimReponse, JSON_UNESCAPED_SLASHES);
|
||||
|
||||
if ($response === false) {
|
||||
throw new SCIMException(sprintf('Could not json_encode due to invalid ' .
|
||||
'non UTF-8 characters in the array: %s', var_export($scimReponse, true)));
|
||||
public function __construct(array $items = [], int $startIndex = 1, int $total = null) {
|
||||
if ($total === null) {
|
||||
$total = sizeof($items);
|
||||
}
|
||||
|
||||
return $response;
|
||||
$data = [
|
||||
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:ListResponse'],
|
||||
'startIndex' => $startIndex,
|
||||
'itemsPerPage' => sizeof($items),
|
||||
'totalResults' => $total,
|
||||
'Resources' => $items,
|
||||
];
|
||||
parent::__construct($data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,153 +6,196 @@ namespace OCA\SCIMServiceProvider\Service;
|
|||
|
||||
use Exception;
|
||||
use OCA\SCIMServiceProvider\AppInfo\Application;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Util\Util;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use OCP\IUserManager;
|
||||
use Opf\Models\SCIM\Standard\Groups\CoreGroup;
|
||||
use Opf\Models\SCIM\Standard\Meta;
|
||||
use Opf\Models\SCIM\Standard\MultiValuedAttribute;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class GroupService
|
||||
{
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
class GroupService {
|
||||
|
||||
/** @var \OCA\SCIMServiceProvider\Repositories\Groups\NextcloudGroupRepository */
|
||||
private $repository;
|
||||
private LoggerInterface $logger;
|
||||
private IGroupManager $groupManager;
|
||||
private IUserManager $userManager;
|
||||
|
||||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
public function __construct(LoggerInterface $logger, IGroupManager $groupManager, IUserManager $userManager) {
|
||||
$this->logger = $logger;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userManager = $userManager;
|
||||
}
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
$this->repository = $container->get('GroupRepository');
|
||||
$this->groupManager = $container->get(IGroupManager::class);
|
||||
$this->request = $container->get(IRequest::class);
|
||||
}
|
||||
|
||||
public function getAll(string $filter = ''): SCIMListResponse
|
||||
{
|
||||
$this->logger->info("Reading all groups");
|
||||
private function toSCIM(IGroup $ncGroup): CoreGroup {
|
||||
$scimGroup = new CoreGroup();
|
||||
$scimGroup->setId($ncGroup->getGID());
|
||||
$scimGroup->setDisplayName($ncGroup->getDisplayName());
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://"
|
||||
. $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
$meta = new Meta();
|
||||
$meta->setResourceType("Group");
|
||||
$scimGroup->setMeta($meta);
|
||||
|
||||
$groups = $this->repository->getAll($filter);
|
||||
return $scimGroup;
|
||||
}
|
||||
|
||||
$scimGroups = [];
|
||||
if (!empty($groups)) {
|
||||
foreach ($groups as $group) {
|
||||
$scimGroups[] = $group->toSCIM(false, $baseUrl);
|
||||
}
|
||||
}
|
||||
|
||||
return new SCIMListResponse($scimGroups);
|
||||
}
|
||||
private function getSCIMMembers(IGroup $ncGroup): array {
|
||||
$members = [];
|
||||
foreach ($ncGroup->getUsers() as $ncGroupMember) {
|
||||
$this->logger->info($ncGroupMember->getUID());
|
||||
$member = new MultiValuedAttribute();
|
||||
$member->setType("User");
|
||||
$member->setRef("Users/" . $ncGroupMember->getUID());
|
||||
$member->setValue($ncGroupMember->getUID());
|
||||
$member->setDisplay($ncGroupMember->getDisplayName());
|
||||
|
||||
public function getOneById(string $id): SCIMJSONResponse
|
||||
{
|
||||
$this->logger->info("Reading group with ID: " . $id);
|
||||
$members[] = $member;
|
||||
}
|
||||
return $members;
|
||||
}
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
private function updateGroup(IGroup $ncGroup, CoreGroup $scimGroup) {
|
||||
$displayName = $scimGroup->getDisplayName();
|
||||
if (isset($displayName)) {
|
||||
$ncGroup->setDisplayName($displayName);
|
||||
}
|
||||
|
||||
$group = $this->repository->getOneById($id);
|
||||
if (!isset($group) || empty($group)) {
|
||||
$this->logger->error("Group with ID " . $id . " not found");
|
||||
return new SCIMErrorResponse(['message' => 'Group not found'], 404);
|
||||
}
|
||||
return new SCIMJSONResponse($group->toSCIM(false, $baseUrl));
|
||||
}
|
||||
$scimMembers = $scimGroup->getMembers();
|
||||
if (isset($scimMembers)) {
|
||||
foreach ($ncGroup->getUsers() as $ncUser) {
|
||||
$found = false;
|
||||
foreach ($scimMembers as $scimMember) {
|
||||
if ($ncUser->getUID() === $scimMember->getValue()) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!$found) {
|
||||
$this->logger->info("remove " . $ncUser->getUID() . " from " . $ncGroup->getGID());
|
||||
$ncGroup->removeUser($ncUser);
|
||||
}
|
||||
}
|
||||
foreach ($scimMembers as $scimMember) {
|
||||
$this->logger->info($scimMember->getValue());
|
||||
$this->logger->info(json_encode($scimMember->jsonSerialize()));
|
||||
$user = $this->userManager->get($scimMember->getValue());
|
||||
if (!isset($user)) {
|
||||
throw new Exception("User " . $scimMember->getValue() . " not found", 404);
|
||||
}
|
||||
if (!$ncGroup->inGroup($user)) {
|
||||
$this->logger->info("add " . $user->getUID() . " from " . $ncGroup->getGID());
|
||||
$ncGroup->addUser($user);
|
||||
$this->logger->info(json_encode($ncGroup->getUsers()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function create(string $displayName = '', array $members = []): SCIMJSONResponse
|
||||
{
|
||||
$id = urlencode($displayName);
|
||||
// Validate name
|
||||
if (empty($id)) {
|
||||
$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
|
||||
return new SCIMErrorResponse(['message' => 'Invalid group name'], 400);
|
||||
}
|
||||
// Check if it exists
|
||||
if ($this->groupManager->groupExists($id)) {
|
||||
$this->logger->error("Group to be created already exists");
|
||||
return new SCIMErrorResponse(['message' => 'Group exists'], 409);
|
||||
}
|
||||
public function countAll(): int {
|
||||
$ncGroups = $this->groupManager->search("");
|
||||
return sizeof($ncGroups);
|
||||
}
|
||||
|
||||
try {
|
||||
$this->logger->info("Creating group with displayName: " . $displayName);
|
||||
/*
|
||||
* @param string $filter
|
||||
* @return OCP\IGroup\IGroup[]
|
||||
*/
|
||||
public function getAll(int $startIndex, int $count = null): array {
|
||||
$this->logger->info("Reading all groups");
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
if ($count === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'displayName' => $displayName,
|
||||
'members' => $members
|
||||
];
|
||||
$ncGroups = $this->groupManager->search("", $count, $startIndex - 1);
|
||||
|
||||
$createdGroup = $this->repository->create($data);
|
||||
if (isset($createdGroup) && !empty($createdGroup)) {
|
||||
return new SCIMJSONResponse($createdGroup->toSCIM(false, $baseUrl), 201);
|
||||
} else {
|
||||
$this->logger->error("Creating group failed");
|
||||
return new SCIMErrorResponse(['message' => 'Creating group failed'], 400);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->logger->warning('Failed createGroup attempt with SCIMException exception.', ['app' => Application::APP_ID]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
$scimGroups = [];
|
||||
foreach ($ncGroups as $ncGroup) {
|
||||
$scimGroup = $this->toSCIM($ncGroup);
|
||||
$members = $this->getSCIMMembers($ncGroup);
|
||||
$scimGroup->setMembers($members);
|
||||
$scimGroups[] = $scimGroup;
|
||||
}
|
||||
|
||||
public function update(string $id, string $displayName = '', array $members = []): SCIMJSONResponse
|
||||
{
|
||||
$this->logger->info("Updating group with ID: " . $id);
|
||||
return $scimGroups;
|
||||
}
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
public function get(string $id): CoreGroup {
|
||||
if (!$this->groupManager->groupExists($id)) {
|
||||
throw new Exception("Not found", 404);
|
||||
}
|
||||
|
||||
$group = $this->repository->getOneById($id);
|
||||
if (!isset($group) || empty($group)) {
|
||||
$this->logger->error("Group with ID " . $id . " not found for update");
|
||||
return new SCIMErrorResponse(['message' => 'Group not found'], 404);
|
||||
}
|
||||
$ncGroup = $this->groupManager->get($id);
|
||||
$scimGroup = $this->toSCIM($ncGroup);
|
||||
|
||||
$data = [
|
||||
'displayName' => $displayName,
|
||||
'members' => $members
|
||||
];
|
||||
|
||||
$updatedGroup = $this->repository->update($id, $data);
|
||||
if (isset($updatedGroup) && !empty($updatedGroup)) {
|
||||
return new SCIMJSONResponse($updatedGroup->toSCIM(false, $baseUrl));
|
||||
} else {
|
||||
$this->logger->error("Updating group with ID " . $id . " failed");
|
||||
return new SCIMErrorResponse(['message' => 'Updating group failed'], 400);
|
||||
}
|
||||
}
|
||||
$members = $this->getSCIMMembers($ncGroup);
|
||||
$scimGroup->setMembers($members);
|
||||
|
||||
public function destroy(string $id): Response
|
||||
{
|
||||
$this->logger->info("Deleting group with ID: " . $id);
|
||||
return $scimGroup;
|
||||
}
|
||||
|
||||
if ($id === 'admin') {
|
||||
// Cannot delete admin group
|
||||
$this->logger->error("Deleting admin group is not allowed");
|
||||
return new SCIMErrorResponse(['message' => 'Can\'t delete admin group'], 403);
|
||||
}
|
||||
|
||||
$deleteRes = $this->repository->delete($id);
|
||||
public function create(CoreGroup $scimGroup): CoreGroup {
|
||||
// Validate name
|
||||
if (empty($scimGroup->getDisplayName())) {
|
||||
$this->logger->error('Group name not supplied', ['app' => 'provisioning_api']);
|
||||
throw new Exception('Invalid group name', 400);
|
||||
}
|
||||
// Check if it exists
|
||||
if ($this->groupManager->groupExists($scimGroup->getDisplayName())) {
|
||||
$this->logger->error("Group to be created already exists");
|
||||
throw new Exception('Group exists', 409);
|
||||
}
|
||||
|
||||
if ($deleteRes) {
|
||||
$response = new Response();
|
||||
$response->setStatus(204);
|
||||
return $response;
|
||||
} else {
|
||||
$this->logger->error("Deletion of group with ID " . $id . " failed");
|
||||
return new SCIMErrorResponse(['message' => 'Couldn\'t delete group'], 503);
|
||||
}
|
||||
}
|
||||
try {
|
||||
$this->logger->info("Creating group with displayName: " . $scimGroup->getDisplayName());
|
||||
|
||||
$ncGroup = $this->groupManager->createGroup($scimGroup->getDisplayName());
|
||||
$this->updateGroup($ncGroup, $scimGroup);
|
||||
} catch (Exception $e) {
|
||||
$this->logger->warning('Failed createGroup attempt with SCIMException exception.', ['app' => Application::APP_ID]);
|
||||
throw $e;
|
||||
}
|
||||
|
||||
return $this->get($ncGroup->getGID());
|
||||
}
|
||||
|
||||
public function update(string $id, CoreGroup $scimGroup): CoreGroup {
|
||||
$this->logger->info("Updating group with ID: " . $id);
|
||||
|
||||
if (!$this->groupManager->groupExists($id)) {
|
||||
throw new Exception('Group not found', 404);
|
||||
}
|
||||
|
||||
$this->logger->info($scimGroup->toSCIM());
|
||||
// $this->atomic(function () use ($id, $scimGroup) {
|
||||
$ncGroup = $this->groupManager->get($id);
|
||||
$this->updateGroup($ncGroup, $scimGroup);
|
||||
// }, $this->db);
|
||||
|
||||
|
||||
$this->logger->info(json_encode($ncGroup->getUsers()));
|
||||
|
||||
return $this->get($id);
|
||||
}
|
||||
|
||||
public function destroy(string $id): void {
|
||||
$this->logger->info("Deleting group with ID: " . $id);
|
||||
|
||||
if ($id === 'admin') {
|
||||
// Cannot delete admin group
|
||||
$this->logger->error("Deleting admin group is not allowed");
|
||||
throw new Exception('Can\'t delete admin group', 403);
|
||||
}
|
||||
|
||||
|
||||
if (!$this->groupManager->groupExists($id)) {
|
||||
throw new Exception('Group not found', 404);
|
||||
}
|
||||
$ncGroup = $this->groupManager->get($id);
|
||||
$ncGroup->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Service;
|
||||
|
||||
use OC\Group\Manager;
|
||||
use OCP\IGroupManager;
|
||||
|
||||
class SCIMGroup {
|
||||
/** @var IGroupManager|Manager */ // FIXME Requires a method that is not on the interface
|
||||
protected $groupManager;
|
||||
|
||||
public function __construct(IGroupManager $groupManager) {
|
||||
$this->groupManager = $groupManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates an object with all group data
|
||||
*
|
||||
* @param string $groupId
|
||||
* @param bool $includeScopes
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(string $groupId): array {
|
||||
$groupId = urldecode($groupId);
|
||||
|
||||
// Check the group exists
|
||||
$group = $this->groupManager->get($groupId);
|
||||
if ($group === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$members = array();
|
||||
foreach ($this->groupManager->get($groupId)->getUsers() as $member) {
|
||||
$members[] = [
|
||||
'value' => $member->getUID(),
|
||||
'$ref' => '/Users/' . $member->getUID(),
|
||||
'display' => $member->getDisplayName()
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:Group'],
|
||||
'id' => $groupId,
|
||||
'displayName' => $group->getDisplayName(),
|
||||
'externalId' => '1234', // todo
|
||||
'meta' => [
|
||||
'resourceType' => 'Group',
|
||||
'location' => '/Groups/' . $groupId,
|
||||
'created' => '1970-01-01T00:00:00.000Z',
|
||||
'lastModified' => '1970-01-01T00:00:00.000Z'
|
||||
],
|
||||
'members' => $members
|
||||
];
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Service;
|
||||
|
||||
use OCA\SCIMServiceProvider\AppInfo\Application;
|
||||
use OCP\IConfig;
|
||||
use OCP\IUserManager;
|
||||
|
||||
class SCIMUser {
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
|
||||
public function __construct(IUserManager $userManager,
|
||||
IConfig $config) {
|
||||
$this->userManager = $userManager;
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates an object with all user data
|
||||
*
|
||||
* @param string $userId
|
||||
* @param bool $includeScopes
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function get(string $userId): array {
|
||||
// Check if the target user exists
|
||||
$targetUserObject = $this->userManager->get($userId);
|
||||
if ($targetUserObject === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$enabled = $this->config->getUserValue($targetUserObject->getUID(), 'core', 'enabled', 'true') === 'true';
|
||||
$externalId = $this->config->getUserValue($targetUserObject->getUID(), Application::APP_ID, 'externalId', '');
|
||||
$email = $targetUserObject->getSystemEMailAddress();
|
||||
|
||||
|
||||
$SCIMUser = [
|
||||
'schemas' => ["urn:ietf:params:scim:schemas:core:2.0:User"],
|
||||
'id' => $userId,
|
||||
'name' => [
|
||||
'formatted' => $targetUserObject->getDisplayName()
|
||||
],
|
||||
'meta' => [
|
||||
'resourceType' => 'User',
|
||||
'location' => '/Users/' . $userId,
|
||||
'created' => '1970-01-01T00:00:00.000Z',
|
||||
'lastModified' => '1970-01-01T00:00:00.000Z'
|
||||
],
|
||||
'userName' => $userId,
|
||||
'displayName' => $targetUserObject->getDisplayName(),
|
||||
'active' => $enabled
|
||||
];
|
||||
if ($externalId !== '') {
|
||||
$SCIMUser['externalId'] = $externalId;
|
||||
}
|
||||
if ($email !== null) {
|
||||
$SCIMUser['emails'] = [ // todo if no emails
|
||||
[
|
||||
'primary' => true,
|
||||
'value' => $email
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
return $SCIMUser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets externalId on user
|
||||
*
|
||||
* @param string $userId
|
||||
* @param string $externalId
|
||||
* @throws Exception
|
||||
*/
|
||||
public function setExternalId(string $userId, string $externalId) {
|
||||
$this->config->setUserValue($userId, Application::APP_ID, 'externalId', $externalId);
|
||||
}
|
||||
|
||||
}
|
|
@ -5,146 +5,148 @@ declare(strict_types=1);
|
|||
namespace OCA\SCIMServiceProvider\Service;
|
||||
|
||||
use Exception;
|
||||
use OCA\SCIMServiceProvider\AppInfo\Application;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMErrorResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMJSONResponse;
|
||||
use OCA\SCIMServiceProvider\Responses\SCIMListResponse;
|
||||
use OCA\SCIMServiceProvider\Util\Util;
|
||||
use OCP\AppFramework\Http\Response;
|
||||
use OCP\IRequest;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
use OCP\Security\ISecureRandom;
|
||||
use Opf\Models\SCIM\Standard\Meta;
|
||||
use Opf\Models\SCIM\Standard\MultiValuedAttribute;
|
||||
use Opf\Models\SCIM\Standard\Users\CoreUser;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class UserService
|
||||
{
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
class UserService {
|
||||
/** @var LoggerInterface */
|
||||
private $logger;
|
||||
|
||||
/** @var \OCA\SCIMServiceProvider\Repositories\Users\NextcloudUserRepository */
|
||||
private $repository;
|
||||
private IUserManager $userManager;
|
||||
|
||||
/** @var IRequest */
|
||||
private $request;
|
||||
/** @var \OCP\Security\ISecureRandom */
|
||||
private $secureRandom;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
$this->repository = $container->get('UserRepository');
|
||||
$this->request = $container->get(IRequest::class);
|
||||
}
|
||||
public function __construct(LoggerInterface $logger, IUserManager $userManager, ISecureRandom $secureRandom) {
|
||||
$this->logger = $logger;
|
||||
$this->userManager = $userManager;
|
||||
$this->secureRandom = $secureRandom;
|
||||
}
|
||||
|
||||
public function getAll(string $filter = ''): SCIMListResponse
|
||||
{
|
||||
$this->logger->info("Reading all users");
|
||||
private function toSCIM(IUser $ncUser): CoreUser {
|
||||
$scimUser = new CoreUser();
|
||||
$scimUser->setId($ncUser->getUID());
|
||||
$scimUser->setUserName($ncUser->getUID());
|
||||
$scimUser->setDisplayName($ncUser->getDisplayName());
|
||||
$scimUser->setActive($ncUser->isEnabled());
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://"
|
||||
. $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
$emails = [];
|
||||
if (!empty($ncUser->getSystemEMailAddress())) {
|
||||
$email = new MultiValuedAttribute();
|
||||
$email->setValue($ncUser->getSystemEMailAddress());
|
||||
$emails[] = $email;
|
||||
}
|
||||
$scimUser->setEmails($emails);
|
||||
|
||||
$users = $this->repository->getAll($filter);
|
||||
$meta = new Meta();
|
||||
$meta->setResourceType("User");
|
||||
|
||||
$scimUsers = [];
|
||||
if (!empty($users)) {
|
||||
foreach ($users as $user) {
|
||||
$scimUsers[] = $user->toSCIM(false, $baseUrl);
|
||||
}
|
||||
}
|
||||
$scimUser->setMeta($meta);
|
||||
|
||||
return new SCIMListResponse($scimUsers);
|
||||
}
|
||||
return $scimUser;
|
||||
}
|
||||
|
||||
public function getOneById(string $id): SCIMJSONResponse
|
||||
{
|
||||
$this->logger->info("Reading user with ID: " . $id);
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
private function updateUser(IUser $ncUser, CoreUser $scimUser) {
|
||||
$displayName = $scimUser->getDisplayName();
|
||||
if (isset($displayName)) {
|
||||
$ncUser->setDisplayName($displayName);
|
||||
}
|
||||
|
||||
$user = $this->repository->getOneById($id);
|
||||
if (!isset($user) || empty($user)) {
|
||||
$this->logger->error("User with ID " . $id . " not found");
|
||||
return new SCIMErrorResponse(['message' => 'User not found'], 404);
|
||||
}
|
||||
return new SCIMJSONResponse($user->toSCIM(false, $baseUrl));
|
||||
}
|
||||
$emails = $scimUser->getEmails();
|
||||
if (isset($emails)) {
|
||||
if (sizeof($emails) > 0) {
|
||||
$ncUser->setSystemEMailAddress($emails[0]->getValue());
|
||||
} else {
|
||||
$ncUser->setSystemEMailAddress("");
|
||||
}
|
||||
}
|
||||
|
||||
public function create(
|
||||
bool $active = true,
|
||||
string $displayName = '',
|
||||
array $emails = [],
|
||||
string $externalId = '',
|
||||
string $userName = ''
|
||||
): SCIMJSONResponse
|
||||
{
|
||||
try {
|
||||
$this->logger->info("Creating user with userName: " . $userName);
|
||||
$active = $scimUser->getActive();
|
||||
if ($active !== null) {
|
||||
$ncUser->setEnabled($active);
|
||||
}
|
||||
}
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
public function countAll(): int {
|
||||
$count = 0;
|
||||
foreach ($this->userManager->countUsers() as $key => $value) {
|
||||
$count = $count + $value;
|
||||
}
|
||||
return $count;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'active' => $active,
|
||||
'displayName' => $displayName,
|
||||
'emails' => $emails,
|
||||
'externalId' => $externalId,
|
||||
'userName' => $userName
|
||||
];
|
||||
public function getAll(int $startIndex, int $count = null): array {
|
||||
$this->logger->info("Reading all users");
|
||||
|
||||
$createdUser = $this->repository->create($data);
|
||||
if (isset($createdUser) && !empty($createdUser)) {
|
||||
return new SCIMJSONResponse($createdUser->toSCIM(false, $baseUrl), 201);
|
||||
} else {
|
||||
$this->logger->error("Creating user failed");
|
||||
return new SCIMErrorResponse(['message' => 'Creating user failed'], 400);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$this->logger->warning('Failed createUser attempt with SCIMException exeption.', ['app' => Application::APP_ID]);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
if ($count === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
public function update(
|
||||
string $id,
|
||||
bool $active,
|
||||
string $displayName = '',
|
||||
array $emails = []
|
||||
): SCIMJSONResponse
|
||||
{
|
||||
$this->logger->info("Updating user with ID: " . $id);
|
||||
$ncUsers = $this->userManager->search("", $count, $startIndex - 1);
|
||||
|
||||
$baseUrl = $this->request->getServerProtocol() . "://" . $this->request->getServerHost() . Util::SCIM_APP_URL_PATH;
|
||||
$scimUsers = [];
|
||||
foreach ($ncUsers as $ncUser) {
|
||||
$scimUsers[] = $this->toSCIM($ncUser);
|
||||
}
|
||||
|
||||
$user = $this->repository->getOneById($id);
|
||||
if (!isset($user) || empty($user)) {
|
||||
$this->logger->error("User with ID " . $id . " not found for update");
|
||||
return new SCIMErrorResponse(['message' => 'User not found'], 404);
|
||||
}
|
||||
return $scimUsers;
|
||||
}
|
||||
|
||||
$data = [
|
||||
'active' => $active,
|
||||
'displayName' => $displayName,
|
||||
'emails' => $emails
|
||||
];
|
||||
|
||||
$updatedUser = $this->repository->update($id, $data);
|
||||
if (isset($updatedUser) && !empty($updatedUser)) {
|
||||
return new SCIMJSONResponse($updatedUser->toSCIM(false, $baseUrl));
|
||||
} else {
|
||||
$this->logger->error("Updating user with ID " . $id . " failed");
|
||||
return new SCIMErrorResponse(['message' => 'Updating user failed'], 400);
|
||||
}
|
||||
}
|
||||
public function get(string $id): CoreUser {
|
||||
$this->logger->info("Reading user with ID: " . $id);
|
||||
|
||||
public function destroy(string $id): Response
|
||||
{
|
||||
$this->logger->info("Deleting user with ID: " . $id);
|
||||
if (!$this->userManager->userExists($id)) {
|
||||
throw new Exception("Not found", 404);
|
||||
}
|
||||
|
||||
$deleteRes = $this->repository->delete($id);
|
||||
$ncUser = $this->userManager->get($id);
|
||||
return $this->toSCIM($ncUser);
|
||||
}
|
||||
|
||||
if ($deleteRes) {
|
||||
$response = new Response();
|
||||
$response->setStatus(204);
|
||||
return $response;
|
||||
} else {
|
||||
$this->logger->error("Deletion of user with ID " . $id . " failed");
|
||||
return new SCIMErrorResponse(['message' => 'Couldn\'t delete user'], 503);
|
||||
}
|
||||
}
|
||||
public function create(CoreUser $scimUser): CoreUser {
|
||||
$this->logger->info("Creating user with userName: " . $scimUser->getUserName());
|
||||
|
||||
|
||||
if ($this->userManager->userExists($scimUser->getUserName())) {
|
||||
$this->logger->error("User to be created already exists");
|
||||
throw new Exception('User exists', 409);
|
||||
}
|
||||
|
||||
$ncUser = $this->userManager->createUser($scimUser->getUserName(), $this->secureRandom->generate(64));
|
||||
$this->updateUser($ncUser, $scimUser);
|
||||
|
||||
return $this->get($ncUser->getUID());
|
||||
}
|
||||
|
||||
public function update(string $id, CoreUser $scimUser): CoreUser {
|
||||
$this->logger->info("Updating user with ID: " . $id);
|
||||
|
||||
if (!$this->userManager->userExists($id)) {
|
||||
throw new Exception("Not found", 404);
|
||||
}
|
||||
|
||||
$this->logger->info($scimUser->toSCIM());
|
||||
|
||||
$ncUser = $this->userManager->get($id);
|
||||
$this->updateUser($ncUser, $scimUser);
|
||||
|
||||
return $this->get($id);
|
||||
}
|
||||
|
||||
public function destroy(string $id): void {
|
||||
$this->logger->info("Deleting user with ID: " . $id);
|
||||
|
||||
if (!$this->userManager->userExists($id)) {
|
||||
throw new Exception('User not found', 404);
|
||||
}
|
||||
$ncUser = $this->userManager->get($id);
|
||||
$ncUser->delete();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace OCA\SCIMServiceProvider\Util\Authentication;
|
||||
|
||||
use Exception;
|
||||
use Opf\ScimServerPhp\Firebase\JWT\JWT;
|
||||
use Opf\ScimServerPhp\Firebase\JWT\Key;
|
||||
use OCA\SCIMServiceProvider\Util\Util;
|
||||
use OCP\IUserManager;
|
||||
use Opf\Util\Authentication\AuthenticatorInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class BearerAuthenticator implements AuthenticatorInterface
|
||||
{
|
||||
/** @var \Psr\Log\LoggerInterface */
|
||||
private LoggerInterface $logger;
|
||||
|
||||
/** @var \OCP\IUserManager */
|
||||
private IUserManager $userManager;
|
||||
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->logger = $container->get(LoggerInterface::class);
|
||||
$this->userManager = $container->get(IUserManager::class);
|
||||
}
|
||||
|
||||
public function authenticate(string $credentials, array $authorizationInfo): bool
|
||||
{
|
||||
$jwtPayload = [];
|
||||
$jwtSecret = Util::getConfigFile()['jwt']['secret'];
|
||||
try {
|
||||
$jwtPayload = (array) JWT::decode($credentials, new Key($jwtSecret, 'HS256'));
|
||||
} catch (Exception $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
return false;
|
||||
}
|
||||
|
||||
// If the 'user' claim is missing from the JWT, then auth is considered to have failed
|
||||
if (!isset($jwtPayload['user']) || empty($jwtPayload['user'])) {
|
||||
$this->logger->error("No \"user\" claim found in JWT");
|
||||
return false;
|
||||
}
|
||||
|
||||
$username = $jwtPayload['user'];
|
||||
|
||||
// If we managed to find a user with that username, then auth succeeded
|
||||
$user = $this->userManager->get($username);
|
||||
if ($user !== null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$this->logger->error("User with this username doesn't exist");
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -2,15 +2,32 @@
|
|||
|
||||
namespace OCA\SCIMServiceProvider\Util;
|
||||
|
||||
class Util
|
||||
{
|
||||
public const SCIM_APP_URL_PATH = "index.php/apps/scimserviceprovider";
|
||||
use OCP\IRequest;
|
||||
|
||||
public static function getConfigFile()
|
||||
{
|
||||
$configFilePath = dirname(__DIR__) . '/Config/config.php';
|
||||
$config = require($configFilePath);
|
||||
class Util {
|
||||
public const SCIM_APP_URL_PATH = "index.php/apps/scimserviceprovider";
|
||||
|
||||
return $config;
|
||||
}
|
||||
public static function getBaseUrl(IRequest $request) : string {
|
||||
return $request->getServerProtocol() . "://" . $request->getServerHost() . "/" . Util::SCIM_APP_URL_PATH;
|
||||
}
|
||||
|
||||
public static function parsePagination(array $params): array {
|
||||
if (isset($params["startIndex"])) {
|
||||
$startIndex = intval($params["startIndex"]);
|
||||
if ($startIndex < 1) {
|
||||
$startIndex = 1;
|
||||
}
|
||||
$params["startIndex"] = $startIndex;
|
||||
} else {
|
||||
$params["startIndex"] = 1;
|
||||
}
|
||||
if (isset($params["count"])) {
|
||||
$count = intval($params["count"]);
|
||||
if ($count < 0) {
|
||||
$count = 0;
|
||||
}
|
||||
$params["count"] = $count;
|
||||
}
|
||||
return $params;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue