Writing JAAS policy files

new InputStreamReaderSystem.in.readLine ; pc.setPasswordpw.toCharArray ; pw = null; Let pw be collected as soon as possible }

15.4.1.3 The text input callback

The TextInputCallback class javax.security.auth.callback.TextInput−Callback allows login modules to retrieve arbitrary text from the user. It functions almost exactly like the name callback; only the method names are changed: public String getText Retrieve the text currently stored in the callback object. public String getDefaultText Return the default text stored in the object. The default text is set by the login module when it constructs the callback; it will often be null . public String getPrompt Return the prompt stored in the object. The prompt is set by the login module when it constructs the callback. public void setTextString Text Store the text in the object. You are responsible for calling this, passing it the appropriate string supplied by the user.

15.4.1.4 The text output callback

The TextOutputCallback class javax.security.auth.callback.TextOutputCallback doesnt actually retrieve information from the user; it allows the login module to send a warning or informational message to the user. You can use the methods of this class to specify the message and display it to the user as appropriate: public String getMessage Specfiy the message to display to the user. public int getMessageType Get the type of the message, which will be one of these final static values: INFORMATION , WARNING , or ERROR .

15.4.1.5 The choice callback

When processing a ChoiceCallback object javax.security.auth.callback.ChoiceCallback , you are expected to present a given set of choices to the user and allow her to select one or more of them. You return an array of which choices were selected through this API: 306 public String getPrompt Return the prompt to be displayed to the user. The prompt is set by the login module when it constructs the callback. public String[] getChoices Return the list of choices that the user should be presented with. public int getDefaultChoice Return the index of whichever choice in the array of choices is the default. public boolean allowMultipleSelections If this method returns true , allow the user to make multiple selections. If it returns false , allow only a single selection. public void setSelectedIndexint selection Call this to indicate that the given selection in the array of choices has been selected. This method should be used only when the allowMultiple−Selections method returns false . public void setSelectedIndexesint[] selections Call this method with an array; each element in the array represents an item that was selected e.g., if item 3 is selected, put the number 3 into the array; dont set selections[3] to some value. If multiple selections are not allowed, this method throws an UnsupportedOperationException . public int[] getSelectedIndexes Return an array of the currently selected choices. If multiple selections are not allowed, return an array of length 1.

15.4.1.6 The confirmation callback

The ConfirmationCallback class javax.security.auth.callback.ConfirmationCallback allows the login module to ask the user a confirmation question that is answered with a yesno, yesnocancel, okcancel, or a similar answer. It has the following API: public String getPrompt Return the prompt that should be displayed to the user. public int getMessageType Return the message type INFORMATION , WARNING , or ERROR . public int getOptionType The type of callback. This will be either: