mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Yannick Lecaillez
03.10.2016 86ad6a08499797f9b3204896caee947abb03394f
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
/*
 * The contents of this file are subject to the terms of the Common Development and
 * Distribution License (the License). You may not use this file except in compliance with the
 * License.
 *
 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
 * specific language governing permission and limitations under the License.
 *
 * When distributing Covered Software, include this CDDL Header Notice in each file and include
 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
 * Header, with the fields enclosed by brackets [] replaced by your own identifying
 * information: "Portions Copyright [year] [name of copyright owner]".
 *
 * Copyright 2008 Sun Microsystems, Inc.
 * Portions Copyright 2011-2016 ForgeRock AS.
 */
package org.opends.server.authorization.dseecompat;
 
import static org.opends.server.authorization.dseecompat.Aci.*;
import static org.opends.server.authorization.dseecompat.AciHandler.*;
import static org.opends.server.util.ServerConstants.OID_GET_EFFECTIVE_RIGHTS;
 
import java.net.InetAddress;
import java.security.cert.Certificate;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
 
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.DN;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.reactive.LDAPClientConnection2;
import org.opends.server.api.ClientConnection;
import org.opends.server.api.Group;
import org.opends.server.controls.GetEffectiveRightsRequestControl;
import org.opends.server.core.AddOperation;
import org.opends.server.core.SearchOperation;
import org.opends.server.types.AuthenticationInfo;
import org.opends.server.types.AuthenticationType;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
import org.opends.server.types.Operation;
 
/**
 *  The AciContainer class contains all of the needed information to perform
 *  both target match and evaluate an ACI. Target matching is the process
 *  of testing if an ACI is applicable to an operation, and evaluation is
 *  the actual access evaluation of the ACI.
 */
abstract class AciContainer implements AciTargetMatchContext, AciEvalContext {
    /** The allow and deny lists. */
    private List<Aci> denyList, allowList;
 
    /** The attribute type in the resource entry currently being evaluated. */
    private AttributeType attributeType;
    /** The attribute type value in the resource entry currently being evaluated. */
    private ByteString attributeValue;
    /** True if this is the first attribute type in the resource entry being evaluated. */
    private boolean isFirst;
 
    /**
     * True if an entry test rule was seen during target matching of an ACI
     * entry. A entry test rule is an ACI with targetattrs target keyword.
     */
    private boolean isEntryTestRule;
 
    /** The right mask to use in the evaluation of the LDAP operation. */
    private int rightsMask;
 
    /** The entry being evaluated (resource entry). */
    private final Entry resourceEntry;
 
    /** The client connection information. */
    private final ClientConnection clientConnection;
    /** The operation being evaluated. */
    private final Operation operation;
 
    /** True if a targattrfilters match was found. */
    private boolean targAttrFiltersMatch;
 
    /**
     * The authorization entry currently being evaluated. If proxied
     * authorization is being used and the handler is doing a proxy access
     * check, then this entry will switched to the original authorization entry
     * rather than the proxy ID entry. If the check succeeds, it will be
     * switched back for non-proxy access checking. If proxied authentication
     * is not being used then this entry never changes.
     */
    private final Entry authorizationEntry;
 
    /** True if proxied authorization is being used. */
    private final boolean proxiedAuthorization;
 
    /**
     * Used by proxied authorization processing. True if the entry has already
     * been processed by an access proxy check. Some operations might perform
     * several access checks on the same entry (modify DN), this
     * flag is used to bypass the proxy check after the initial evaluation.
     */
    private boolean seenEntry;
 
    /** True if geteffectiverights evaluation is in progress. */
    private boolean isGetEffectiveRightsEval;
    /** True if the operation has a geteffectiverights control. */
    private final boolean hasGetEffectiveRightsControl;
    /** The geteffectiverights authzID in DN format. */
    private final DN authzid;
 
    /**
     * True if the authZid should be used as the client DN, only used in
     * geteffectiverights evaluation.
     */
    private boolean useAuthzid;
 
