forked from JesseCoretta/go-aci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dn.go
1729 lines (1422 loc) · 51.7 KB
/
dn.go
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package aci
/*
dn.go contains distinguished name types and methods.
*/
/*
Commonly-used distinguished name expression preambles.
*/
var (
// LocalScheme is the localhost-implicit scheme prefix for a DN. For security
// reasons, the LDAP scheme should never be non-local within the context of an
// ACI (even if proxy operations are involved). For instance:
//
// ldap://ldap.example.com/ou=People,dc=example,dc=com??one?(objectClass=*) // BAD
//
// ldap:///ou=People,dc=example,dc=com??one?(objectClass=*) // GOOD
//
// This constant is automatically used in any request related to the string
// representation of distinguished name instances. It is exported and visible
// to users for reference purposes only, and generally need not be accessed
// directly.
LocalScheme = `ldap:///`
// AllDN is the BindRule abstraction of all *known user* DNs; this does not imply ANONYMOUS DNs
AllDN BindDistinguishedName
// AnyDN is the BindRule abstraction of all user DNs, known or anonymous
AnyDN BindDistinguishedName
// SelfDN is the BindRule abstraction of a user's own DN
SelfDN BindDistinguishedName
// ParentDN is the BindRule abstraction of a user's superior DN
ParentDN BindDistinguishedName
// badBindDN is an empty BindDistinguishedName struct returned when
// a DN operation fails for some reason.
badBindDN BindDistinguishedName
// targetBindDN is an empty TargetDistinguishedName struct returned
// when a DN operation fails for some reason.
badTargetDN TargetDistinguishedName
badBDN string = `<invalid_bind_distinguished_name>`
badTDN string = `<invalid_target_distinguished_name>`
)
/*
BindDistinguishedName describes a single distinguished name. For example:
ou=People,dc=example,dc=com
For efficiency reasons, the LDAP "local scheme" prefix (ldap:///) is not stored in literal form within any distinguished name instance, however it will appear during string representation operations, e.g.:
ldap:///ou=People,dc=example,dc=com
Instances of this kind can be crafted using the appropriate package-level function with the appropriate [BindKeyword] as the input argument:
- [UDN](<dn>, [BindUDN]) for a `userdn` [BindDistinguishedName]
- [GDN](<dn>, [BindGDN]) for a `groupdn` [BindDistinguishedName]
- [RDN](<dn>, [BindRDN]) for a `roledn` [BindDistinguishedName]
In order to fashion multi-valued [BindRule] instances using instances of this type, they must reside within an appropriate stack type instance. See the [BindDistinguishedNames] and [TargetDistinguishedNames] types for details.
*/
type BindDistinguishedName struct {
*distinguishedName
}
/*
TargetDistinguishedName describes a single distinguished name. For
example:
ou=People,dc=example,dc=com
For efficiency reasons, the LDAP "local scheme" prefix (ldap:///) is not
stored in literal form within any distinguished name instance, however it
will appear during string representation operations, e.g.:
ldap:///ou=People,dc=example,dc=com
Instances of this kind can be crafted using the DN package-level function
with the appropriate [Target] [Keyword] as the input argument:
• TDN(<dn>, [Target]) for a `target` Distinguished Name
• TTDN(<dn>, [TargetTo]) for a `target_to` Distinguished Name
• TFDN(<dn>, [TargetFrom]) for a `target_from` Distinguished Name
In order to fashion multi-valued [TargetRule] instances using values of this type,
they must reside within an appropriate stack type instance. For further details,
see the [BindDistinguishedNames] and [TargetDistinguishedNames] types.
*/
type TargetDistinguishedName struct {
*distinguishedName
}
/*
distinguishedName is the embedded type (as a pointer!) within instances of
DistinguishedName.
The following [TargetRule] keywords allow the (indirect) use of instances
of this type:
• [Target] `target`
• [TargetTo] `target_to`
• [TargetFrom] `target_from`
The following [BindRule] keywords allow the (indirect) use of instances
of this type:
• userdn
• roledn
• groupdn
*/
type distinguishedName struct {
Keyword // `target`, `target_[to|from]` `userdn`, `groupdn` or `roledn`
*string
}
/*
Valid returns an instance of error that reflects whether certain required elements or value combinations were present and deemed valid.
A non-nil error indicates an undesirable receiver state.
*/
func (r BindDistinguishedName) Valid() (err error) {
return validDistinguishedName(r)
}
/*
isDistinguishedNameContext exists to prevent false positive qualifiers of the [DistinguishedNameContext] interface.
*/
func (r BindDistinguishedName) isDistinguishedNameContext() {}
/*
Compare returns a Boolean value indicative of a SHA-1 comparison between the receiver (r) and input value x.
*/
func (r BindDistinguishedName) Compare(x any) bool {
return compareHashInstance(r, x)
}
/*
Valid returns an instance of error that reflects whether certain required elements or value combinations were present and deemed valid.
A non-nil error indicates an undesirable receiver state.
*/
func (r TargetDistinguishedName) Valid() (err error) {
return validDistinguishedName(r)
}
func validDistinguishedName(x any) (err error) {
switch tv := x.(type) {
case BindDistinguishedName:
if tv.IsZero() {
err = nilInstanceErr(tv)
}
case TargetDistinguishedName:
if tv.IsZero() {
err = nilInstanceErr(tv)
}
}
return
}
/*
Keyword returns the [Keyword] assigned to the receiver instance. This shall be the keyword that appears in a [BindRule] bearing the receiver as a condition value.
*/
func (r BindDistinguishedName) Keyword() Keyword {
if r.isZero() {
return nil
}
return r.distinguishedName.Keyword
}
/*
Keyword returns the [Keyword] assigned to the receiver instance. This shall be the keyword that appears in a [TargetRule] bearing the receiver as a condition value.
*/
func (r TargetDistinguishedName) Keyword() Keyword {
if err := r.Valid(); err != nil {
return nil
}
return r.distinguishedName.Keyword
}
/*
Valid wraps the [stackage.Stack.Valid] method.
*/
func (r BindDistinguishedNames) Valid() error {
return r.cast().Valid()
}
/*
Valid wraps the [stackage.Stack.Valid] method.
*/
func (r TargetDistinguishedNames) Valid() error {
return r.cast().Valid()
}
/*
Kind returns the string name `bind`.
*/
func (r BindDistinguishedName) Kind() string {
return bindRuleID
}
/*
Kind returns the string name `target`.
*/
func (r TargetDistinguishedName) Kind() string {
return targetRuleID
}
/*
isDistinguishedNameContext exists to prevent false positive qualifiers
of the DistinguishedNameContext interface.
*/
func (r TargetDistinguishedName) isDistinguishedNameContext() {}
/*
Compare returns a Boolean value indicative of a SHA-1 comparison
between the receiver (r) and input value x.
*/
func (r TargetDistinguishedName) Compare(x any) bool {
return compareHashInstance(r, x)
}
/*
String is a stringer method that returns the string representation
of the receiver instance.
The Local LDAP scheme (ldap:///) is automatically imposed during
the string representation of the value; this is required by the
ACIv3 syntax.
*/
func (r BindDistinguishedName) String() string {
if err := r.Valid(); err != nil {
return badBDN
}
return sprintf("%s%s", LocalScheme, (*r.distinguishedName.string))
}
/*
Len returns 0 or 1 to describe an abstract length of
the receiver. This method exists only to satisfy Go's
interface signature requirements and need not be used
for any legitimate operation.
A length of zero (0) is returned if the receiver is
uninitialized or invalid in some way. A length of one
(1) is returned otherwise.
*/
func (r BindDistinguishedName) Len() int {
if err := r.Valid(); err != nil {
return 0
}
return 1
}
/*
String is a stringer method that returns the string representation
of the receiver instance.
The Local LDAP scheme (ldap:///) is automatically imposed during
the string representation of the value; this is required by the
ACIv3 syntax.
*/
func (r TargetDistinguishedName) String() string {
if err := r.Valid(); err != nil {
return badTDN
}
return sprintf("%s%s", LocalScheme, (*r.distinguishedName.string))
}
/*
Len returns 0 or 1 to describe an abstract length of
the receiver. This method exists only to satisfy Go's
interface signature requirements and need not be used.
*/
func (r TargetDistinguishedName) Len() int {
if err := r.Valid(); err != nil {
return 0
}
return 1
}
/*
IsZero returns a Boolean value indicative of whether the receiver
is considered nil, or unset.
*/
func (r BindDistinguishedName) IsZero() bool {
return r.distinguishedName.isZero()
}
/*
IsZero returns a Boolean value indicative of whether the receiver
is considered nil, or unset.
*/
func (r TargetDistinguishedName) IsZero() bool {
return r.distinguishedName.isZero()
}
/*
Set assigns value x to the receiver to represent an distinguished name in
the context of a [BindRule].
This method presents an opportunity for setting a DN at a later point versus
doing so during the initialization process alone and is totally optional.
If no keyword is specified, the userdn keyword context is supplied automatically,
which may or may not be what the caller wants.
*/
func (r *BindDistinguishedName) Set(x string, kw ...BindKeyword) BindDistinguishedName {
// default keyword, if unspecified by caller,
// is the main DN context `userdn`.
var key BindKeyword = BindUDN
if len(kw) > 0 {
// perform a keyword switch
switch kw[0] {
case BindGDN, BindRDN:
// keyword is verified to be
// related to bindrule DNs of
// some kind.
key = kw[0]
}
}
// if the receiver was not initialized, do so now
if r.IsZero() {
*r = BindDistinguishedName{newDistinguishedName(x, key)}
}
// set it and go
r.distinguishedName.set(x, key)
return *r
}
/*
Set assigns value x to the receiver to represent an distinguished name in
the context of a [TargetRule].
This method presents an opportunity for setting a DN at a later point versus
doing so during the initialization process alone and is totally optional.
If no keyword is specified, the target keyword context is supplied automatically,
which may or may not be what the caller wants.
*/
func (r *TargetDistinguishedName) Set(x string, kw ...TargetKeyword) TargetDistinguishedName {
// default keyword, if unspecified by caller,
// is the main DN context `userdn`.
var key TargetKeyword = Target
if len(kw) > 0 {
// perform a keyword switch
switch kw[0] {
case TargetTo, TargetFrom:
// keyword is verified to be
// related to bindrule DNs of
// some kind.
key = kw[0]
}
}
// if the receiver was not initialized, do so now
if r.IsZero() {
*r = TargetDistinguishedName{newDistinguishedName(x, key)}
}
// set it and go
r.distinguishedName.set(x, key)
return *r
}
/*
isZero is a private method called by DistinguishedName.IsZero.
*/
func (r *distinguishedName) isZero() bool {
if r == nil {
return true
}
return r.string == nil
}
/*
set is a private method called during the assembly of an underlying
Target or Bind (embedded) distinguishedName instance. This presents
an opportunity for setting a DN at a later point versus doing so
during the initialization process.
*/
func (r *distinguishedName) set(x string, kw Keyword) {
if len(x) == 0 {
return
}
_r := newDistinguishedName(x, kw)
*r = *_r
}
/*
UDN initializes, sets and returns an instance of [BindDistinguishedName].
A distinguished name in string form is required.
The return value shall be suitable for use in creating a [BindRule] that bears the [BindUDN] [BindKeyword].
*/
func UDN(x string) BindDistinguishedName {
return BindDistinguishedName{newDistinguishedName(x, BindUDN)}
}
/*
RDN initializes, sets and returns an instance of [BindDistinguishedName]. A distinguished name in string form is required.
The return value shall be suitable for use in creating a [BindRule] that bears the [BindRDN] [BindKeyword].
*/
func RDN(x string) BindDistinguishedName {
return BindDistinguishedName{newDistinguishedName(x, BindRDN)}
}
/*
GDN initializes, sets and returns an instance of [BindDistinguishedName]. A distinguished name in string form is required.
The return value shall be suitable for use in creating a [BindRule] that bears the [BindGDN] [BindKeyword].
*/
func GDN(x string) BindDistinguishedName {
return BindDistinguishedName{newDistinguishedName(x, BindGDN)}
}
/*
TDN initializes, sets and returns an instance of [TargetDistinguishedName] in one shot. A distinguished name in string form is required.
The return value shall be suitable for use in creating a [TargetRule] instance that bears the [Target] [TargetKeyword].
*/
func TDN(x string) TargetDistinguishedName {
return TargetDistinguishedName{newDistinguishedName(x, Target)}
}
/*
TTDN initializes, sets and returns an instance of [TargetDistinguishedName] in one shot. A distinguished name in string form is required.
The return value shall be suitable for use in creating a [TargetRule] instance that bears the [TargetTo] [TargetKeyword].
*/
func TTDN(x string) TargetDistinguishedName {
return TargetDistinguishedName{newDistinguishedName(x, TargetTo)}
}
/*
TFDN initializes, sets and returns an instance of [TargetDistinguishedName] in one shot. A distinguished name in string form is required.
The return value shall be suitable for use in creating a TargetRule instance that bears the [TargetFrom] [TargetKeyword].
*/
func TFDN(x string) TargetDistinguishedName {
return TargetDistinguishedName{newDistinguishedName(x, TargetFrom)}
}
/*
newDistinguishedName is a private function that returns a new instance of *distinguishedName. This function is called by the UDN, RDN, GDN, TDN, TTDN and TFDN functions.
*/
func newDistinguishedName(x string, kw Keyword) (d *distinguishedName) {
d = new(distinguishedName)
d.Keyword = kw
if len(x) != 0 {
x = chopDNPfx(x)
d.string = &x
}
return d
}
func (r BindDistinguishedNames) reset() {
r.cast().Reset()
}
/*
*/
func (r BindDistinguishedNames) resetKeyword(x any) {
if r.Len() > 0 {
return
}
switch tv := x.(type) {
case BindKeyword:
r.resetKeyword(tv.String())
case string:
_r := r.cast()
switch lc(tv) {
case BindUDN.String():
_r.SetCategory(BindUDN.String()).
SetPushPolicy(r.uDNPushPolicy)
case BindRDN.String():
_r.SetCategory(BindRDN.String()).
SetPushPolicy(r.rDNPushPolicy)
case BindGDN.String():
_r.SetCategory(BindGDN.String()).
SetPushPolicy(r.gDNPushPolicy)
}
}
}
func (r TargetDistinguishedNames) reset() {
r.cast().Reset()
}
/*
*/
func (r TargetDistinguishedNames) resetKeyword(x any) {
if r.Len() > 0 {
return
}
switch tv := x.(type) {
case TargetKeyword:
r.resetKeyword(tv.String())
case string:
_r := r.cast()
switch lc(tv) {
case Target.String():
_r.SetCategory(Target.String()).
SetPushPolicy(r.tDNPushPolicy)
case TargetTo.String():
_r.SetCategory(TargetTo.String()).
SetPushPolicy(r.tToDNPushPolicy)
case TargetFrom.String():
_r.SetCategory(TargetFrom.String()).
SetPushPolicy(r.tFromDNPushPolicy)
}
}
}
/*
Compare returns a Boolean value indicative of a SHA-1 comparison between the receiver (r) and input value x.
*/
func (r BindDistinguishedNames) Compare(x any) bool {
return compareHashInstance(r, x)
}
/*
Compare returns a Boolean value indicative of a SHA-1 comparison between the receiver (r) and input value x.
*/
func (r TargetDistinguishedNames) Compare(x any) bool {
return compareHashInstance(r, x)
}
/*
BRM returns an instance of [BindRuleMethods].
Each of the return instance's key values represent a single instance of the [ComparisonOperator] type that is allowed for use in the creation of [BindRule] instances which bear the receiver instance as an expression value. The value for each key is the actual [BindRuleMethod] instance for OPTIONAL use in the creation of a [BindRule] instance.
This is merely a convenient alternative to maintaining knowledge of which [ComparisonOperator] instances apply to which types. Instances of this type are also used to streamline package unit tests.
Please note that if the receiver is in an aberrant state, or if it has not yet been initialized, the execution of ANY of the return instance's value methods will return bogus [BindRule] instances. While this is useful in unit testing, the end user must only execute this method IF and WHEN the receiver has been properly populated and prepared for such activity.
*/
func (r BindDistinguishedName) BRM() BindRuleMethods {
return newBindRuleMethods(bindRuleFuncMap{
Eq: r.Eq,
Ne: r.Ne,
})
}
/*
BRM returns an instance of [BindRuleMethods].
Each of the return instance's key values represent a single instance of the [ComparisonOperator] type that is allowed for use in the creation of [BindRule] instances which bear the receiver instance as an expression value. The value for each key is the actual [BindRuleMethod] instance for OPTIONAL use in the creation of a [BindRule] instance.
This is merely a convenient alternative to maintaining knowledge of which [ComparisonOperator] instances apply to which types. Instances of this type are also used to streamline package unit tests.
Please note that if the receiver is in an aberrant state, or if it has not yet been initialized, the execution of ANY of the return instance's value methods will return bogus [BindRule] instances. While this is useful in unit testing, the end user must only execute this method IF and WHEN the receiver has been properly populated and prepared for such activity.
*/
func (r BindDistinguishedNames) BRM() BindRuleMethods {
return newBindRuleMethods(bindRuleFuncMap{
Eq: r.Eq,
Ne: r.Ne,
})
}
/*
TRM returns an instance of [TargetRuleMethods].
Each of the return instance's key values represent a single instance of the [ComparisonOperator] type that is allowed for use in the creation of [TargetRule] instances which bear the receiver instance as an expression value. The value for each key is the actual [TargetRuleMethod] instance for OPTIONAL use in the creation of a [TargetRule] instance.
This is merely a convenient alternative to maintaining knowledge of which [ComparisonOperator] instances apply to which types. Instances of this type are also used to streamline package unit tests.
Please note that if the receiver is in an aberrant state, or if it has not yet been initialized, the execution of ANY of the return instance's value methods will return bogus [TargetRule] instances. While this is useful in unit testing, the end user must only execute this method IF and WHEN the receiver has been properly populated and prepared for such activity.
*/
func (r TargetDistinguishedName) TRM() TargetRuleMethods {
return newTargetRuleMethods(targetRuleFuncMap{
Eq: r.Eq,
Ne: r.Ne,
})
}
/*
TRM returns an instance of [TargetRuleMethods].
Each of the return instance's key values represent a single instance of the [ComparisonOperator] type that is allowed for use in the creation of [TargetRule] instances which bear the receiver instance as an expression value. The value for each key is the actual [TargetRuleMethod] instance for OPTIONAL use in the creation of a [TargetRule] instance.
This is merely a convenient alternative to maintaining knowledge of which [ComparisonOperator] instances apply to which types. Instances of this type are also used to streamline package unit tests.
Please note that if the receiver is in an aberrant state, or if it has not yet been initialized, the execution of ANY of the return instance's value methods will return bogus [TargetRule] instances. While this is useful in unit testing, the end user must only execute this method IF and WHEN the receiver has been properly populated and prepared for such activity.
*/
func (r TargetDistinguishedNames) TRM() TargetRuleMethods {
return newTargetRuleMethods(targetRuleFuncMap{
Eq: r.Eq,
Ne: r.Ne,
})
}
/*
ID returns the string literal `bind`.
*/
func (r BindDistinguishedNames) ID() string {
return `bind`
}
/*
ID returns the string literal `target`.
*/
func (r TargetDistinguishedNames) ID() string {
return `target`
}
/*
setQuoteStyle shall set the receiver instance to the quotation scheme defined by integer i.
*/
func (r BindDistinguishedNames) setQuoteStyle(style int) BindDistinguishedNames {
_r := r.cast()
if _r.Len() < 2 {
_r.Encap() // not multivalued, force default
return r
}
if style == MultivalSliceQuotes {
_r.Encap(`"`)
} else {
_r.Encap()
}
return r
}
/*
setQuoteStyle shall set the receiver instance to the quotation scheme defined by integer i.
*/
func (r TargetDistinguishedNames) setQuoteStyle(style int) TargetDistinguishedNames {
_r := r.cast()
if _r.Len() < 2 {
_r.Encap() // not multivalued, force default
return r
}
if style == MultivalSliceQuotes {
_r.Encap(`"`)
} else {
_r.Encap()
}
return r
}
/*
Eq initializes and returns a new [BindRule] instance configured to express the evaluation of the receiver value as Equal-To one (1) of the following [BindKeyword] contexts:
- [BindUDN] `userdn`
- [BindGDN] `groupdn`
- [BindRDN] `roledn`
*/
func (r BindDistinguishedName) Eq() BindRule {
x, ok := dnToCondition(r, Eq)
if !ok {
return badBindRule
}
return x.(BindRule)
}
/*
Eq initializes and returns a new [TargetRule] instance configured to express the evaluation of the receiver value as Equal-To one (1) of the following [TargetKeyword] contexts:
- [Target] `target`
- [TargetTo] `target_to`
- [TargetFrom] `target_from`
*/
func (r TargetDistinguishedName) Eq() TargetRule {
x, ok := dnToCondition(r, Eq)
if !ok {
return badTargetRule
}
return x.(TargetRule)
}
/*
Ne initializes and returns a new [BindRule] instance configured to express the evaluation of the receiver value as Not-Equal-To one (1) of the following [BindKeyword] contexts:
- [BindUDN] `userdn`
- [BindGDN] `groupdn`
- [BindRDN] `roledn`
Negated equality [BindRule] instances should be used with caution.
*/
func (r BindDistinguishedName) Ne() BindRule {
x, ok := dnToCondition(r, Ne)
if !ok {
return badBindRule
}
return x.(BindRule)
}
/*
Ne initializes and returns a new [TargetRule] instance configured to express the evaluation of the receiver value as Not-Equal-To one (1) of the following [TargetKeyword] contexts:
- [Target] `target`
- [TargetTo] `target_to`
- [TargetFrom] `target_from`
Negated equality [TargetRule] instances should be used with caution.
*/
func (r TargetDistinguishedName) Ne() TargetRule {
x, ok := dnToCondition(r, Ne)
if !ok {
return badTargetRule
}
return x.(TargetRule)
}
/*
Eq initializes and returns a new [BindRule] instance configured to express the evaluation of the receiver value as Equal-To one (1) of the following [BindKeyword] contexts:
- [BindUDN] `userdn`
- [BindGDN] `groupdn`
- [BindRDN] `roledn`
*/
func (r BindDistinguishedNames) Eq() BindRule {
x, ok := dnToCondition(r, Eq)
if !ok {
return badBindRule
}
return x.(BindRule)
}
/*
Eq initializes and returns a new [TargetRule] instance configured to express the evaluation of the receiver value as Equal-To one (1) of the following [TargetKeyword] contexts:
- [Target] `target`
- [TargetTo] `target_to`
- [TargetFrom] `target_from`
*/
func (r TargetDistinguishedNames) Eq() TargetRule {
x, ok := dnToCondition(r, Eq)
if !ok {
return badTargetRule
}
return x.(TargetRule)
}
/*
Ne initializes and returns a new [BindRule] instance configured to express the evaluation of the receiver value as Not-Equal-To one (1) of the following [BindKeyword] contexts:
- [BindUDN] `userdn`
- [BindGDN] `groupdn`
- [BindRDN] `roledn`
Negated equality [BindRule] instances should be used with caution.
*/
func (r BindDistinguishedNames) Ne() BindRule {
x, ok := dnToCondition(r, Ne)
if !ok {
return badBindRule
}
return x.(BindRule)
}
/*
Ne initializes and returns a new [TargetRule] instance configured to express the evaluation of the receiver value as Not-Equal-To one (1) of the following [TargetKeyword] contexts:
- [Target] `target`
- [TargetTo] `target_to`
- [TargetFrom] `target_from`
Negated equality [TargetRule] instances should be used with caution.
*/
func (r TargetDistinguishedNames) Ne() TargetRule {
x, ok := dnToCondition(r, Ne)
if !ok {
return badTargetRule
}
return x.(TargetRule)
}
func dnToCondition(dest any, op ComparisonOperator) (c any, ok bool) {
c = badBindRule
switch tv := dest.(type) {
case BindDistinguishedNames:
// case matched bind rule DN(s)
c, ok = bindDNToCondition(tv, op)
case TargetDistinguishedNames:
// case matched target rule DN(s)
c, ok = targetDNToCondition(tv, op)
case BindDistinguishedName:
if tv.Kind() == bindRuleID {
c, ok = bindDNToCondition(tv, op)
}
case TargetDistinguishedName:
if tv.Kind() == targetRuleID {
c, ok = targetDNToCondition(tv, op)
}
}
return
}
func bindDNToCondition(dest any, op ComparisonOperator) (b BindRule, ok bool) {
b = badBindRule
var value any
var kw Keyword
switch tv := dest.(type) {
case BindDistinguishedName:
if tv.IsZero() {
return
}
value = tv
kw = tv.Keyword()
case BindDistinguishedNames:
if tv.IsZero() {
return
}
value = tv
kw = tv.Keyword()
}
if value != nil {
b = BR(kw, op, value)
ok = true
}
return
}
func targetDNToCondition(dest any, op ComparisonOperator) (t TargetRule, ok bool) {
t = badTargetRule
var value any
var kw Keyword
switch tv := dest.(type) {
case TargetDistinguishedName:
if tv.IsZero() {
return
}
value = tv
kw = tv.Keyword()
case TargetDistinguishedNames:
if tv.IsZero() {
return
}
value = tv
kw = tv.Keyword()
}
if value != nil {
t = TR(kw, op, value)
ok = true
}
return
}
/*
setExpressionValues is a private method called by assertBindUGRDN for DN-based Bind Rules parsing.
*/
func (r BindDistinguishedNames) setExpressionValues(key Keyword, values ...string) (err error) {
// iterate each string-based distinguishedName
// in the values sequence ...
for i := 0; i < len(values); i++ {
// Identify this distinguished name value
// as D, as referenced by index integer i.
//
// First, let's see if this is a URI, which
// is initially similar to a DN in the ACIv3
// syntax. If positive, push it and skip ahead.
if hasPfx(values[i], LocalScheme) && contains(values[i], `?`) {
var U LDAPURI
if U, err = parseLDAPURI(values[i], key.(BindKeyword)); err == nil {
r.Push(U)
}
} else {
//
// If the DN has the LocalScheme (ldap:///)
// prefix, we will chop it off as it is not
// needed in literal form any longer.
D := chopDNPfx(condenseWHSP(values[i]))
err = illegalSyntaxPerTypeErr(D, r.Keyword())
if !isInvalidDNSyntax(D) && !contains(D, `?`) {
err = nil
// Push DN into receiver
r.Push(BindDistinguishedName{newDistinguishedName(D, key)})
}
}
if err != nil {
break
}
}
return
}
func isInvalidDNSyntax(dn string) bool {
return (len(dn) < 3 || !(contains(dn, `=`) || !isDNAlias(dn)))
}
/*
setExpressionValues is a private method called by assertTargetTFDN for DN-based Target Rules parsing.
*/
func (r TargetDistinguishedNames) setExpressionValues(key Keyword, values ...string) (err error) {
// iterate each string-based distinguishedName
// in the values sequence ...
for i := 0; i < len(values); i++ {
// Identify this distinguished name value
// as D, as referenced by index integer i.
//
// If the DN has the LocalScheme (ldap:///)
// prefix, we will chop it off as it is not
// needed in literal form any longer.
D := chopDNPfx(condenseWHSP(values[i]))
if isInvalidDNSyntax(D) {
err = illegalSyntaxPerTypeErr(D, r.Keyword())
return
}
// Push DN into receiver
r.Push(TargetDistinguishedName{newDistinguishedName(D, key)})
}
return
}
/*
IsZero wraps the [stackage.Stack.IsZero] method.
*/
func (r BindDistinguishedNames) IsZero() bool {
return r.cast().IsZero()
}
/*
IsZero wraps the [stackage.Stack.IsZero] method.
*/
func (r TargetDistinguishedNames) IsZero() bool {
return r.cast().IsZero()
}
/*
Len wraps the [stackage.Stack.Len] method.
*/
func (r BindDistinguishedNames) Len() int {
return r.cast().Len()
}
/*
Len wraps the [stackage.Stack.Len] method.
*/
func (r TargetDistinguishedNames) Len() int {
return r.cast().Len()
}
/*
Index wraps the [stackage.Stack.Index] method. Note that the Boolean OK value returned by [stackage.Stack.Index] method by default will be shadowed and not obtainable by the caller.
*/
func (r BindDistinguishedNames) Index(idx int) (b DistinguishedNameContext) {
b = badBindDN
var (
assert any
ok bool
)
y, _ := r.cast().Index(idx)