1. /*
  2. * @(#)AppConfigurationEntry.java 1.34 04/05/05
  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.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.34, 05/05/04
  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<String,?> options)
  54. {
  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<String,?> 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 (sun.security.util.ResourcesMgr.getString
  132. ("LoginModuleControlFlag: ") + controlFlag);
  133. }
  134. }
  135. }