01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.harmony.auth.tests.jgss.kerberos;
19:
20: import java.util.Date;
21: import java.security.PrivilegedAction;
22:
23: import javax.security.auth.Subject;
24: import javax.security.auth.kerberos.KerberosPrincipal;
25: import javax.security.auth.kerberos.KerberosTicket;
26:
27: import org.apache.harmony.auth.jgss.kerberos.KerberosUtils;
28: import org.apache.harmony.auth.jgss.kerberos.toolbox.KerberosToolboxImpl;
29: import org.apache.harmony.auth.jgss.kerberos.toolbox.KerberosToolboxSpi;
30:
31: import junit.framework.TestCase;
32:
33: public class KerberosUtilsTest extends TestCase {
34:
35: public void testGetKerberosToolBox() throws Exception {
36: KerberosToolboxSpi kerberosToolBoxSpi = KerberosUtils
37: .getKerberosToolbox("TESTKDCNAME");
38: assertTrue(kerberosToolBoxSpi instanceof KerberosToolboxImpl);
39: }
40:
41: public void testGetTGT_fromContext() throws Exception {
42: final KerberosPrincipal clientPrincipal = new KerberosPrincipal(
43: "leo@EXAMPLE.COM");
44: final KerberosPrincipal serverPrincipal = new KerberosPrincipal(
45: "krbtgt/EXAMPLE.COM@EXAMPLE.COM");
46: KerberosTicket tgt = new KerberosTicket(new byte[0],
47: clientPrincipal, serverPrincipal, new byte[0], 1,
48: new boolean[0], new Date(1000), null, new Date(
49: new Date().getTime() + 1000), null, null);
50: Subject subject = new Subject();
51: subject.getPrivateCredentials().add(tgt);
52: KerberosTicket tgtFromContext = (KerberosTicket) Subject.doAs(
53: subject, new PrivilegedAction<KerberosTicket>() {
54: public KerberosTicket run() {
55: return KerberosUtils.getTGT(clientPrincipal);
56: }
57: });
58: assertNotNull(tgtFromContext);
59: assertEquals(tgt, tgtFromContext);
60: }
61:
62: public void testGetTGT_fromLoginContext() throws Exception {
63: final KerberosPrincipal clientPrincipal = new KerberosPrincipal(
64: "leo@EXAMPLE.COM");
65: KerberosTicket tgt = KerberosUtils.getTGT(clientPrincipal);
66: assertNull(tgt);
67: }
68: }
|