Added: servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationEntryTest.java URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationEntryTest.java?rev=662362&view=auto ============================================================================== --- servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationEntryTest.java (added) +++ servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationEntryTest.java Mon Jun 2 01:45:14 2008 @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicemix.nmr.core.security; + +import java.util.Set; + +import org.apache.servicemix.nmr.api.security.GroupPrincipal; +import junit.framework.TestCase; + +public class DefaultAuthorizationEntryTest extends TestCase { + + public void testSetRoles() { + DefaultAuthorizationEntry entry = new DefaultAuthorizationEntry(); + entry.setRoles("role1, role2"); + Set<GroupPrincipal> acls = entry.getAcls(); + assertNotNull(acls); + assertEquals(2, acls.size()); + assertTrue(acls.contains(new GroupPrincipal("role1"))); + assertTrue(acls.contains(new GroupPrincipal("role2"))); + } + + public void testAnyRole() { + DefaultAuthorizationEntry entry = new DefaultAuthorizationEntry(); + entry.setRoles("*"); + Set<GroupPrincipal> acls = entry.getAcls(); + assertNotNull(acls); + assertEquals(1, acls.size()); + assertTrue(acls.contains(GroupPrincipal.ANY)); + } +}
Added: servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationServiceTest.java URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationServiceTest.java?rev=662362&view=auto ============================================================================== --- servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationServiceTest.java (added) +++ servicemix/smx4/nmr/trunk/nmr/core/src/test/java/org/apache/servicemix/nmr/core/security/DefaultAuthorizationServiceTest.java Mon Jun 2 01:45:14 2008 @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.servicemix.nmr.core.security; + +import java.util.Set; + +import javax.xml.namespace.QName; + +import junit.framework.TestCase; +import org.apache.servicemix.nmr.api.security.AuthorizationEntry; +import org.apache.servicemix.nmr.api.security.GroupPrincipal; + +public class DefaultAuthorizationServiceTest extends TestCase { + + protected DefaultAuthorizationService service; + + protected void setUp() { + service = new DefaultAuthorizationService(); + } + + public void testSet() { + addEntry("*", null, "*", AuthorizationEntry.Type.Add); + addEntry("ep1", null, "role1", AuthorizationEntry.Type.Set); + + Set<GroupPrincipal> acls = service.getAcls("ep1", null); + assertNotNull(acls); + assertEquals(1, acls.size()); + assertTrue(acls.contains(new GroupPrincipal("role1"))); + acls = service.getAcls("ep2", null); + assertNotNull(acls); + assertEquals(1, acls.size()); + assertTrue(acls.contains(GroupPrincipal.ANY)); + } + + public void testRemoveAdd() { + addEntry("*", null, "*", AuthorizationEntry.Type.Add); + addEntry("ep.*", null, "*", AuthorizationEntry.Type.Remove); + addEntry("ep1", null, "role1", AuthorizationEntry.Type.Add); + + Set<GroupPrincipal> acls = service.getAcls("ep1", null); + assertNotNull(acls); + assertEquals(1, acls.size()); + assertTrue(acls.contains(new GroupPrincipal("role1"))); + acls = service.getAcls("ep2", null); + assertNotNull(acls); + assertEquals(0, acls.size()); + acls = service.getAcls("p3", null); + assertNotNull(acls); + assertEquals(1, acls.size()); + assertTrue(acls.contains(GroupPrincipal.ANY)); + } + + public void testRank() { + addEntry("*", null, "*", AuthorizationEntry.Type.Add, 0); + addEntry("*", null, "*", AuthorizationEntry.Type.Remove, -1); + addEntry("ep1", null, "role1", AuthorizationEntry.Type.Add); + + Set<GroupPrincipal> acls = service.getAcls("ep1", null); + assertNotNull(acls); + assertEquals(2, acls.size()); + assertTrue(acls.contains(new GroupPrincipal("role1"))); + assertTrue(acls.contains(GroupPrincipal.ANY)); + } + + protected void addEntry(String endpoint, QName operation, String roles) { + addEntry(endpoint, operation, roles, AuthorizationEntry.Type.Add); + } + + protected void addEntry(String endpoint, QName operation, String roles, AuthorizationEntry.Type type) { + addEntry(endpoint, operation, roles, type, 0); + } + + protected void addEntry(String endpoint, QName operation, String roles, AuthorizationEntry.Type type, int rank) { + DefaultAuthorizationEntry entry = new DefaultAuthorizationEntry(endpoint, operation, roles, type, rank); + service.register(entry, null); + } + +} Modified: servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml?rev=662362&r1=662361&r2=662362&view=diff ============================================================================== --- servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml (original) +++ servicemix/smx4/nmr/trunk/nmr/osgi/src/main/resources/META-INF/spring/servicemix-nmr.xml Mon Jun 2 01:45:14 2008 @@ -42,7 +42,9 @@ </osgi:service> <!-- Flow registry and service tracker --> - <bean id="flowRegistry" class="org.apache.servicemix.nmr.core.FlowRegistryImpl" /> + <bean id="flowRegistry" class="org.apache.servicemix.nmr.core.FlowRegistryImpl"> + <property name="authorizationService" ref="authorizationService" /> + </bean> <osgi:list id="flows" interface="org.apache.servicemix.nmr.api.internal.Flow" cardinality="0..N"> @@ -77,4 +79,29 @@ </osgi:interfaces> </osgi:service> + <!-- AuthorizationService --> + <bean id="authorizationService" class="org.apache.servicemix.nmr.core.security.DefaultAuthorizationService" /> + <osgi:service ref="authorizationService" interface="org.apache.servicemix.nmr.api.security.AuthorizationService" /> + + <!-- AuthorizationEntries --> + <osgi:list id="authorizationEntries" + interface="org.apache.servicemix.nmr.api.security.AuthorizationEntry" + cardinality="0..N"> + <osgi:listener ref="authorizationService" bind-method="register" unbind-method="unregister" /> + </osgi:list> + + <!-- Default authorization entry --> + <osgi:service interface="org.apache.servicemix.nmr.api.security.AuthorizationEntry"> + <bean class="org.apache.servicemix.nmr.core.security.DefaultAuthorizationEntry"> + <property name="endpoint" value="*" /> + <property name="rank" value="-2147483648" /> + <property name="roles" value="*" /> + <property name="type" value="Set" /> + </bean> + </osgi:service> + + <!-- AuthenticationService --> + <bean id="authenticationService" class="org.apache.servicemix.nmr.core.security.JaasAuthenticationService" /> + <osgi:service ref="authenticationService" interface="org.apache.servicemix.nmr.api.security.AuthorizationService" /> + </beans> Modified: servicemix/smx4/nmr/trunk/pom.xml URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/pom.xml?rev=662362&r1=662361&r2=662362&view=diff ============================================================================== --- servicemix/smx4/nmr/trunk/pom.xml (original) +++ servicemix/smx4/nmr/trunk/pom.xml Mon Jun 2 01:45:14 2008 @@ -35,6 +35,7 @@ <modules> <module>bundles</module> <module>nmr</module> + <module>document</module> <module>jbi</module> <module>bundle</module> <module>assembly</module>
