1. /*
  2. * @(#)AppConfigurationEntry.java 1.32 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.security.auth.login;
  8. import java.util.Map;
  9. import java.util.Collections;
  10. /**
  11. * This class represents a single <code>LoginModule</code> entry
  12. * configured for the application specified in the
  13. * <code>getAppConfigurationEntry(String appName)</code>
  14. * method in the <code>Configuration</code> class. Each respective
  15. * <code>AppConfigurationEntry</code> contains a <code>LoginModule</code> name,
  16. * a control flag (specifying whether this <code>LoginModule</code> is
  17. * REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL), and LoginModule-specific
  18. * options. Please refer to the <code>Configuration</code> class for
  19. * more information on the different control flags and their semantics.
  20. *
  21. * @version 1.32, 01/23/03
  22. * @see javax.security.auth.login.Configuration
  23. */
  24. public class AppConfigurationEntry {
  25. private String loginModuleName;
  26. private LoginModuleControlFlag controlFlag;
  27. private Map options;
  28. /**
  29. * Default constructor for this class.
  30. *
  31. * <p> This entry represents a single <code>LoginModule</code>
  32. * entry configured for the application specified in the
  33. * <code>getAppConfigurationEntry(String appName)</code>
  34. * method from the <code>Configuration</code> class.
  35. *
  36. * @param loginModuleName String representing the class name of the
  37. * <code>LoginModule</code> configured for the
  38. * specified application. <p>
  39. *
  40. * @param controlFlag either REQUIRED, REQUISITE, SUFFICIENT,
  41. * or OPTIONAL. <p>
  42. *
  43. * @param options the options configured for this <code>LoginModule</code>.
  44. *
  45. * @exception IllegalArgumentException if <code>loginModuleName</code>
  46. * is null, if <code>LoginModuleName</code>
  47. * has a length of 0, if <code>controlFlag</code>
  48. * is not either REQUIRED, REQUISITE, SUFFICIENT
  49. * or OPTIONAL, or if <code>options</code> is null.
  50. */
  51. public AppConfigurationEntry(String loginModuleName,
  52. LoginModuleControlFlag controlFlag,
  53. Map options) {
  54. if (loginModuleName == null || loginModuleName.length() == 0 ||
  55. (controlFlag != LoginModuleControlFlag.REQUIRED &&
  56. controlFlag != LoginModuleControlFlag.REQUISITE &&
  57. controlFlag != LoginModuleControlFlag.SUFFICIENT &&
  58. controlFlag != LoginModuleControlFlag.OPTIONAL) ||
  59. options == null)
  60. throw new IllegalArgumentException();
  61. this.loginModuleName = loginModuleName;
  62. this.controlFlag = controlFlag;
  63. this.options = Collections.unmodifiableMap(options);
  64. }
  65. /**
  66. * Get the class name of the configured <code>LoginModule</code>.
  67. *
  68. * @return the class name of the configured <code>LoginModule</code> as
  69. * a String.
  70. */
  71. public String getLoginModuleName() {
  72. return loginModuleName;
  73. }
  74. /**
  75. * Return the controlFlag
  76. * (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL)
  77. * for this <code>LoginModule</code>.
  78. *
  79. * @return the controlFlag
  80. * (either REQUIRED, REQUISITE, SUFFICIENT, or OPTIONAL)
  81. * for this <code>LoginModule</code>.
  82. */
  83. public LoginModuleControlFlag getControlFlag() {
  84. return controlFlag;
  85. }
  86. /**
  87. * Get the options configured for this <code>LoginModule</code>.
  88. *
  89. * @return the options configured for this <code>LoginModule</code>
  90. * as an unmodifiable <code>Map</code>.
  91. */
  92. public Map getOptions() {
  93. return options;
  94. }
  95. /**
  96. * This class represents whether or not a <code>LoginModule</code>
  97. * is REQUIRED, REQUISITE, SUFFICIENT or OPTIONAL.
  98. */
  99. public static class LoginModuleControlFlag {
  100. private String controlFlag;
  101. /**
  102. * Required <code>LoginModule</code>.
  103. */
  104. public static final LoginModuleControlFlag REQUIRED =
  105. new LoginModuleControlFlag("required");
  106. /**
  107. * Requisite <code>LoginModule</code>.
  108. */
  109. public static final LoginModuleControlFlag REQUISITE =
  110. new LoginModuleControlFlag("requisite");
  111. /**
  112. * Sufficient <code>LoginModule</code>.
  113. */
  114. public static final LoginModuleControlFlag SUFFICIENT =
  115. new LoginModuleControlFlag("sufficient");
  116. /**
  117. * Optional <code>LoginModule</code>.
  118. */
  119. public static final LoginModuleControlFlag OPTIONAL =
  120. new LoginModuleControlFlag("optional");
  121. private LoginModuleControlFlag(String controlFlag) {
  122. this.controlFlag = controlFlag;
  123. }
  124. /**
  125. * Return a String representation of this controlFlag.
  126. *
  127. * @return a String representation of this controlFlag.
  128. */
  129. public String toString() {
  130. return (sun.security.util.ResourcesMgr.getString
  131. ("LoginModuleControlFlag: ") + controlFlag);
  132. }
  133. }
  134. }