1 // ========================================================================
2 // Copyright (c) 2009-2009 Mort Bay Consulting Pty. Ltd.
3 // ------------------------------------------------------------------------
4 // All rights reserved. This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v1.0
6 // and Apache License v2.0 which accompanies this distribution.
7 // The Eclipse Public License is available at
8 // http://www.eclipse.org/legal/epl-v10.html
9 // The Apache License v2.0 is available at
10 // http://www.opensource.org/licenses/apache2.0.php
11 // You may elect to redistribute this code under either of these licenses.
12 // ========================================================================
13
14 package org.eclipse.jetty.security;
15
16 import java.security.Principal;
17
18 import javax.security.auth.Subject;
19 import org.eclipse.jetty.server.UserIdentity;
20
21
22 /* ------------------------------------------------------------ */
23 /**
24 * The default implementation of UserIdentity.
25 *
26 */
27 public class DefaultUserIdentity implements UserIdentity
28 {
29 private final Subject _subject;
30 private final Principal _userPrincipal;
31 private final String[] _roles;
32
33 public DefaultUserIdentity(Subject subject, Principal userPrincipal, String[] roles)
34 {
35 _subject=subject;
36 _userPrincipal=userPrincipal;
37 _roles=roles;
38 }
39
40 public Subject getSubject()
41 {
42 return _subject;
43 }
44
45 public Principal getUserPrincipal()
46 {
47 return _userPrincipal;
48 }
49
50 public boolean isUserInRole(String role)
51 {
52 for (String r :_roles)
53 if (r.equals(role))
54 return true;
55 return false;
56 }
57
58 public String toString()
59 {
60 return DefaultUserIdentity.class.getSimpleName()+"('"+_userPrincipal+"')";
61 }
62
63 }