-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathidentity_sources.go
More file actions
212 lines (196 loc) · 8.19 KB
/
identity_sources.go
File metadata and controls
212 lines (196 loc) · 8.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package morpheus
import (
"fmt"
"time"
)
var (
// IdentitySourcesPath is the API endpoint for identity sources
IdentitySourcesPath = "/api/user-sources"
CreateIdentitySourcesPath = "/api/accounts"
)
// IdentitySource structures for use in request and response payloads
type IdentitySource struct {
ID int64 `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Code string `json:"code"`
Type string `json:"type"`
Active bool `json:"active"`
Deleted bool `json:"deleted"`
AutoSyncOnLogin bool `json:"autoSyncOnLogin"`
ExternalLogin bool `json:"externalLogin"`
AllowCustomMappings bool `json:"allowCustomMappings"`
Account struct {
ID int64 `json:"id"`
Name string `json:"name"`
} `json:"account"`
DefaultAccountRole struct {
ID int64 `json:"id"`
Name string `json:"name"`
Authority string `json:"authority"`
} `json:"defaultAccountRole"`
Config struct {
URL string `json:"url"`
Domain string `json:"domain"`
UseSSL string `json:"useSSL"`
BindingUsername string `json:"bindingUsername"`
BindingPassword string `json:"bindingPassword"`
BindingPasswordHash string `json:"bindingPasswordHash"`
RequiredGroup string `json:"requiredGroup"`
SearchMemberGroups bool `json:"searchMemberGroups"`
RequiredGroupDN string `json:"requiredGroupDN"`
UserFqnExpression string `json:"userFqnExpression"`
RequiredRoleFqn string `json:"requiredRoleFqn"`
UsernameAttribute string `json:"usernameAttribute"`
CommonNameAttribute string `json:"commonNameAttribute"`
FirstNameAttribute string `json:"firstNameAttribute"`
LastNameAttribute string `json:"lastNameAttribute"`
EmailAttribute string `json:"emailAttribute"`
UniqueMemberAttribute string `json:"uniqueMemberAttribute"`
MemberOfAttribute string `json:"memberOfAttribute"`
OrganizationID string `json:"organizationId"`
RequiredRole string `json:"requiredRole"`
AdministratorAPIToken string `json:"administratorAPIToken"`
RequiredGroupID string `json:"requiredGroupId"`
Subdomain string `json:"subdomain"`
Region string `json:"region"`
ClientSecret string `json:"clientSecret"`
ClientID string `json:"clientId"`
RequiredRoleID string `json:"requiredRoleId"`
RoleAttributeName string `json:"roleAttributeName"`
RequiredAttributeValue string `json:"requiredAttributeValue"`
GivenNameAttribute string `json:"givenNameAttribute"`
SurnameAttribute string `json:"surnameAttribute"`
LogoutURL string `json:"logoutUrl"`
LoginURL string `json:"loginUrl"`
EncryptionAlgorithim string `json:"encryptionAlgo"`
EncryptionKey string `json:"encryptionKey"`
APIStyle string `json:"apiStyle"`
DoNotIncludeSAMLRequest bool `json:"doNotIncludeSAMLRequest"`
DoNotValidateSignature bool `json:"doNotValidateSignature"`
DoNotValidateStatusCode bool `json:"doNotValidateStatusCode"`
DoNotValidateDestination bool `json:"doNotValidateDestination"`
DoNotValidateIssueInstants bool `json:"doNotValidateIssueInstants"`
DoNotValidateAssertions bool `json:"doNotValidateAssertions"`
DoNotValidateAuthStatements bool `json:"doNotValidateAuthStatements"`
DoNotValidateSubject bool `json:"doNotValidateSubject"`
DoNotValidateConditions bool `json:"doNotValidateConditions"`
DoNotValidateAudiences bool `json:"doNotValidateAudiences"`
DoNotValidateSubjectRecipients bool `json:"doNotValidateSubjectRecipients"`
SAMLSignatureMode string `json:"SAMLSignatureMode"`
Endpoint string `json:"endpoint"`
Logout string `json:"logout"`
Request509Certificate string `json:"request509Certificate"`
RequestPrivateKey string `json:"requestPrivateKey"`
PublicKey string `json:"publicKey"`
PrivateKey string `json:"privateKey"`
} `json:"config"`
RoleMappings []struct {
SourceRoleName string `json:"sourceRoleName"`
SourceRoleFqn string `json:"sourceRoleFqn"`
MappedRole struct {
ID int64 `json:"id"`
Name string `json:"string"`
Authority string `json:"authority"`
} `json:"mappedRole"`
} `json:"roleMappings"`
Subdomain string `json:"subdomain"`
LoginURL string `json:"loginURL"`
ProviderSettings struct {
} `json:"providerSettings"`
DateCreated time.Time `json:"dateCreated"`
LastUpdated time.Time `json:"lastUpdated"`
}
// ListIdentitySourcesResult structure parses the list identity source response payload
type ListIdentitySourcesResult struct {
IdentitySources *[]IdentitySource `json:"userSources"`
Meta *MetaResult `json:"meta"`
}
type GetIdentitySourceResult struct {
IdentitySource *IdentitySource `json:"userSource"`
}
type CreateIdentitySourceResult struct {
Success bool `json:"success"`
Message string `json:"msg"`
Errors map[string]string `json:"errors"`
IdentitySource *IdentitySource `json:"userSource"`
}
type UpdateIdentitySourceResult struct {
CreateIdentitySourceResult
}
type DeleteIdentitySourceResult struct {
DeleteResult
}
// Client request methods
func (client *Client) ListIdentitySources(req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: IdentitySourcesPath,
QueryParams: req.QueryParams,
Result: &ListIdentitySourcesResult{},
})
}
func (client *Client) GetIdentitySource(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "GET",
Path: fmt.Sprintf("%s/%d", IdentitySourcesPath, id),
QueryParams: req.QueryParams,
Result: &GetIdentitySourceResult{},
})
}
func (client *Client) CreateIdentitySource(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "POST",
Path: fmt.Sprintf("%s/%d/user-sources", CreateIdentitySourcesPath, id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &CreateIdentitySourceResult{},
})
}
func (client *Client) UpdateIdentitySource(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("%s/%d", IdentitySourcesPath, id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateIdentitySourceResult{},
})
}
func (client *Client) UpdateIdentitySourceSubdomain(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "PUT",
Path: fmt.Sprintf("%s/%d/subdomain", IdentitySourcesPath, id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &UpdateIdentitySourceResult{},
})
}
func (client *Client) DeleteIdentitySource(id int64, req *Request) (*Response, error) {
return client.Execute(&Request{
Method: "DELETE",
Path: fmt.Sprintf("%s/%d", IdentitySourcesPath, id),
QueryParams: req.QueryParams,
Body: req.Body,
Result: &DeleteIdentitySourceResult{},
})
}
// helper functions
func (client *Client) FindIdentitySourceByName(name string) (*Response, error) {
// Find by name, then get by ID
resp, err := client.ListIdentitySources(&Request{
QueryParams: map[string]string{
"name": name,
},
})
if err != nil {
return resp, err
}
listResult := resp.Result.(*ListIdentitySourcesResult)
userSourceCount := len(*listResult.IdentitySources)
if userSourceCount != 1 {
return resp, fmt.Errorf("found %d Identity Sources for %v", userSourceCount, name)
}
firstRecord := (*listResult.IdentitySources)[0]
userSourceID := firstRecord.ID
return client.GetIdentitySource(userSourceID, &Request{})
}