1   /*
2    *  Licensed to the Apache Software Foundation (ASF) under one
3    *  or more contributor license agreements.  See the NOTICE file
4    *  distributed with this work for additional information
5    *  regarding copyright ownership.  The ASF licenses this file
6    *  to you under the Apache License, Version 2.0 (the
7    *  "License"); you may not use this file except in compliance
8    *  with the License.  You may obtain a copy of the License at
9    *  
10   *    http://www.apache.org/licenses/LICENSE-2.0
11   *  
12   *  Unless required by applicable law or agreed to in writing,
13   *  software distributed under the License is distributed on an
14   *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *  KIND, either express or implied.  See the License for the
16   *  specific language governing permissions and limitations
17   *  under the License. 
18   *  
19   */
20  package org.apache.directory.server.core.authz;
21  
22  
23  import org.apache.directory.server.core.DirectoryService;
24  import static org.apache.directory.server.core.authz.AutzIntegUtils.createAccessControlSubentry;
25  import org.apache.directory.server.core.integ.CiRunner;
26  import org.apache.directory.server.core.integ.annotations.Factory;
27  import org.apache.directory.shared.ldap.exception.LdapInvalidAttributeValueException;
28  import org.apache.directory.shared.ldap.message.ResultCodeEnum;
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.fail;
31  import org.junit.Test;
32  import org.junit.runner.RunWith;
33  
34  import javax.naming.NamingException;
35  
36  
37  /**
38   * Tests various authorization functionality without any specific operation.
39   *
40   * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
41   * @version $Rev: 494176 $
42   */
43  @RunWith ( CiRunner.class )
44  @Factory ( AutzIntegUtils.ServiceFactory.class )
45  public class GeneralAuthorizationIT 
46  {
47      public static DirectoryService service;
48  
49  
50      /**
51       * Checks to make sure we cannot create a malformed ACI missing two
52       * last brackets.
53       *
54       * @throws NamingException if the test encounters an error
55       */
56      @Test
57      public void testFailureToAddBadACI() throws Exception
58      {
59          // add a subentry with malformed ACI
60          try
61          {
62              createAccessControlSubentry( "anybodyAdd", "{ " + "identificationTag \"addAci\", " + "precedence 14, "
63                  + "authenticationLevel none, " + "itemOrUserFirst userFirst: { " + "userClasses { allUsers }, "
64                  + "userPermissions { { " + "protectedItems {entry, allUserAttributeTypesAndValues}, "
65                  + "grantsAndDenials { grantAdd, grantBrowse } } }" );
66              fail( "should never get here due to failure to add bad ACIItem" );
67          }
68          catch( LdapInvalidAttributeValueException e )
69          {
70              assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, e.getResultCode() );
71          }
72      }
73  }