@@ -2,88 +2,22 @@ package goauth2
22
33import (
44 "github.com/inklabs/rangedb"
5- "github.com/inklabs/rangedb/pkg/clock"
65)
76
8- type authorizationCommandHandler struct {
9- store rangedb.Store
10- pendingEvents []rangedb.Event
11- tokenGenerator TokenGenerator
12- clock clock.Clock
7+ type clientApplicationCommandAuthorization struct {
8+ store rangedb.Store
9+ pendingEvents []rangedb.Event
1310}
1411
15- func newAuthorizationCommandHandler (
16- store rangedb.Store ,
17- tokenGenerator TokenGenerator ,
18- clock clock.Clock ,
19- ) * authorizationCommandHandler {
20- return & authorizationCommandHandler {
21- store : store ,
22- tokenGenerator : tokenGenerator ,
23- clock : clock ,
12+ func newClientApplicationCommandAuthorization (store rangedb.Store ) * clientApplicationCommandAuthorization {
13+ return & clientApplicationCommandAuthorization {
14+ store : store ,
2415 }
2516}
2617
27- func (h * authorizationCommandHandler ) Handle (command Command ) bool {
18+ func (h * clientApplicationCommandAuthorization ) Handle (command Command ) bool {
2819 switch c := command .(type ) {
2920
30- case GrantUserAdministratorRole :
31- grantingUser := h .loadResourceOwnerAggregate (c .GrantingUserID )
32-
33- if ! grantingUser .IsOnBoarded {
34- h .emit (GrantUserAdministratorRoleWasRejectedDueToMissingGrantingUser {
35- UserID : c .UserID ,
36- GrantingUserID : c .GrantingUserID ,
37- })
38- return false
39- }
40-
41- if ! grantingUser .IsAdministrator {
42- h .emit (GrantUserAdministratorRoleWasRejectedDueToNonAdministrator {
43- UserID : c .UserID ,
44- GrantingUserID : c .GrantingUserID ,
45- })
46- return false
47- }
48-
49- case AuthorizeUserToOnBoardClientApplications :
50- authorizingUser := h .loadResourceOwnerAggregate (c .AuthorizingUserID )
51-
52- if ! authorizingUser .IsOnBoarded {
53- h .emit (AuthorizeUserToOnBoardClientApplicationsWasRejectedDueToMissingAuthorizingUser {
54- UserID : c .UserID ,
55- AuthorizingUserID : c .AuthorizingUserID ,
56- })
57- return false
58- }
59-
60- if ! authorizingUser .IsAdministrator {
61- h .emit (AuthorizeUserToOnBoardClientApplicationsWasRejectedDueToNonAdministrator {
62- UserID : c .UserID ,
63- AuthorizingUserID : c .AuthorizingUserID ,
64- })
65- return false
66- }
67-
68- case OnBoardClientApplication :
69- resourceOwner := h .loadResourceOwnerAggregate (c .UserID )
70-
71- if ! resourceOwner .IsOnBoarded {
72- h .emit (OnBoardClientApplicationWasRejectedDueToUnAuthorizeUser {
73- ClientID : c .ClientID ,
74- UserID : c .UserID ,
75- })
76- return false
77- }
78-
79- if ! resourceOwner .IsAuthorizedToOnboardClientApplications {
80- h .emit (OnBoardClientApplicationWasRejectedDueToUnAuthorizeUser {
81- ClientID : c .ClientID ,
82- UserID : c .UserID ,
83- })
84- return false
85- }
86-
8721 case RequestAccessTokenViaImplicitGrant :
8822 clientApplication := h .loadClientApplicationAggregate (c .ClientID )
8923
@@ -195,18 +129,14 @@ func (h *authorizationCommandHandler) Handle(command Command) bool {
195129 return true
196130}
197131
198- func (h * authorizationCommandHandler ) emit (events ... rangedb.Event ) {
132+ func (h * clientApplicationCommandAuthorization ) emit (events ... rangedb.Event ) {
199133 h .pendingEvents = append (h .pendingEvents , events ... )
200134}
201135
202- func (h * authorizationCommandHandler ) loadResourceOwnerAggregate (userID string ) * resourceOwner {
203- return newResourceOwner (h .store .AllEventsByStream (resourceOwnerStream (userID )), h .tokenGenerator , h .clock )
204- }
205-
206- func (h * authorizationCommandHandler ) loadClientApplicationAggregate (clientID string ) * clientApplication {
136+ func (h * clientApplicationCommandAuthorization ) loadClientApplicationAggregate (clientID string ) * clientApplication {
207137 return newClientApplication (h .store .AllEventsByStream (clientApplicationStream (clientID )))
208138}
209139
210- func (h * authorizationCommandHandler ) GetPendingEvents () []rangedb.Event {
140+ func (h * clientApplicationCommandAuthorization ) GetPendingEvents () []rangedb.Event {
211141 return h .pendingEvents
212142}
0 commit comments