    /**
     * The list of specific attributes to get rights for, in addition to
     * any attributes requested in the search.
     */
    private final List<AttributeType> specificAttrs;
 
    /**
     * Table of ACIs that have targattrfilter keywords that matched. Used
     * in geteffectiverights attributeLevel write evaluation.
     */
    private final HashMap<Aci,Aci> targAttrFilterAcis = new HashMap<>();
 
    /**
     * The name of a ACI that decided an evaluation and contained a
     * targattrfilter keyword. Used in geteffectiverights attributeLevel
     * write evaluation.
     */
    private String targAttrFiltersAciName;
 
    /**
     * Value that is used to store the allow/deny result of a deciding ACI
     * containing a targattrfilter keyword.  Used in geteffectiverights
     * attributeLevel write evaluation.
     */
    private int targAttrMatch;
 
    /** The ACI that decided the last evaluation. Used in geteffectiverights loginfo processing. */
    private Aci decidingAci;
 
    /**
     * The reason the last evaluation decision was made. Used both
     * in geteffectiverights loginfo processing and attributeLevel write
     * evaluation.
     */
    private EnumEvalReason evalReason;
 
    /**
     * A summary string holding the last evaluation information in textual
     * format. Used in geteffectiverights loginfo processing.
     */
    private String summaryString;
 
    /** Flag used to determine if ACI all attributes target matched. */
    private int evalAllAttributes;
 
    /** String used to hold a control OID string. */
    private String controlOID;
    /** String used to hold an extended operation OID string. */
    private String extOpOID;
 
  /** AuthenticationInfo class to use. */
  private final AuthenticationInfo authInfo;
 
  /**
     * This constructor is used by all currently supported LDAP operations
     * except the generic access control check that can be used by
     * plugins.
     *
     * @param operation The Operation object being evaluated and target
     * matching.
     *
     * @param rights The rights array to use in evaluation and target matching.
     *
     * @param entry The current entry being evaluated and target matched.
     */
    protected AciContainer(Operation operation, int rights, Entry entry) {
      this.resourceEntry=entry;
      this.operation=operation;
      this.clientConnection=operation.getClientConnection();
      this.authInfo = clientConnection.getAuthenticationInfo();
 
      //If the proxied authorization control was processed, then the operation
      //will contain an attachment containing the original authorization entry.
      final Entry origAuthorizationEntry = (Entry) operation.getAttachment(ORIG_AUTH_ENTRY);
      this.proxiedAuthorization = origAuthorizationEntry != null;
      this.authorizationEntry=operation.getAuthorizationEntry();
 
      //The ACI_READ right at constructor time can only be the result of the
      //AciHandler.filterEntry method. This method processes the
      //geteffectiverights control, so it needs to check for it.  There are
      //two other checks done, because the resource entry passed to that method
      //is filtered (it may not contain enough attribute information
      //to evaluate correctly). See the the comments below.
      if (rights == ACI_READ) {
        //Checks if a geteffectiverights control was sent and
        //sets up the structures needed.
        GetEffectiveRightsRequestControl getEffectiveRightsControl =
              (GetEffectiveRightsRequestControl)
                      operation.getAttachment(OID_GET_EFFECTIVE_RIGHTS);
        if (getEffectiveRightsControl != null
            && operation instanceof SearchOperation)
        {
          hasGetEffectiveRightsControl = true;
          DN authzDN = getEffectiveRightsControl.getAuthzDN();
          this.authzid = authzDN != null ? authzDN : getClientDN();
          this.specificAttrs = getEffectiveRightsControl.getAttributes();
        } else {
          hasGetEffectiveRightsControl = false;
          authzid = null;
          specificAttrs = null;
        }
 
        //If an ACI evaluated because of an Targetattr="*", then the
        //AciHandler.maySend method signaled this via adding this attachment
        //string.
        String allUserAttrs=
                  (String)operation.getAttachment(ALL_USER_ATTRS_MATCHED);
        if(allUserAttrs != null)
        {
          evalAllAttributes |= ACI_USER_ATTR_STAR_MATCHED;
        }
        //If an ACI evaluated because of an Targetattr="+", then the
        //AciHandler.maySend method signaled this via adding this attachment
        //string.
        String allOpAttrs=(String)operation.getAttachment(ALL_OP_ATTRS_MATCHED);
        if(allOpAttrs != null)
        {
          evalAllAttributes |= ACI_OP_ATTR_PLUS_MATCHED;
        }
      } else {
        hasGetEffectiveRightsControl = false;
        authzid = null;
        specificAttrs = null;
      }
 
      //Reference the current authorization entry, so it can be put back
      //if an access proxy check was performed.
        this.rightsMask = rights;
    }
 
