1 package org.apache.archiva.redback.authorization.rbac.evaluator;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
23 import org.apache.archiva.redback.rbac.Permission;
24 import org.apache.archiva.redback.rbac.Operation;
25 import org.apache.archiva.redback.rbac.Resource;
26 import org.apache.archiva.redback.rbac.memory.MemoryOperation;
27 import org.apache.archiva.redback.rbac.memory.MemoryPermission;
28 import org.apache.archiva.redback.rbac.memory.MemoryResource;
29 import org.junit.Test;
30 import org.junit.runner.RunWith;
31 import org.springframework.test.context.ContextConfiguration;
32 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
34 import javax.inject.Inject;
36 @RunWith( SpringJUnit4ClassRunner.class )
37 @ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
38 public class PermissionEvaluatorTest
43 PermissionEvaluator permissionEvaluator;
46 public void testNullResource()
47 throws PermissionEvaluationException
49 // null resources should be considered as matching if any resource is obtained.
50 // we do this instead of using "global" as that is the inverse - you are allocated global rights,
51 // which is right to everything. null is the right to anything.
53 Resource resource = new MemoryResource();
54 resource.setIdentifier( "Resource" );
56 Operation operation = new MemoryOperation();
57 operation.setName( "Operation" );
59 Permission permission = new MemoryPermission();
60 permission.setName( "Permission" );
61 permission.setOperation( operation );
62 permission.setResource( resource );
64 assertTrue( permissionEvaluator.evaluate( permission, "Operation", null, "brett" ) );