Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/net/httpserver/HttpPrincipal.java
38922 views
/*1* Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.net.httpserver;26import java.net.*;27import java.io.*;28import java.util.*;29import java.security.Principal;3031/**32* Represents a user authenticated by HTTP Basic or Digest33* authentication.34*/35@jdk.Exported36public class HttpPrincipal implements Principal {37private String username, realm;3839/**40* creates a HttpPrincipal from the given username and realm41* @param username The name of the user within the realm42* @param realm The realm.43* @throws NullPointerException if either username or realm are null44*/45public HttpPrincipal (String username, String realm) {46if (username == null || realm == null) {47throw new NullPointerException();48}49this.username = username;50this.realm = realm;51}5253/**54* Compares two HttpPrincipal. Returns <code>true</code>55* if <i>another</i> is an instance of HttpPrincipal, and its56* username and realm are equal to this object's username57* and realm. Returns <code>false</code> otherwise.58*/59public boolean equals (Object another) {60if (!(another instanceof HttpPrincipal)) {61return false;62}63HttpPrincipal theother = (HttpPrincipal)another;64return (username.equals(theother.username) &&65realm.equals(theother.realm));66}6768/**69* returns the contents of this principal in the form70* <i>realm:username</i>71*/72public String getName() {73return username;74}7576/**77* returns the username this object was created with.78*/79public String getUsername() {80return username;81}8283/**84* returns the realm this object was created with.85*/86public String getRealm() {87return realm;88}8990/**91* returns a hashcode for this HttpPrincipal. This is calculated92* as <code>(getUsername()+getRealm().hashCode()</code>93*/94public int hashCode() {95return (username+realm).hashCode();96}9798/**99* returns the same string as getName()100*/101public String toString() {102return getName();103}104}105106107