1. /*
  2. * @(#)AuthorizeCallback.java 1.10 04/02/03
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.security.sasl;
  8. import javax.security.auth.callback.Callback;
  9. /**
  10. * This callback is used by <tt>SaslServer</tt> to determine whether
  11. * one entity (identified by an authenticated authentication id)
  12. * can act on
  13. * behalf of another entity (identified by an authorization id).
  14. *
  15. * @since 1.5
  16. *
  17. * @author Rosanna Lee
  18. * @author Rob Weltman
  19. */
  20. public class AuthorizeCallback implements Callback, java.io.Serializable {
  21. /**
  22. * The (authenticated) authentication id to check.
  23. * @serial
  24. */
  25. private String authenticationID;
  26. /**
  27. * The authorization id to check.
  28. * @serial
  29. */
  30. private String authorizationID;
  31. /**
  32. * The id of the authorized entity. If null, the id of
  33. * the authorized entity is authorizationID.
  34. * @serial
  35. */
  36. private String authorizedID;
  37. /**
  38. * A flag indicating whether the authentication id is allowed to
  39. * act on behalf of the authorization id.
  40. * @serial
  41. */
  42. private boolean authorized;
  43. /**
  44. * Constructs an instance of <tt>AuthorizeCallback</tt>.
  45. *
  46. * @param authnID The (authenticated) authentication id.
  47. * @param authzID The authorization id.
  48. */
  49. public AuthorizeCallback(String authnID, String authzID) {
  50. authenticationID = authnID;
  51. authorizationID = authzID;
  52. }
  53. /**
  54. * Returns the authentication id to check.
  55. * @return The authentication id to check.
  56. */
  57. public String getAuthenticationID() {
  58. return authenticationID;
  59. }
  60. /**
  61. * Returns the authorization id to check.
  62. * @return The authentication id to check.
  63. */
  64. public String getAuthorizationID() {
  65. return authorizationID;
  66. }
  67. /**
  68. * Determines whether the authentication id is allowed to
  69. * act on behalf of the authorization id.
  70. *
  71. * @return <tt>true</tt> if authorization is allowed; <tt>false</tt> otherwise
  72. * @see #setAuthorized(boolean)
  73. * @see #getAuthorizedID()
  74. */
  75. public boolean isAuthorized() {
  76. return authorized;
  77. }
  78. /**
  79. * Sets whether the authorization is allowed.
  80. * @param ok <tt>true</tt> if authorization is allowed; <tt>false</tt> otherwise
  81. * @see #isAuthorized
  82. * @see #setAuthorizedID(java.lang.String)
  83. */
  84. public void setAuthorized(boolean ok) {
  85. authorized = ok;
  86. }
  87. /**
  88. * Returns the id of the authorized user.
  89. * @return The id of the authorized user. <tt>null</tt> means the
  90. * authorization failed.
  91. * @see #setAuthorized(boolean)
  92. * @see #setAuthorizedID(java.lang.String)
  93. */
  94. public String getAuthorizedID() {
  95. if (!authorized) {
  96. return null;
  97. }
  98. return (authorizedID == null) ? authorizationID : authorizedID;
  99. }
  100. /**
  101. * Sets the id of the authorized entity. Called by handler only when the id
  102. * is different from getAuthorizationID(). For example, the id
  103. * might need to be canonicalized for the environment in which it
  104. * will be used.
  105. * @param id The id of the authorized user.
  106. * @see #setAuthorized(boolean)
  107. * @see #getAuthorizedID
  108. */
  109. public void setAuthorizedID(String id) {
  110. authorizedID = id;
  111. }
  112. private static final long serialVersionUID = -2353344186490470805L;
  113. }