Author: rareddy
Date: 2010-07-22 11:15:43 -0400 (Thu, 22 Jul 2010)
New Revision: 2368
Modified:
trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java
trunk/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java
Log:
TEIID-1048: adding a unit test for pass though identity
Modified: trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java 2010-07-22
13:29:41 UTC (rev 2367)
+++ trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java 2010-07-22
15:15:43 UTC (rev 2368)
@@ -78,7 +78,7 @@
if (existing != null) {
this.userName = getUserName(existing)+AT+domain;
this.securitydomain = domain;
- this.loginContext = new LoginContext(domain, existing);
+ this.loginContext = createLoginContext(domain, existing);
return;
}
@@ -133,6 +133,10 @@
protected LoginContext createLoginContext(String domain, CallbackHandler handler) throws
LoginException {
return new LoginContext(domain, handler);
}
+
+ protected LoginContext createLoginContext(String domain, Subject subject) throws
LoginException {
+ return new LoginContext(domain, subject);
+ }
public LoginContext getLoginContext() {
return this.loginContext;
Modified: trunk/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java
===================================================================
---
trunk/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java 2010-07-22
13:29:41 UTC (rev 2367)
+++
trunk/runtime/src/test/java/org/teiid/services/TestMembershipServiceImpl.java 2010-07-22
15:15:43 UTC (rev 2368)
@@ -22,9 +22,12 @@
package org.teiid.services;
+import java.security.Principal;
import java.util.ArrayList;
+import java.util.HashSet;
import java.util.List;
+import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;
import javax.security.auth.login.LoginException;
@@ -51,11 +54,24 @@
}
private TeiidLoginContext createMembershipService() throws Exception {
- TeiidLoginContext membershipService = new
TeiidLoginContext(Mockito.mock(SecurityHelper.class)) {
+ Principal p = Mockito.mock(Principal.class);
+ Mockito.stub(p.getName()).toReturn("alreadylogged"); //$NON-NLS-1$
+ HashSet<Principal> principals = new HashSet<Principal>();
+ principals.add(p);
+
+ Subject subject = new Subject(false, principals, new HashSet(), new HashSet());
+ SecurityHelper sh = Mockito.mock(SecurityHelper.class);
+ Mockito.stub(sh.getSubjectInContext("passthrough")).toReturn(subject);
//$NON-NLS-1$
+
+ TeiidLoginContext membershipService = new TeiidLoginContext(sh) {
public LoginContext createLoginContext(String domain, CallbackHandler handler) throws
LoginException {
LoginContext context = Mockito.mock(LoginContext.class);
return context;
}
+ protected LoginContext createLoginContext(String domain, Subject subject) throws
LoginException {
+ LoginContext context = Mockito.mock(LoginContext.class);
+ return context;
+ }
};
return membershipService;
}
@@ -64,7 +80,7 @@
public void testAuthenticate() throws Exception {
TeiidLoginContext ms = createMembershipService();
List<String> domains = new ArrayList<String>();
- domains.add("testFile");
+ domains.add("testFile"); //$NON-NLS-1$
ms.authenticateUser("user1", new
Credentials("pass1".toCharArray()), null, domains); //$NON-NLS-1$ //$NON-NLS-2$
Mockito.verify(ms.getLoginContext()).login();
@@ -73,4 +89,12 @@
}
+ public void testPassThrough() throws Exception {
+ TeiidLoginContext ms = createMembershipService();
+ List<String> domains = new ArrayList<String>();
+ domains.add("passthrough"); //$NON-NLS-1$
+ ms.authenticateUser("user1", new
Credentials("pass1".toCharArray()), null, domains); //$NON-NLS-1$ //$NON-NLS-2$
+
+ assertEquals("alreadylogged@passthrough", ms.getUserName());
//$NON-NLS-1$
+ }
}