    /**
     * This constructor is used by the generic access control check.
     *
     * @param operation The operation to use in the access evaluation.
     * @param e The entry to check access for.
     * @param authInfo The authentication information to use in the evaluation.
     * @param rights The rights to check access of.
     */
    protected AciContainer(Operation operation, Entry e,
                            AuthenticationInfo authInfo,
                            int rights) {
        this.resourceEntry=e;
        this.operation=operation;
        this.clientConnection=operation.getClientConnection();
        this.authInfo = authInfo;
        this.authorizationEntry = authInfo.getAuthorizationEntry();
        this.rightsMask = rights;
        proxiedAuthorization = false;
        hasGetEffectiveRightsControl = false;
        authzid = null;
        specificAttrs = null;
    }
 
  /**
   * Returns true if an entry has already been processed by an access proxy
   * check.
   *
   * @return True if an entry has already been processed by an access proxy
   * check.
   */
   public boolean hasSeenEntry() {
      return this.seenEntry;
    }
 
  /**
   * Set to true if an entry has already been processed by an access proxy check.
   *
   * @param val The value to set the seenEntry boolean to.
   */
    public void setSeenEntry(boolean val) {
     this.seenEntry=val;
    }
 
    @Override
    public boolean isProxiedAuthorization() {
         return this.proxiedAuthorization;
    }
 
    @Override
    public boolean isGetEffectiveRightsEval() {
        return this.isGetEffectiveRightsEval;
    }
 
  /**
   * The container is going to be used in a geteffectiverights evaluation, set
   * the flag isGetEffectiveRightsEval to true.
   */
  public void setGetEffectiveRightsEval() {
       this.isGetEffectiveRightsEval=true;
    }
 
  /**
   * Return true if the container is being used in a geteffectiverights
   * evaluation.
   *
   * @return True if the container is being used in a geteffectiverights
   * evaluation.
   */
    public boolean hasGetEffectiveRightsControl() {
      return this.hasGetEffectiveRightsControl;
    }
 
  /**
   * Use the DN from the geteffectiverights control's authzId as the
   * client DN, rather than the authorization entry's DN.
   *
   * @param v The valued to set the useAuthzid to.
   */
    public void useAuthzid(boolean v) {
       this.useAuthzid=v;
    }
 
  /**
   * Return the list of additional attributes specified in the
   * geteffectiverights control.
   *
   * @return The list of attributes to return rights information about in the
   * entry.
   */
    public List<AttributeType> getSpecificAttributes() {
       return this.specificAttrs;
    }
 
    @Override
    public void addTargAttrFiltersMatchAci(Aci aci) {
      this.targAttrFilterAcis.put(aci, aci);
    }
 
    @Override
    public boolean hasTargAttrFiltersMatchAci(Aci aci) {
      return this.targAttrFilterAcis.containsKey(aci);
    }
 
    @Override
    public boolean isTargAttrFilterMatchAciEmpty() {
       return this.targAttrFilterAcis.isEmpty();
    }
 
  /**
   * Reset the values used by the geteffectiverights evaluation to
   * original values. The geteffectiverights evaluation uses the same container
   * repeatedly for different rights evaluations (read, write, proxy,...) and
   * this method resets variables that are specific to a single evaluation.
   */
    public void resetEffectiveRightsParams() {
      this.targAttrFilterAcis.clear();
      this.decidingAci=null;
      this.evalReason=null;
      this.targAttrFiltersMatch=false;
      this.summaryString=null;
      this.targAttrMatch=0;
    }
 
