Skip to content

Commit 8dbf86f

Browse files
author
Costin Leau
committed
+ update copyright dates on some files
+ migrated test from JUnit 3 to 4
1 parent 2d7c2d6 commit 8dbf86f

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

org.springframework.beans/src/main/java/org/springframework/beans/factory/support/SecurityContextProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2009 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.beans.factory.support;
1718

1819
import java.security.AccessControlContext;

org.springframework.beans/src/main/java/org/springframework/beans/factory/support/SimpleSecurityContextProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2009 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.beans.factory.support;
1718

1819
import java.security.AccessControlContext;

org.springframework.beans/src/test/java/org/springframework/beans/factory/support/security/CallbacksSecurityTests.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2009 the original author or authors.
2+
* Copyright 2002-2009 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -13,8 +13,15 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.beans.factory.support.security;
1718

19+
import static junit.framework.Assert.assertEquals;
20+
import static junit.framework.Assert.assertNotNull;
21+
import static junit.framework.Assert.assertNull;
22+
import static junit.framework.Assert.assertTrue;
23+
import static junit.framework.Assert.fail;
24+
1825
import java.lang.reflect.Method;
1926
import java.net.URL;
2027
import java.security.AccessControlContext;
@@ -31,8 +38,8 @@
3138
import javax.security.auth.AuthPermission;
3239
import javax.security.auth.Subject;
3340

34-
import junit.framework.TestCase;
35-
41+
import org.junit.Before;
42+
import org.junit.Test;
3643
import org.springframework.beans.BeansException;
3744
import org.springframework.beans.factory.BeanClassLoaderAware;
3845
import org.springframework.beans.factory.BeanCreationException;
@@ -62,7 +69,7 @@
6269
*
6370
* @author Costin Leau
6471
*/
65-
public class CallbacksSecurityTests extends TestCase {
72+
public class CallbacksSecurityTests {
6673

6774
private XmlBeanFactory beanFactory;
6875
private SecurityContextProvider provider;
@@ -264,8 +271,8 @@ public CallbacksSecurityTests() {
264271
}
265272
}
266273

267-
@Override
268-
protected void setUp() throws Exception {
274+
@Before
275+
public void setUp() throws Exception {
269276

270277
final ProtectionDomain empty = new ProtectionDomain(null,
271278
new Permissions());
@@ -286,6 +293,7 @@ public AccessControlContext getAccessControlContext() {
286293
beanFactory.setSecurityContextProvider(provider);
287294
}
288295

296+
@Test
289297
public void testSecuritySanity() throws Exception {
290298
AccessControlContext acc = provider.getAccessControlContext();
291299
try {
@@ -300,7 +308,7 @@ public void testSecuritySanity() throws Exception {
300308
method.setAccessible(true);
301309

302310
try {
303-
AccessController.doPrivileged(new PrivilegedExceptionAction() {
311+
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
304312

305313
public Object run() throws Exception {
306314
method.invoke(bean, null);
@@ -325,6 +333,7 @@ public Object run() throws Exception {
325333
}
326334
}
327335

336+
@Test
328337
public void testSpringInitBean() throws Exception {
329338
try {
330339
beanFactory.getBean("spring-init");
@@ -333,7 +342,8 @@ public void testSpringInitBean() throws Exception {
333342
assertTrue(ex.getCause() instanceof SecurityException);
334343
}
335344
}
336-
345+
346+
@Test
337347
public void testCustomInitBean() throws Exception {
338348
try {
339349
beanFactory.getBean("custom-init");
@@ -343,18 +353,21 @@ public void testCustomInitBean() throws Exception {
343353
}
344354
}
345355

356+
@Test
346357
public void testSpringDestroyBean() throws Exception {
347358
beanFactory.getBean("spring-destroy");
348359
beanFactory.destroySingletons();
349360
assertNull(System.getProperty("security.destroy"));
350361
}
351362

363+
@Test
352364
public void testCustomDestroyBean() throws Exception {
353365
beanFactory.getBean("custom-destroy");
354366
beanFactory.destroySingletons();
355367
assertNull(System.getProperty("security.destroy"));
356368
}
357369

370+
@Test
358371
public void testCustomFactoryObject() throws Exception {
359372
try {
360373
beanFactory.getBean("spring-factory");
@@ -365,11 +378,13 @@ public void testCustomFactoryObject() throws Exception {
365378

366379
}
367380

381+
@Test
368382
public void testCustomFactoryType() throws Exception {
369383
assertNull(beanFactory.getType("spring-factory"));
370384
assertNull(System.getProperty("factory.object.type"));
371385
}
372386

387+
@Test
373388
public void testCustomStaticFactoryMethod() throws Exception {
374389
try {
375390
beanFactory.getBean("custom-static-factory-method");
@@ -379,6 +394,7 @@ public void testCustomStaticFactoryMethod() throws Exception {
379394
}
380395
}
381396

397+
@Test
382398
public void testCustomInstanceFactoryMethod() throws Exception {
383399
try {
384400
beanFactory.getBean("custom-factory-method");
@@ -388,6 +404,7 @@ public void testCustomInstanceFactoryMethod() throws Exception {
388404
}
389405
}
390406

407+
@Test
391408
public void testTrustedFactoryMethod() throws Exception {
392409
try {
393410
beanFactory.getBean("privileged-static-factory-method");
@@ -397,6 +414,7 @@ public void testTrustedFactoryMethod() throws Exception {
397414
}
398415
}
399416

417+
@Test
400418
public void testConstructor() throws Exception {
401419
try {
402420
beanFactory.getBean("constructor");
@@ -407,10 +425,11 @@ public void testConstructor() throws Exception {
407425
}
408426
}
409427

428+
@Test
410429
public void testContainerPriviledges() throws Exception {
411430
AccessControlContext acc = provider.getAccessControlContext();
412431

413-
AccessController.doPrivileged(new PrivilegedExceptionAction() {
432+
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
414433

415434
public Object run() throws Exception {
416435
beanFactory.getBean("working-factory-method");
@@ -420,6 +439,7 @@ public Object run() throws Exception {
420439
}, acc);
421440
}
422441

442+
@Test
423443
public void testPropertyInjection() throws Exception {
424444
try {
425445
beanFactory.getBean("property-injection");
@@ -431,6 +451,7 @@ public void testPropertyInjection() throws Exception {
431451
beanFactory.getBean("working-property-injection");
432452
}
433453

454+
@Test
434455
public void testInitSecurityAwarePrototypeBean() {
435456
final DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
436457
BeanDefinitionBuilder bdb = BeanDefinitionBuilder
@@ -442,15 +463,16 @@ public void testInitSecurityAwarePrototypeBean() {
442463
final Subject subject = new Subject();
443464
subject.getPrincipals().add(new TestPrincipal("user1"));
444465

445-
NonPrivilegedBean bean = (NonPrivilegedBean) Subject.doAsPrivileged(
446-
subject, new PrivilegedAction() {
447-
public Object run() {
448-
return lbf.getBean("test");
466+
NonPrivilegedBean bean = Subject.doAsPrivileged(
467+
subject, new PrivilegedAction<NonPrivilegedBean>() {
468+
public NonPrivilegedBean run() {
469+
return lbf.getBean("test", NonPrivilegedBean.class);
449470
}
450471
}, null);
451472
assertNotNull(bean);
452473
}
453474

475+
@Test
454476
public void testTrustedExecution() throws Exception {
455477
beanFactory.setSecurityContextProvider(null);
456478

0 commit comments

Comments
 (0)