Path: blob/master/src/java.security.sasl/share/classes/javax/security/sasl/AuthorizeCallback.java
41159 views
/*1* Copyright (c) 2000, 2020, 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 javax.security.sasl;2627import javax.security.auth.callback.Callback;2829/**30* This callback is used by {@code SaslServer} to determine whether31* one entity (identified by an authenticated authentication id)32* can act on33* behalf of another entity (identified by an authorization id).34*35* @since 1.536*37* @author Rosanna Lee38* @author Rob Weltman39*/40public class AuthorizeCallback implements Callback, java.io.Serializable {41/**42* The (authenticated) authentication id to check.43* @serial44*/45private String authenticationID;4647/**48* The authorization id to check.49* @serial50*/51private String authorizationID;5253/**54* The id of the authorized entity. If null, the id of55* the authorized entity is authorizationID.56* @serial57*/58private String authorizedID;5960/**61* A flag indicating whether the authentication id is allowed to62* act on behalf of the authorization id.63* @serial64*/65private boolean authorized;6667/**68* Constructs an instance of {@code AuthorizeCallback}.69*70* @param authnID The (authenticated) authentication id.71* @param authzID The authorization id.72*/73public AuthorizeCallback(String authnID, String authzID) {74authenticationID = authnID;75authorizationID = authzID;76}7778/**79* Returns the authentication id to check.80* @return The authentication id to check.81*/82public String getAuthenticationID() {83return authenticationID;84}8586/**87* Returns the authorization id to check.88* @return The authentication id to check.89*/90public String getAuthorizationID() {91return authorizationID;92}9394/**95* Determines whether the authentication id is allowed to96* act on behalf of the authorization id.97*98* @return {@code true} if authorization is allowed; {@code false} otherwise99* @see #setAuthorized(boolean)100* @see #getAuthorizedID()101*/102public boolean isAuthorized() {103return authorized;104}105106/**107* Sets whether the authorization is allowed.108* @param ok {@code true} if authorization is allowed; {@code false} otherwise109* @see #isAuthorized110* @see #setAuthorizedID(java.lang.String)111*/112public void setAuthorized(boolean ok) {113authorized = ok;114}115116/**117* Returns the id of the authorized user.118* @return The id of the authorized user. {@code null} means the119* authorization failed.120* @see #setAuthorized(boolean)121* @see #setAuthorizedID(java.lang.String)122*/123public String getAuthorizedID() {124if (!authorized) {125return null;126}127return (authorizedID == null) ? authorizationID : authorizedID;128}129130/**131* Sets the id of the authorized entity. Called by handler only when the id132* is different from getAuthorizationID(). For example, the id133* might need to be canonicalized for the environment in which it134* will be used.135* @param id The id of the authorized user.136* @see #setAuthorized(boolean)137* @see #getAuthorizedID138*/139public void setAuthorizedID(String id) {140authorizedID = id;141}142143private static final long serialVersionUID = -2353344186490470805L;144}145146147