📄 jcsifspnegoauthenticationhandlertests.java
字号:
/* * Copyright 2007 The JA-SIG Collaborative. All rights reserved. See license * distributed with this file and available online at * http://www.uportal.org/license.html */package org.jasig.cas.support.spnego.authentication.handler.support;import junit.framework.TestCase;import org.jasig.cas.authentication.handler.AuthenticationException;import org.jasig.cas.authentication.principal.SimplePrincipal;import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;import org.jasig.cas.support.spnego.MockJCSIFAuthentication;import org.jasig.cas.support.spnego.authentication.handler.support.JCIFSSpnegoAuthenticationHandler;import org.jasig.cas.support.spnego.authentication.principal.SpnegoCredentials;/** * @author Marc-Antoine Garrigue * @author Arnaud Lesueur * @version $Id: JCSIFSpnegoAuthenticationHandlerTests.java 42058 2007-06-11 15:59:18Z sbattaglia $ * @since 3.1 * */public class JCSIFSpnegoAuthenticationHandlerTests extends TestCase { private JCIFSSpnegoAuthenticationHandler authenticationHandler; protected void setUp() throws Exception { this.authenticationHandler = new JCIFSSpnegoAuthenticationHandler(); } public void testSuccessfulAuthenticationWithDomainName() throws AuthenticationException { final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {0, 1, 2}); this.authenticationHandler.setPrincipalWithDomainName(true); this.authenticationHandler.setAuthentication(new MockJCSIFAuthentication(true)); assertTrue(this.authenticationHandler.authenticate(credentials)); assertEquals("test", credentials.getPrincipal().getId()); assertNotNull(credentials.getNextToken()); } public void testSuccessfulAuthenticationWithoutDomainName() throws AuthenticationException { final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {0, 1, 2}); this.authenticationHandler.setPrincipalWithDomainName(false); this.authenticationHandler.setAuthentication(new MockJCSIFAuthentication(true)); assertTrue(this.authenticationHandler.authenticate(credentials)); assertEquals("test", credentials.getPrincipal().getId()); assertNotNull(credentials.getNextToken()); } public void testUnsuccessfulAuthentication() { final SpnegoCredentials credentials = new SpnegoCredentials(new byte[] {0, 1, 2}); this.authenticationHandler.setAuthentication(new MockJCSIFAuthentication(false)); try { this.authenticationHandler.authenticate(credentials); fail("An AuthenticationException should have been thrown"); } catch (AuthenticationException e) { assertNull(credentials.getNextToken()); assertNull(credentials.getPrincipal()); } } public void testSupports() { assertFalse(this.authenticationHandler.supports(null)); assertTrue(this.authenticationHandler.supports(new SpnegoCredentials(new byte[] {0, 1, 2}))); assertFalse(this.authenticationHandler.supports(new UsernamePasswordCredentials())); } public void testGetSimpleCredentials() { String myNtlmUser = "DOMAIN\\Username"; String myKerberosUser = "Username@DOMAIN.COM"; this.authenticationHandler.setPrincipalWithDomainName(true); assertEquals(new SimplePrincipal(myNtlmUser), this.authenticationHandler .getSimplePrincipal(myNtlmUser, true)); assertEquals(new SimplePrincipal(myKerberosUser), this.authenticationHandler .getSimplePrincipal(myKerberosUser, false)); this.authenticationHandler.setPrincipalWithDomainName(false); assertEquals(new SimplePrincipal("Username"), this.authenticationHandler .getSimplePrincipal(myNtlmUser, true)); assertEquals(new SimplePrincipal("Username"), this.authenticationHandler .getSimplePrincipal(myKerberosUser, false)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -