1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.ws.security.spnego;
21
22 import org.ietf.jgss.GSSContext;
23 import org.ietf.jgss.GSSException;
24 import org.ietf.jgss.GSSManager;
25 import org.ietf.jgss.GSSName;
26 import org.ietf.jgss.Oid;
27
28 /**
29 * This class represents a PrivilegedAction implementation to validate a received (SPNEGO) ticket
30 * to a KDC.
31 */
32 public class DefaultSpnegoServiceAction implements SpnegoServiceAction {
33 private static org.apache.commons.logging.Log log =
34 org.apache.commons.logging.LogFactory.getLog(DefaultSpnegoServiceAction.class);
35
36 private byte[] ticket;
37 private String serviceName;
38 private GSSContext secContext;
39
40 /**
41 * Set the ticket to validate
42 */
43 public void setTicket(byte[] ticket) {
44 this.ticket = ticket;
45 }
46
47 /**
48 * The Service Name
49 */
50 public void setServiceName(String serviceName) {
51 this.serviceName = serviceName;
52 }
53
54 /**
55 * Validate a service ticket
56 */
57 public byte[] run() {
58 try {
59 GSSManager gssManager = GSSManager.getInstance();
60 Oid oid = new Oid("1.3.6.1.5.5.2");
61
62 GSSName gssService = gssManager.createName(serviceName, GSSName.NT_HOSTBASED_SERVICE);
63 secContext = gssManager.createContext(gssService, oid, null, GSSContext.DEFAULT_LIFETIME);
64
65 return secContext.acceptSecContext(ticket, 0, ticket.length);
66 } catch (GSSException e) {
67 if (log.isDebugEnabled()) {
68 log.debug("Error in obtaining a Kerberos token", e);
69 }
70 }
71
72 return null;
73 }
74
75 /**
76 * Get the GSSContext that was created after a service ticket was obtained
77 */
78 public GSSContext getContext() {
79 return secContext;
80 }
81
82 }