SEC-1382: Removed deprecated label-based voter and related classes.

This commit is contained in:
Luke Taylor
2010-01-25 00:38:20 +00:00
parent 68f6afd905
commit dacb8dd25a
9 changed files with 0 additions and 852 deletions

View File

@@ -1,184 +0,0 @@
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed 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.springframework.security.access.vote;
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Greg Turnquist
*/
@ContextConfiguration(locations={"/org/springframework/security/vote/labelBasedSecurityApplicationContext.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class LabelBasedAclVoterTests {
//~ Instance fields ================================================================================================
@Autowired
private SampleService sampleService = null;
@Autowired
private AuthenticationManager authenticationManager;
//~ Methods ========================================================================================================
public SampleService getSampleService() {
return sampleService;
}
public void setSampleService(SampleService sampleService) {
this.sampleService = sampleService;
}
private void setupContext(String username, String password) {
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(username, password);
SecurityContextHolder.getContext().setAuthentication(authenticationManager.authenticate(token));
}
@Test
public void testDoingSomethingForBlueUser() {
setupContext("blueuser", "password");
List<SampleBlockOfData> dataList = sampleService.getTheSampleData();
assertNotNull(dataList);
SampleBlockOfData block1 = (SampleBlockOfData) dataList.get(0);
SampleBlockOfData block2 = (SampleBlockOfData) dataList.get(1);
SampleBlockOfData block3 = (SampleBlockOfData) dataList.get(2);
sampleService.doSomethingOnThis(block1, block1);
try {
sampleService.doSomethingOnThis(block2, block2);
fail("Expected an AccessDeniedException");
} catch (AccessDeniedException e) {}
catch (RuntimeException e) {
fail("Expected an AccessDeniedException");
}
try {
sampleService.doSomethingOnThis(block1, block2);
fail("Expected an AccessDeniedException");
} catch (AccessDeniedException e) {}
catch (RuntimeException e) {
fail("Expected an AccessDeniedException");
}
try {
sampleService.doSomethingOnThis(block2, block1);
fail("Expected an AccessDeniedException");
} catch (AccessDeniedException e) {}
catch (RuntimeException e) {
fail("Expected an AccessDeniedException");
}
sampleService.doSomethingOnThis(block3, block3);
}
@Test
public void testDoingSomethingForMultiUser() {
setupContext("multiuser", "password4");
List<SampleBlockOfData> dataList = sampleService.getTheSampleData();
assertNotNull(dataList);
SampleBlockOfData block1 = (SampleBlockOfData) dataList.get(0);
SampleBlockOfData block2 = (SampleBlockOfData) dataList.get(1);
SampleBlockOfData block3 = (SampleBlockOfData) dataList.get(2);
sampleService.doSomethingOnThis(block1, block1);
sampleService.doSomethingOnThis(block2, block2);
sampleService.doSomethingOnThis(block1, block2);
sampleService.doSomethingOnThis(block2, block1);
sampleService.doSomethingOnThis(block3, block3);
}
@Test
public void testDoingSomethingForOrangeUser() {
setupContext("orangeuser", "password3");
List<SampleBlockOfData> dataList = sampleService.getTheSampleData();
assertNotNull(dataList);
SampleBlockOfData block1 = (SampleBlockOfData) dataList.get(0);
SampleBlockOfData block2 = (SampleBlockOfData) dataList.get(1);
SampleBlockOfData block3 = (SampleBlockOfData) dataList.get(2);
sampleService.doSomethingOnThis(block2, block2);
try {
sampleService.doSomethingOnThis(block1, block1);
fail("Expected an AccessDeniedException");
} catch (AccessDeniedException e) {}
catch (RuntimeException e) {
fail("Expected an AccessDeniedException");
}
try {
sampleService.doSomethingOnThis(block1, block2);
fail("Expected an AccessDeniedException");
} catch (AccessDeniedException e) {}
catch (RuntimeException e) {
fail("Expected an AccessDeniedException");
}
try {
sampleService.doSomethingOnThis(block2, block1);
fail("Expected an AccessDeniedException");
} catch (AccessDeniedException e) {}
catch (RuntimeException e) {
fail("Expected an AccessDeniedException");
}
sampleService.doSomethingOnThis(block3, block3);
}
@Test
public void testDoingSomethingForSuperUser() {
setupContext("superuser", "password2");
List<SampleBlockOfData> dataList = sampleService.getTheSampleData();
assertNotNull(dataList);
SampleBlockOfData block1 = (SampleBlockOfData) dataList.get(0);
SampleBlockOfData block2 = (SampleBlockOfData) dataList.get(1);
SampleBlockOfData block3 = (SampleBlockOfData) dataList.get(2);
sampleService.doSomethingOnThis(block1, block1);
sampleService.doSomethingOnThis(block2, block2);
sampleService.doSomethingOnThis(block1, block2);
sampleService.doSomethingOnThis(block2, block1);
sampleService.doSomethingOnThis(block3, block3);
}
@Test
public void testSampleBlockOfDataPOJO() {
SampleBlockOfData block = new SampleBlockOfData();
block.setId("ID-ABC");
assertEquals(block.getId(), "ID-ABC");
}
}

View File

@@ -1,66 +0,0 @@
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed 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.springframework.security.access.vote;
import org.springframework.security.access.vote.LabeledData;
import java.io.Serializable;
/**
* For label unit tests.
*
* @author Greg Turnquist
*/
public class SampleBlockOfData implements Serializable, LabeledData {
//~ Static fields/initializers =====================================================================================
private static final long serialVersionUID = 1L;
public static final String DATA_LABEL_BLUE = "blue";
public static final String DATA_LABEL_ORANGE = "orange";
public static final String DATA_LABEL_SHARED = "blue-orange";
//~ Instance fields ================================================================================================
private String dataType;
private String id;
//~ Methods ========================================================================================================
public String getId() {
return id;
}
public String getLabel() {
return dataType;
}
public String getSomeData() {
return dataType;
}
public void setId(String ticketNumber) {
this.id = ticketNumber;
}
public void setSomeData(String trafficType) {
this.dataType = trafficType;
}
public String toString() {
return this.id + "/" + this.dataType;
}
}

View File

@@ -1,30 +0,0 @@
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed 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.springframework.security.access.vote;
import java.util.List;
/**
* @author Greg Turnquist
*/
public interface SampleService {
//~ Methods ========================================================================================================
public void doSomethingOnThis(SampleBlockOfData block1, SampleBlockOfData block2);
public List<SampleBlockOfData> getTheSampleData();
}

View File

@@ -1,53 +0,0 @@
/* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
*
* Licensed 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.springframework.security.access.vote;
import java.util.List;
import java.util.Vector;
/**
* For label unit tests.
*
* @author Greg Turnquist
*/
public class SampleServiceImpl implements SampleService {
//~ Methods ========================================================================================================
public void doSomethingOnThis(SampleBlockOfData block1, SampleBlockOfData block2) {
}
public List<SampleBlockOfData> getTheSampleData() {
List<SampleBlockOfData> dataList = new Vector<SampleBlockOfData>();
SampleBlockOfData block;
block = new SampleBlockOfData();
block.setId("001");
block.setSomeData(SampleBlockOfData.DATA_LABEL_BLUE);
dataList.add(block);
block = new SampleBlockOfData();
block.setId("002");
block.setSomeData(SampleBlockOfData.DATA_LABEL_ORANGE);
dataList.add(block);
block = new SampleBlockOfData();
block.setId("003");
block.setSomeData(SampleBlockOfData.DATA_LABEL_SHARED);
dataList.add(block);
return dataList;
}
}

View File

@@ -1,91 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" >
<beans>
<bean id="userDetailsService" class="org.springframework.security.core.userdetails.memory.InMemoryDaoImpl">
<property name="userMap">
<value>
blueuser=password,ROLE_BASIC,LABEL_BLUE
superuser=password2,ROLE_BASIC,LABEL_SHARED
orangeuser=password3,ROLE_BASIC,LABEL_ORANGE
multiuser=password4,ROLE_BASIC,LABEL_BLUE,LABEL_ORANGE
</value>
</property>
</bean>
<bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
<property name="userDetailsService"><ref bean="userDetailsService"/></property>
</bean>
<bean id="authenticationManager" class="org.springframework.security.authentication.ProviderManager">
<property name="providers">
<list>
<ref local="daoAuthenticationProvider"/>
</list>
</property>
</bean>
<bean id="accessDecisionManager" class="org.springframework.security.access.vote.UnanimousBased">
<property name="allowIfAllAbstainDecisions"><value>false</value></property>
<property name="decisionVoters">
<list>
<bean class="org.springframework.security.access.vote.RoleVoter"/>
<bean class="org.springframework.security.access.vote.LabelBasedAclVoter">
<property name="attributeIndicatingLabeledOperation"><value>LABELED_OPERATION</value></property>
<property name="labelMap">
<map>
<entry key="LABEL_BLUE">
<list>
<value>blue</value>
<value>blue-orange</value>
</list>
</entry>
<entry key="LABEL_ORANGE">
<list>
<value>orange</value>
<value>blue-orange</value>
</list>
</entry>
<entry key="LABEL_SHARED">
<list>
<value>blue</value>
<value>orange</value>
<value>blue-orange</value>
</list>
</entry>
</map>
</property>
</bean>
</list>
</property>
</bean>
<bean id="securityInteceptor"
class="org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor">
<property name="validateConfigAttributes"><value>false</value></property>
<property name="authenticationManager"><ref bean="authenticationManager"/></property>
<property name="accessDecisionManager"><ref bean="accessDecisionManager"/></property>
<property name="securityMetadataSource">
<value>
org.springframework.security.access.vote.SampleService.get*=ROLE_BASIC
org.springframework.security.access.vote.SampleService.do*=ROLE_BASIC,LABELED_OPERATION
</value>
</property>
</bean>
<bean id="perfOfSecurity" class="org.springframework.aop.interceptor.PerformanceMonitorInterceptor">
<property name="prefix"><value>Security: </value></property>
</bean>
<bean id="sampleService" class="org.springframework.security.access.vote.SampleServiceImpl"/>
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames"><value>sampleService</value></property>
<property name="interceptorNames">
<list>
<value>perfOfSecurity</value>
<value>securityInteceptor</value>
</list>
</property>
</bean>
</beans>