KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > bridge > CallerIdentityUserPasswordBridgeTest


1 /**
2  *
3  * Copyright 2003-2004 The Apache Software Foundation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.security.bridge;
19
20 import java.util.Set JavaDoc;
21 import javax.security.auth.Subject JavaDoc;
22 import javax.security.auth.login.LoginException JavaDoc;
23
24 import org.apache.geronimo.security.ContextManager;
25 import org.apache.geronimo.security.IdentificationPrincipal;
26 import org.apache.geronimo.security.realm.providers.GeronimoPasswordCredential;
27
28
29 /**
30  * @version $Rev: 154957 $ $Date: 2005-02-22 21:07:36 -0800 (Tue, 22 Feb 2005) $
31  */

32 public class CallerIdentityUserPasswordBridgeTest extends AbstractBridgeTest {
33
34     private CallerIdentityUserPasswordRealmBridge bridge;
35
36     protected void setUp() throws Exception JavaDoc {
37         super.setUp();
38         bridge = new CallerIdentityUserPasswordRealmBridge();
39         bridge.setTargetRealm(TestLoginModule.JAAS_NAME);
40     }
41
42     public void testCallerIdentityBridge() throws Exception JavaDoc {
43         Subject JavaDoc sourceSubject = new Subject JavaDoc();
44         sourceSubject.getPrivateCredentials().add(new GeronimoPasswordCredential(AbstractBridgeTest.USER, AbstractBridgeTest.PASSWORD.toCharArray()));
45         Subject JavaDoc targetSubject = bridge.mapSubject(sourceSubject);
46         assertTrue("expected non-null client subject", targetSubject != null);
47         Set JavaDoc set = targetSubject.getPrincipals(IdentificationPrincipal.class);
48         assertEquals("client subject should have one ID principal", set.size(), 1);
49         IdentificationPrincipal idp = (IdentificationPrincipal)set.iterator().next();
50         targetSubject = ContextManager.getRegisteredSubject(idp.getId());
51         checkValidSubject(targetSubject);
52     }
53
54     public void testNoCredentials() throws Exception JavaDoc {
55         Subject JavaDoc sourceSubject = new Subject JavaDoc();
56         try {
57             bridge.mapSubject(sourceSubject);
58             fail();
59         } catch (LoginException JavaDoc e) {
60         }
61
62     }
63 }
64
Popular Tags