2 // ========================================================================
3 // Copyright (c) 1995-2014 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.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.security;
21 import java.security.Principal;
23 import javax.security.auth.Subject;
25 import org.eclipse.jetty.server.UserIdentity;
28 /* ------------------------------------------------------------ */
30 * The default implementation of UserIdentity.
33 public class DefaultUserIdentity implements UserIdentity
35 private final Subject _subject;
36 private final Principal _userPrincipal;
37 private final String[] _roles;
39 public DefaultUserIdentity(Subject subject, Principal userPrincipal, String[] roles)
42 _userPrincipal=userPrincipal;
46 public Subject getSubject()
51 public Principal getUserPrincipal()
53 return _userPrincipal;
56 public boolean isUserInRole(String role, Scope scope)
58 //Servlet Spec 3.1, pg 125
62 String roleToTest = null;
63 if (scope!=null && scope.getRoleRefMap()!=null)
64 roleToTest=scope.getRoleRefMap().get(role);
66 //Servlet Spec 3.1, pg 125
67 if (roleToTest == null)
70 for (String r :_roles)
71 if (r.equals(roleToTest))
77 public String toString()
79 return DefaultUserIdentity.class.getSimpleName()+"('"+_userPrincipal+"')";