Tidying up to remove warnings (generics, use of deprecated test classes etc).
This commit is contained in:
@@ -6,8 +6,7 @@ import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.GrantedAuthorityImpl;
|
||||
import org.springframework.security.core.authority.AuthorityUtils;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
@@ -74,8 +73,8 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
template.execute("INSERT INTO AUTHORITIES VALUES('jane','ROLE_USER');");
|
||||
|
||||
// Now create an ACL entry for the root directory
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("rod", "ignored", new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_IGNORED")}));
|
||||
tt.execute(new TransactionCallback() {
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("rod", "ignored", AuthorityUtils.createAuthorityList(("ROLE_IGNORED"))));
|
||||
tt.execute(new TransactionCallback<Object>() {
|
||||
public Object doInTransaction(TransactionStatus arg0) {
|
||||
addPermission(documentDao, Directory.ROOT_DIRECTORY, "ROLE_USER", LEVEL_GRANT_WRITE);
|
||||
return null;
|
||||
@@ -147,4 +146,4 @@ public class DataSourcePopulator implements InitializingBean {
|
||||
* @param level based on the static final integer fields on this class
|
||||
*/
|
||||
protected void addPermission(DocumentDao documentDao, AbstractElement element, String recipient, int level) {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SecureDataSourcePopulator extends DataSourcePopulator {
|
||||
Assert.notNull(SecurityContextHolder.getContext().getAuthentication(), "SecurityContextHolder must contain an Authentication");
|
||||
|
||||
// We need SecureDocumentDao to assign different permissions
|
||||
SecureDocumentDao dao = (SecureDocumentDao) documentDao;
|
||||
//SecureDocumentDao dao = (SecureDocumentDao) documentDao;
|
||||
|
||||
// We need to construct an ACL-specific Sid. Note the prefix contract is defined on the superclass method's JavaDocs
|
||||
Sid sid = null;
|
||||
|
||||
@@ -34,8 +34,8 @@ public class SecureDocumentDaoImpl extends DocumentDaoImpl implements SecureDocu
|
||||
}
|
||||
|
||||
public String[] getUsers() {
|
||||
return (String[]) getJdbcTemplate().query(SELECT_FROM_USERS, new RowMapper() {
|
||||
public Object mapRow(ResultSet rs, int rowNumber) throws SQLException {
|
||||
return (String[]) getJdbcTemplate().query(SELECT_FROM_USERS, new RowMapper<String>() {
|
||||
public String mapRow(ResultSet rs, int rowNumber) throws SQLException {
|
||||
return rs.getString("USERNAME");
|
||||
}
|
||||
}).toArray(new String[] {});
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
|
||||
<property name="url" value="jdbc:hsqldb:mem:insecuredms"/>
|
||||
@@ -16,23 +20,23 @@
|
||||
<property name="password" value=""/>
|
||||
</bean>
|
||||
|
||||
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
|
||||
<property name="transactionAttributeSource">
|
||||
<value>
|
||||
sample.dms.DocumentDao.*=PROPAGATION_REQUIRED
|
||||
</value>
|
||||
</property>
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
</bean>
|
||||
<bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
|
||||
<property name="transactionAttributeSource">
|
||||
<value>
|
||||
sample.dms.DocumentDao.*=PROPAGATION_REQUIRED
|
||||
</value>
|
||||
</property>
|
||||
<property name="transactionManager" ref="transactionManager" />
|
||||
</bean>
|
||||
|
||||
<bean id="documentDao" class="sample.dms.DocumentDaoImpl">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="dataSourcePopulator" class="sample.dms.DataSourcePopulator">
|
||||
<constructor-arg ref="dataSource"/>
|
||||
<constructor-arg ref="documentDao"/>
|
||||
<constructor-arg ref="transactionManager"/>
|
||||
</bean>
|
||||
<bean id="documentDao" class="sample.dms.DocumentDaoImpl">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="dataSourcePopulator" class="sample.dms.DataSourcePopulator">
|
||||
<constructor-arg ref="dataSource"/>
|
||||
<constructor-arg ref="documentDao"/>
|
||||
<constructor-arg ref="transactionManager"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
-->
|
||||
|
||||
<beans>
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
<property name="driverClassName" value="org.hsqldb.jdbcDriver"/>
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
|
||||
|
||||
import sample.dms.AbstractElement;
|
||||
import sample.dms.Directory;
|
||||
@@ -13,14 +20,21 @@ import sample.dms.DocumentDao;
|
||||
* @version $Id$
|
||||
*
|
||||
*/
|
||||
public class DmsIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
|
||||
@ContextConfiguration(locations={"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-insecure.xml"})
|
||||
public class DmsIntegrationTests extends AbstractTransactionalJUnit4SpringContextTests{
|
||||
|
||||
@Autowired
|
||||
protected JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
protected DocumentDao documentDao;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-insecure.xml"};
|
||||
}
|
||||
|
||||
protected void onTearDown() throws Exception {
|
||||
@After
|
||||
public void clearContext() {
|
||||
SecurityContextHolder.clearContext();
|
||||
}
|
||||
|
||||
@@ -28,20 +42,24 @@ public class DmsIntegrationTests extends AbstractTransactionalDataSourceSpringCo
|
||||
this.documentDao = documentDao;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasePopulation() {
|
||||
assertEquals(9, jdbcTemplate.queryForInt("select count(id) from DIRECTORY"));
|
||||
assertEquals(90, jdbcTemplate.queryForInt("select count(id) from FILE"));
|
||||
assertEquals(3, documentDao.findElements(Directory.ROOT_DIRECTORY).length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMarissaRetrieval() {
|
||||
process("rod", "koala", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScottRetrieval() {
|
||||
process("scott", "wombat", false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDianneRetrieval() {
|
||||
process("dianne", "emu", false);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import org.springframework.security.acls.AclService;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
|
||||
|
||||
@@ -9,18 +12,17 @@ import org.springframework.security.acls.AclService;
|
||||
* @version $Id$
|
||||
*
|
||||
*/
|
||||
@ContextConfiguration(locations={"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-secure.xml"})
|
||||
public class SecureDmsIntegrationTests extends DmsIntegrationTests {
|
||||
|
||||
private AclService aclService;
|
||||
|
||||
public void setAclService(AclService aclService) {
|
||||
this.aclService = aclService;
|
||||
}
|
||||
// @Autowired
|
||||
// private AclService aclService;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-secure.xml"};
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasePopulation() {
|
||||
assertEquals(9, jdbcTemplate.queryForInt("select count(id) from DIRECTORY"));
|
||||
assertEquals(90, jdbcTemplate.queryForInt("select count(id) from FILE"));
|
||||
|
||||
Reference in New Issue
Block a user