Renamed all JAAS* classes to Jaas*
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
package net.sf.acegisecurity.providers.jaas;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.acegisecurity.Authentication;
|
||||
import net.sf.acegisecurity.AuthenticationException;
|
||||
import net.sf.acegisecurity.GrantedAuthority;
|
||||
import net.sf.acegisecurity.GrantedAuthorityImpl;
|
||||
import net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken;
|
||||
import org.springframework.context.support.FileSystemXmlApplicationContext;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Insert comments here...
|
||||
* <br>
|
||||
*
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class JaasAuthenticationProviderTests extends TestCase {
|
||||
|
||||
private JaasAuthenticationProvider jaasProvider;
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
String resName = "/" + getClass().getName().replace('.', '/') + ".xml";
|
||||
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(getClass().getResource(resName).toString());
|
||||
jaasProvider = (JaasAuthenticationProvider) context.getBean("jaasAuthenticationProvider");
|
||||
}
|
||||
|
||||
public void testFull() throws Exception {
|
||||
|
||||
GrantedAuthorityImpl role1 = new GrantedAuthorityImpl("ROLE_1");
|
||||
GrantedAuthorityImpl role2 = new GrantedAuthorityImpl("ROLE_2");
|
||||
|
||||
GrantedAuthority[] defaultAuths = new GrantedAuthority[]{
|
||||
role1,
|
||||
role2,
|
||||
};
|
||||
|
||||
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("user", "password", defaultAuths);
|
||||
|
||||
Authentication auth = jaasProvider.authenticate(token);
|
||||
|
||||
List list = Arrays.asList(auth.getAuthorities());
|
||||
|
||||
assertTrue("GrantedAuthorities does not contain ROLE_TEST",
|
||||
list.contains(new GrantedAuthorityImpl("ROLE_TEST")));
|
||||
|
||||
assertTrue("GrantedAuthorities does not contain ROLE_1", list.contains(role1));
|
||||
|
||||
assertTrue("GrantedAuthorities does not contain ROLE_2", list.contains(role2));
|
||||
}
|
||||
|
||||
public void testBadUser() {
|
||||
try {
|
||||
jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("asdf", "password"));
|
||||
fail("LoginException should have been thrown for the bad user");
|
||||
} catch (AuthenticationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testBadPassword() {
|
||||
try {
|
||||
jaasProvider.authenticate(new UsernamePasswordAuthenticationToken("user", "asdf"));
|
||||
fail("LoginException should have been thrown for the bad password");
|
||||
} catch (AuthenticationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?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="jaasAuthenticationProvider" class="net.sf.acegisecurity.providers.jaas.JaasAuthenticationProvider">
|
||||
<property name="loginContextName">
|
||||
<value>JAASTest</value>
|
||||
</property>
|
||||
<property name="loginConfig">
|
||||
<value>classpath:net/sf/acegisecurity/providers/jaas/login.conf</value>
|
||||
</property>
|
||||
<property name="callbackHandlers">
|
||||
<list>
|
||||
<bean class="net.sf.acegisecurity.providers.jaas.TestCallbackHandler"/>
|
||||
<bean class="net.sf.acegisecurity.providers.jaas.JaasNameCallbackHandler"/>
|
||||
<bean class="net.sf.acegisecurity.providers.jaas.JaasPasswordCallbackHandler"/>
|
||||
</list>
|
||||
</property>
|
||||
<property name="authorityGranters">
|
||||
<list>
|
||||
<bean class="net.sf.acegisecurity.providers.jaas.TestAuthorityGranter"/>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
</beans>
|
||||
@@ -14,7 +14,7 @@ import java.io.IOException;
|
||||
* @author Ray Krueger
|
||||
* @version $Id$
|
||||
*/
|
||||
public class TestCallbackHandler implements JAASAuthenticationCallbackHandler {
|
||||
public class TestCallbackHandler implements JaasAuthenticationCallbackHandler {
|
||||
|
||||
Authentication auth;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user