View Javadoc

1   package org.eclipse.jetty.security;
2   //========================================================================
3   //Copyright 2011-2012 Mort Bay Consulting Pty. Ltd.
4   //------------------------------------------------------------------------
5   //All rights reserved. This program and the accompanying materials
6   //are made available under the terms of the Eclipse Public License v1.0
7   //and Apache License v2.0 which accompanies this distribution.
8   //The Eclipse Public License is available at
9   //http://www.eclipse.org/legal/epl-v10.html
10  //The Apache License v2.0 is available at
11  //http://www.opensource.org/licenses/apache2.0.php
12  //You may elect to redistribute this code under either of these licenses.
13  //========================================================================
14  
15  import java.security.Principal;
16  
17  import org.eclipse.jetty.util.security.B64Code;
18  
19  public class SpnegoUserPrincipal implements Principal
20  {
21      private final String _name;
22      private byte[] _token;
23      private String _encodedToken;
24      
25      public SpnegoUserPrincipal( String name, String encodedToken )
26      {
27          _name = name;
28          _encodedToken = encodedToken;
29      }
30      
31      public SpnegoUserPrincipal( String name, byte[] token )
32      {
33          _name = name;
34          _token = token;
35      }
36      
37      public String getName()
38      {
39          return _name;
40      }
41  
42      public byte[] getToken()
43      {
44          if ( _token == null )
45          {
46              _token = B64Code.decode(_encodedToken);
47          }
48          return _token;
49      }
50      
51      public String getEncodedToken()
52      {
53          if ( _encodedToken == null )
54          {
55              _encodedToken = new String(B64Code.encode(_token,true));
56          }
57          return _encodedToken;
58      }   
59  }