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