mirror of
https://github.com/spring-projects/spring-security.git
synced 2025-06-24 13:02:13 +00:00
Fix NullPointerException caused by unit tests.
This commit is contained in:
parent
4d15375421
commit
4e1649c2b7
@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2004 Acegi Technology Pty Limited
|
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -28,6 +28,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
|
||||||
import org.springframework.dao.DataRetrievalFailureException;
|
import org.springframework.dao.DataRetrievalFailureException;
|
||||||
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
import java.security.cert.X509Certificate;
|
import java.security.cert.X509Certificate;
|
||||||
@ -38,9 +39,11 @@ import java.security.cert.X509Certificate;
|
|||||||
* HREF="http://ehcache.sourceforge.net">EHCACHE</a>.
|
* HREF="http://ehcache.sourceforge.net">EHCACHE</a>.
|
||||||
*
|
*
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
|
* @author Ben Alex
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
public class EhCacheBasedX509UserCache implements X509UserCache, InitializingBean {
|
public class EhCacheBasedX509UserCache implements X509UserCache,
|
||||||
|
InitializingBean {
|
||||||
//~ Static fields/initializers =============================================
|
//~ Static fields/initializers =============================================
|
||||||
|
|
||||||
private static final Log logger = LogFactory.getLog(EhCacheBasedX509UserCache.class);
|
private static final Log logger = LogFactory.getLog(EhCacheBasedX509UserCache.class);
|
||||||
@ -55,10 +58,6 @@ public class EhCacheBasedX509UserCache implements X509UserCache, InitializingBea
|
|||||||
this.cache = cache;
|
this.cache = cache;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void afterPropertiesSet() throws Exception {
|
|
||||||
Assert.notNull(cache, "cache is mandatory");
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserDetails getUserFromCache(X509Certificate userCert) {
|
public UserDetails getUserFromCache(X509Certificate userCert) {
|
||||||
Element element = null;
|
Element element = null;
|
||||||
|
|
||||||
@ -70,8 +69,13 @@ public class EhCacheBasedX509UserCache implements X509UserCache, InitializingBea
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug("X.509 Cache hit. SubjectDN: "
|
String subjectDN = "unknown";
|
||||||
+ userCert.getSubjectDN());
|
|
||||||
|
if ((userCert != null) && (userCert.getSubjectDN() != null)) {
|
||||||
|
subjectDN = userCert.getSubjectDN().toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
logger.debug("X.509 Cache hit. SubjectDN: " + subjectDN);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
@ -81,6 +85,10 @@ public class EhCacheBasedX509UserCache implements X509UserCache, InitializingBea
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
Assert.notNull(cache, "cache is mandatory");
|
||||||
|
}
|
||||||
|
|
||||||
public void putUserInCache(X509Certificate userCert, UserDetails user) {
|
public void putUserInCache(X509Certificate userCert, UserDetails user) {
|
||||||
Element element = new Element(userCert, user);
|
Element element = new Element(userCert, user);
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/* Copyright 2004 Acegi Technology Pty Limited
|
/* Copyright 2004, 2005 Acegi Technology Pty Limited
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@ -17,19 +17,21 @@ package net.sf.acegisecurity.providers.x509.cache;
|
|||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import net.sf.acegisecurity.providers.dao.User;
|
|
||||||
import net.sf.acegisecurity.providers.x509.X509TestUtils;
|
|
||||||
import net.sf.acegisecurity.MockApplicationContext;
|
|
||||||
import net.sf.acegisecurity.UserDetails;
|
|
||||||
import net.sf.acegisecurity.GrantedAuthority;
|
import net.sf.acegisecurity.GrantedAuthority;
|
||||||
import net.sf.acegisecurity.GrantedAuthorityImpl;
|
import net.sf.acegisecurity.GrantedAuthorityImpl;
|
||||||
|
import net.sf.acegisecurity.MockApplicationContext;
|
||||||
|
import net.sf.acegisecurity.UserDetails;
|
||||||
|
import net.sf.acegisecurity.providers.dao.User;
|
||||||
|
import net.sf.acegisecurity.providers.x509.X509TestUtils;
|
||||||
|
|
||||||
import net.sf.ehcache.Cache;
|
import net.sf.ehcache.Cache;
|
||||||
|
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* DOCUMENT ME!
|
||||||
|
*
|
||||||
* @author Luke Taylor
|
* @author Luke Taylor
|
||||||
* @version $Id$
|
* @version $Id$
|
||||||
*/
|
*/
|
||||||
@ -58,7 +60,8 @@ public class EhCacheBasedX509UserCacheTests extends TestCase {
|
|||||||
// Check it gets stored in the cache
|
// Check it gets stored in the cache
|
||||||
cache.putUserInCache(X509TestUtils.buildTestCertificate(), getUser());
|
cache.putUserInCache(X509TestUtils.buildTestCertificate(), getUser());
|
||||||
assertEquals(getUser().getPassword(),
|
assertEquals(getUser().getPassword(),
|
||||||
cache.getUserFromCache(X509TestUtils.buildTestCertificate()).getPassword());
|
cache.getUserFromCache(X509TestUtils.buildTestCertificate())
|
||||||
|
.getPassword());
|
||||||
|
|
||||||
// Check it gets removed from the cache
|
// Check it gets removed from the cache
|
||||||
cache.removeUserFromCache(X509TestUtils.buildTestCertificate());
|
cache.removeUserFromCache(X509TestUtils.buildTestCertificate());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user