    @Override
    public void setTargAttrFiltersAciName(String name) {
      this.targAttrFiltersAciName=name;
    }
 
    @Override
    public String getTargAttrFiltersAciName() {
      return this.targAttrFiltersAciName;
    }
 
    @Override
    public void setTargAttrFiltersMatchOp(int flag) {
      this.targAttrMatch |= flag;
    }
 
    @Override
    public boolean hasTargAttrFiltersMatchOp(int flag) {
       return (this.targAttrMatch & flag) != 0;
    }
 
    @Override
    public String getDecidingAciName() {
      if(this.decidingAci != null) {
        return this.decidingAci.getName();
      }
      return null;
    }
 
  @Override
  public void setEvaluationResult(EnumEvalReason reason, Aci decidingAci)
  {
    this.evalReason = reason;
    this.decidingAci = decidingAci;
  }
 
    @Override
    public EnumEvalReason getEvalReason() {
      return this.evalReason;
    }
 
    @Override
    public void setEvalSummary(String summary) {
      this.summaryString=summary;
    }
 
    @Override
    public String getEvalSummary() {
      return this.summaryString;
    }
 
  /**
   * Returns true if the geteffectiverights control's authZid DN is equal to the
   * authorization entry's DN.
   *
   * @return True if the authZid is equal to the authorization entry's DN.
   */
    public boolean isAuthzidAuthorizationDN() {
     return this.authzid.equals(this.authorizationEntry.getName());
    }
 
    @Override
    public void setDenyList(List<Aci> denys) {
        denyList=denys;
    }
 
    @Override
    public void setAllowList(List<Aci> allows) {
        allowList=allows;
    }
 
    @Override
    public AttributeType getCurrentAttributeType() {
        return attributeType;
    }
 
    @Override
    public ByteString getCurrentAttributeValue() {
        return attributeValue;
    }
 
    @Override
    public void setCurrentAttributeType(AttributeType type) {
        attributeType=type;
    }
 
    @Override
    public void setCurrentAttributeValue(ByteString value) {
        attributeValue=value;
    }
 
    @Override
    public boolean isFirstAttribute() {
        return isFirst;
    }
 
    @Override
    public void setIsFirstAttribute(boolean val) {
        isFirst=val;
    }
 
    @Override
    public boolean hasEntryTestRule() {
        return isEntryTestRule;
    }
 
    @Override
    public void setEntryTestRule(boolean val) {
        isEntryTestRule=val;
    }
 
    @Override
    public Entry getResourceEntry() {
        return resourceEntry;
    }
 
    @Override
    public Entry getClientEntry() {
      return this.authorizationEntry;
    }
 
    @Override
    public List<Aci> getDenyList() {
        return denyList;
    }
 
    @Override
    public List<Aci> getAllowList() {
       return allowList;
    }
 
    @Override
    public boolean isDenyEval() {
        return EnumEvalReason.NO_ALLOW_ACIS.equals(evalReason)
            || EnumEvalReason.EVALUATED_DENY_ACI.equals(evalReason);
    }
 
    @Override
    public boolean isAnonymousUser() {
        return !authInfo.isAuthenticated();
    }
 
    @Override
    public DN getClientDN() {
      if(this.useAuthzid)
      {
        return this.authzid;
      }
      else if (this.authorizationEntry != null)
      {
        return this.authorizationEntry.getName();
      }
      return DN.rootDN();
    }
 
    @Override
    public DN getResourceDN() {
        return resourceEntry.getName();
    }
 
   /**
    * {@inheritDoc}
    * <p>
    * JNR: I find the implementation in this method dubious.
    *
    * @see EnumRight#hasRights(int, int)
    */
    @Override
    public boolean hasRights(int rights) {
       return (this.rightsMask & rights) != 0;
    }
 
    @Override
    public int getRights() {
        return this.rightsMask;
    }
 
    @Override
    public void setRights(int rights) {
         this.rightsMask=rights;
    }
 
    @Override
    public String getHostName() {
        return clientConnection.getRemoteAddress().getCanonicalHostName();
    }
 
    @Override
    public InetAddress getRemoteAddress() {
        return clientConnection.getRemoteAddress();
    }
 
    @Override
    public boolean isAddOperation() {
        return operation instanceof AddOperation;
    }
 
    @Override
    public void setTargAttrFiltersMatch(boolean v) {
        this.targAttrFiltersMatch=v;
    }
 
    @Override
    public boolean getTargAttrFiltersMatch() {
        return targAttrFiltersMatch;
    }
 
    @Override
    public String getControlOID() {
      return controlOID;
    }
 
    @Override
    public String getExtOpOID() {
      return extOpOID;
    }
 
    /**
     * Set the the controlOID value to the specified oid string.
     *
     * @param oid  The control oid string.
     */
    protected void setControlOID(String oid) {
      this.controlOID=oid;
    }
 
    /**
     * Set the extended operation OID value to the specified oid string.
     *
     * @param oid  The extended operation oid string.
     */
    protected void setExtOpOID(String oid) {
      this.extOpOID=oid;
    }
 
    @Override
    public EnumEvalResult hasAuthenticationMethod(EnumAuthMethod authMethod,
                                                  String saslMech) {
      EnumEvalResult matched=EnumEvalResult.FALSE;
 
      if(authMethod==EnumAuthMethod.AUTHMETHOD_NONE) {
        /*
         * None actually means any, in that we don't care what method was used.
         * This doesn't seem very intuitive or useful, but that's the way it is.
         */
        matched = EnumEvalResult.TRUE;
      } else {
        // Some kind of authentication is required.
        if(authInfo.isAuthenticated()) {
          if(authMethod==EnumAuthMethod.AUTHMETHOD_SIMPLE) {
            if(authInfo.hasAuthenticationType(AuthenticationType.SIMPLE)) {
              matched = EnumEvalResult.TRUE;
            }
          } else if(authMethod == EnumAuthMethod.AUTHMETHOD_SSL) {
            /*
             * This means authentication using a certificate over TLS.
             *
             * We check the following:
             * - SASL EXTERNAL has been used, and
             * - TLS is the security provider, and
             * - The client provided a certificate.
             */
            if (authInfo.hasAuthenticationType(AuthenticationType.SASL)
                && authInfo.hasSASLMechanism(saslMech)
                && clientConnection instanceof LDAPClientConnection2) {
                LDAPClientConnection2 lc = (LDAPClientConnection2) clientConnection;
                Certificate[] certChain = lc.getClientCertificateChain();
                if (certChain.length != 0) {
                  matched = EnumEvalResult.TRUE;
                }
            }
          } else {
            // A particular SASL mechanism.
            if (authInfo.hasAuthenticationType(AuthenticationType.SASL) &&
                 authInfo.hasSASLMechanism(saslMech)) {
              matched = EnumEvalResult.TRUE;
            }
          }
        }
      }
      return matched;
    }
 
    @Override
    public boolean isMemberOf(Group<?> group) {
        try {
            if(useAuthzid) {
                return group.isMember(this.authzid);
            }
            Entry e = getClientEntry();
            if (e != null) {
                return group.isMember(e);
            }
            return group.isMember(getClientDN());
        } catch (DirectoryException ex) {
            return false;
        }
    }
 
  /**
   * {@inheritDoc}
   * <p>
   * JNR: I find the implementation in this method dubious.
   *
   * @see EnumRight#getEnumRight(int)
   */
    @Override
    public String rightToString() {
      if(hasRights(ACI_SEARCH))
      {
        return "search";
      }
      else if(hasRights(ACI_COMPARE))
      {
        return "compare";
      }
      else if(hasRights(ACI_READ))
      {
        return "read";
      }
      else if(hasRights(ACI_DELETE))
      {
        return "delete";
      }
      else if(hasRights(ACI_ADD))
      {
        return "add";
      }
      else if(hasRights(ACI_WRITE))
      {
        return "write";
      }
      else if(hasRights(ACI_PROXY))
      {
        return "proxy";
      }
      else if(hasRights(ACI_IMPORT))
      {
        return "import";
      }
      else if(hasRights(ACI_EXPORT))
      {
        return "export";
      }
      else if(hasRights(ACI_WRITE) &&
              hasRights(ACI_SELF))
      {
        return "selfwrite";
      }
      return null;
  }
 
  @Override
  public  void setEvalUserAttributes(int v) {
    if(rightsMask == ACI_READ) {
      if(v == ACI_FOUND_USER_ATTR_RULE) {
        evalAllAttributes |= ACI_FOUND_USER_ATTR_RULE;
        evalAllAttributes &= ~ACI_USER_ATTR_STAR_MATCHED;
      }
      else
      {
        evalAllAttributes |= ACI_USER_ATTR_STAR_MATCHED;
      }
    }
  }
 
  @Override
  public  void setEvalOpAttributes(int v) {
    if(rightsMask == ACI_READ) {
      if(v == ACI_FOUND_OP_ATTR_RULE) {
        evalAllAttributes |= ACI_FOUND_OP_ATTR_RULE;
        evalAllAttributes &= ~ACI_OP_ATTR_PLUS_MATCHED;
      }
      else
      {
        evalAllAttributes |= ACI_OP_ATTR_PLUS_MATCHED;
      }
    }
  }
 
  @Override
  public boolean hasEvalUserAttributes() {
    return hasAttribute(ACI_FOUND_USER_ATTR_RULE);
  }
 
  @Override
  public boolean hasEvalOpAttributes() {
    return hasAttribute(ACI_FOUND_OP_ATTR_RULE);
  }
 
  /**
   * Return true if the evaluating ACI contained a targetattr all
   * user attributes rule match.
   *
   * @return  True if the above condition was seen.
   */
  public boolean hasAllUserAttributes() {
    return hasAttribute(ACI_USER_ATTR_STAR_MATCHED);
  }
 
  /**
   * Return true if the evaluating ACI contained a targetattr all
   * operational attributes rule match.
   *
   * @return  True if the above condition was seen.
   */
  public boolean hasAllOpAttributes() {
    return hasAttribute(ACI_OP_ATTR_PLUS_MATCHED);
  }
 
  private boolean hasAttribute(int aciAttribute)
  {
    return (evalAllAttributes & aciAttribute) == aciAttribute;
  }
 
  @Override
  public void clearEvalAttributes(int v) {
    if(v == 0)
    {
      evalAllAttributes=0;
    }
    else
    {
      evalAllAttributes &= ~v;
    }
  }
 
  @Override
  public int getCurrentSSF() {
      return clientConnection.getSSF();
  }
 
  @Override
  public String toString()
  {
    final StringBuilder sb = new StringBuilder();
    if (attributeType != null)
    {
      appendSeparatorIfNeeded(sb);
      sb.append("attributeType: ").append(attributeType.getNameOrOID());
      if (attributeValue != null)
      {
        sb.append(":").append(attributeValue);
      }
    }
    appendSeparatorIfNeeded(sb);
    sb.append(size(allowList)).append(" allow ACIs");
    appendSeparatorIfNeeded(sb);
    sb.append(size(denyList)).append(" deny ACIs");
    if (evalReason != null)
    {
      appendSeparatorIfNeeded(sb);
      sb.append("evaluationResult: ").append(evalReason);
      if (decidingAci != null)
      {
        sb.append(",").append(decidingAci);
      }
    }
    return sb.toString();
  }
 
  private void appendSeparatorIfNeeded(StringBuilder sb)
  {
    if (sb.length() > 0)
    {
      sb.append(", ");
    }
  }
 
  private int size(Collection<?> col)
  {
    if (col != null)
    {
      return col.size();
    }
    return 0;
  }
}