Java 类javax.security.auth.callback.TextInputCallback 实例源码

项目:neoscada    文件:JavaCallbackHandler.java   
private void fillResultFromCallback ( final Callback cb, final javax.security.auth.callback.Callback jcb )
{
    if ( cb instanceof TextCallback && jcb instanceof TextInputCallback )
    {
        ( (TextCallback)cb ).setValue ( ( (TextInputCallback)jcb ).getText () );
    }
    else if ( cb instanceof UserNameCallback && jcb instanceof NameCallback )
    {
        ( (UserNameCallback)cb ).setValue ( ( (NameCallback)jcb ).getName () );
    }
    else if ( cb instanceof PasswordCallback && jcb instanceof javax.security.auth.callback.PasswordCallback )
    {
        ( (PasswordCallback)cb ).setPassword ( String.valueOf ( ( (javax.security.auth.callback.PasswordCallback)jcb ).getPassword () ) );
    }
    else
    {
        cb.cancel ();
    }
}
项目:neoscada    文件:JavaCallbackHandler.java   
private javax.security.auth.callback.Callback convert ( final Callback cb )
{
    if ( cb instanceof UserNameCallback )
    {
        return new NameCallback ( ( (UserNameCallback)cb ).getLabel () );
    }
    else if ( cb instanceof TextCallback )
    {
        return new TextInputCallback ( ( (TextCallback)cb ).getLabel () );
    }
    if ( cb instanceof PasswordCallback )
    {
        return new javax.security.auth.callback.PasswordCallback ( ( (PasswordCallback)cb ).getLabel (), false );
    }
    return null;
}
项目:nics-tools    文件:LoginTest.java   
private void addLoginCallbackMessage(Callback[] callbacks)
throws UnsupportedCallbackException
{
    int i = 0;
    try {
        for (i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof TextOutputCallback) {
                handleTextOutputCallback((TextOutputCallback)callbacks[i]);
            } else if (callbacks[i] instanceof NameCallback) {
                handleNameCallback((NameCallback)callbacks[i]);
            } else if (callbacks[i] instanceof PasswordCallback) {
                handlePasswordCallback((PasswordCallback)callbacks[i]);
            } else if (callbacks[i] instanceof TextInputCallback) {
                handleTextInputCallback((TextInputCallback)callbacks[i]);
            } else if (callbacks[i] instanceof ChoiceCallback) {
                handleChoiceCallback((ChoiceCallback)callbacks[i]);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new UnsupportedCallbackException(callbacks[i],e.getMessage());
    }
}
项目:nics-tools    文件:FailedLoginTest.java   
private void addLoginCallbackMessage(Callback[] callbacks)
throws UnsupportedCallbackException {
    int i = 0;
    try {
        for (i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof TextOutputCallback) {
                handleTextOutputCallback((TextOutputCallback)callbacks[i]);
            } else if (callbacks[i] instanceof NameCallback) {
                handleNameCallback((NameCallback)callbacks[i]);
            } else if (callbacks[i] instanceof PasswordCallback) {
                handlePasswordCallback((PasswordCallback)callbacks[i]);
            } else if (callbacks[i] instanceof TextInputCallback) {
                handleTextInputCallback((TextInputCallback)callbacks[i]);
            } else if (callbacks[i] instanceof ChoiceCallback) {
                handleChoiceCallback((ChoiceCallback)callbacks[i]);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
        throw new UnsupportedCallbackException(callbacks[i],e.getMessage());
    }
}
项目:nics-tools    文件:LoginTest.java   
private void handleTextInputCallback(TextInputCallback tic)
    throws IOException {
    // prompt for text input
    System.out.print(tic.getPrompt());
    System.out.flush();
    tic.setText((new BufferedReader
        (new InputStreamReader(System.in))).readLine());
}
项目:nics-tools    文件:FailedLoginTest.java   
private void handleTextInputCallback(TextInputCallback tic)
    throws IOException {
    // prompt for text input
    System.out.print(tic.getPrompt());
    System.out.flush();
    tic.setText((new BufferedReader
        (new InputStreamReader(System.in))).readLine());
}
项目:javify    文件:GenKeyCmd.java   
private String parseUserPrompt(TextInputCallback ticb)
{
  String result = ticb.getText();
  if (result == null || result.trim().length() == 0)
    result = ticb.getDefaultText();
  else if (result.trim().equals(".")) //$NON-NLS-1$
    result = null;
  else
    result = result.trim();

  return result;
}
项目:javify    文件:AbstractCallbackHandler.java   
public void handle(Callback[] callbacks)
  throws IOException, UnsupportedCallbackException
{
  if (callbacks == null)
    throw new NullPointerException();
  for (int i = 0; i < callbacks.length; i++)
    {
      if (callbacks[i] == null)
        continue;
      if (callbacks[i] instanceof ChoiceCallback)
        handleChoice((ChoiceCallback) callbacks[i]);
      else if (callbacks[i] instanceof ConfirmationCallback)
        handleConfirmation((ConfirmationCallback) callbacks[i]);
      else if (callbacks[i] instanceof LanguageCallback)
        handleLanguage((LanguageCallback) callbacks[i]);
      else if (callbacks[i] instanceof NameCallback)
        handleName((NameCallback) callbacks[i]);
      else if (callbacks[i] instanceof PasswordCallback)
        handlePassword((PasswordCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextInputCallback)
        handleTextInput((TextInputCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextOutputCallback)
        handleTextOutput((TextOutputCallback) callbacks[i]);
      else
        handleOther(callbacks[i]);
    }
}
项目:javify    文件:ConsoleCallbackHandler.java   
protected void handleTextInput(TextInputCallback c) throws IOException
{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  out.print(c.getPrompt());
  String text = in.readLine();
  if (text != null)
    c.setText(text);
}
项目:javify    文件:AWTCallbackHandler.java   
protected synchronized void handleTextInput(TextInputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setTitle(c.getPrompt());
  dialog.setLayout(new BorderLayout());
  Label label = new Label(c.getPrompt());
  TextArea text = new TextArea(10, 40);
  if (c.getDefaultText() != null)
    {
      text.setText(c.getDefaultText());
    }
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  ok.setActionCommand(ACTION_OK);
  ok.addActionListener(this);
  Button cancel = new Button(messages.getString("callback.cancel"));
  cancel.setActionCommand(ACTION_CANCEL);
  cancel.addActionListener(this);
  dialog.add(label, BorderLayout.NORTH);
  dialog.add(text, BorderLayout.CENTER);
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  buttons.add(cancel);
  dialog.add(buttons, BorderLayout.SOUTH);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  if (actionCommand.equals(ACTION_OK))
    {
      c.setText(text.getText());
    }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:jvm-stm    文件:GenKeyCmd.java   
private String parseUserPrompt(TextInputCallback ticb)
{
  String result = ticb.getText();
  if (result == null || result.trim().length() == 0)
    result = ticb.getDefaultText();
  else if (result.trim().equals(".")) //$NON-NLS-1$
    result = null;
  else
    result = result.trim();

  return result;
}
项目:jvm-stm    文件:AbstractCallbackHandler.java   
public void handle(Callback[] callbacks)
  throws IOException, UnsupportedCallbackException
{
  if (callbacks == null)
    throw new NullPointerException();
  for (int i = 0; i < callbacks.length; i++)
    {
      if (callbacks[i] == null)
        continue;
      if (callbacks[i] instanceof ChoiceCallback)
        handleChoice((ChoiceCallback) callbacks[i]);
      else if (callbacks[i] instanceof ConfirmationCallback)
        handleConfirmation((ConfirmationCallback) callbacks[i]);
      else if (callbacks[i] instanceof LanguageCallback)
        handleLanguage((LanguageCallback) callbacks[i]);
      else if (callbacks[i] instanceof NameCallback)
        handleName((NameCallback) callbacks[i]);
      else if (callbacks[i] instanceof PasswordCallback)
        handlePassword((PasswordCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextInputCallback)
        handleTextInput((TextInputCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextOutputCallback)
        handleTextOutput((TextOutputCallback) callbacks[i]);
      else
        handleOther(callbacks[i]);
    }
}
项目:jvm-stm    文件:ConsoleCallbackHandler.java   
protected void handleTextInput(TextInputCallback c) throws IOException
{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  out.print(c.getPrompt());
  String text = in.readLine();
  if (text != null)
    c.setText(text);
}
项目:jvm-stm    文件:AWTCallbackHandler.java   
protected synchronized void handleTextInput(TextInputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setTitle(c.getPrompt());
  dialog.setLayout(new BorderLayout());
  Label label = new Label(c.getPrompt());
  TextArea text = new TextArea(10, 40);
  if (c.getDefaultText() != null)
    {
      text.setText(c.getDefaultText());
    }
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  ok.setActionCommand(ACTION_OK);
  ok.addActionListener(this);
  Button cancel = new Button(messages.getString("callback.cancel"));
  cancel.setActionCommand(ACTION_CANCEL);
  cancel.addActionListener(this);
  dialog.add(label, BorderLayout.NORTH);
  dialog.add(text, BorderLayout.CENTER);
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  buttons.add(cancel);
  dialog.add(buttons, BorderLayout.SOUTH);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  if (actionCommand.equals(ACTION_OK))
    {
      c.setText(text.getText());
    }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:cn1    文件:TextInputCallbackTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertTrue(test instanceof TextInputCallback);
    assertEquals(((TextInputCallback) golden).getDefaultText(),
            ((TextInputCallback) test).getDefaultText());
    assertEquals(((TextInputCallback) golden).getPrompt(),
            ((TextInputCallback) test).getPrompt());
    assertEquals(((TextInputCallback) golden).getText(),
            ((TextInputCallback) test).getText());
}
项目:JamVM-PH    文件:GenKeyCmd.java   
private String parseUserPrompt(TextInputCallback ticb)
{
  String result = ticb.getText();
  if (result == null || result.trim().length() == 0)
    result = ticb.getDefaultText();
  else if (result.trim().equals(".")) //$NON-NLS-1$
    result = null;
  else
    result = result.trim();

  return result;
}
项目:JamVM-PH    文件:AbstractCallbackHandler.java   
public void handle(Callback[] callbacks)
  throws IOException, UnsupportedCallbackException
{
  if (callbacks == null)
    throw new NullPointerException();
  for (int i = 0; i < callbacks.length; i++)
    {
      if (callbacks[i] == null)
        continue;
      if (callbacks[i] instanceof ChoiceCallback)
        handleChoice((ChoiceCallback) callbacks[i]);
      else if (callbacks[i] instanceof ConfirmationCallback)
        handleConfirmation((ConfirmationCallback) callbacks[i]);
      else if (callbacks[i] instanceof LanguageCallback)
        handleLanguage((LanguageCallback) callbacks[i]);
      else if (callbacks[i] instanceof NameCallback)
        handleName((NameCallback) callbacks[i]);
      else if (callbacks[i] instanceof PasswordCallback)
        handlePassword((PasswordCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextInputCallback)
        handleTextInput((TextInputCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextOutputCallback)
        handleTextOutput((TextOutputCallback) callbacks[i]);
      else
        handleOther(callbacks[i]);
    }
}
项目:JamVM-PH    文件:ConsoleCallbackHandler.java   
protected void handleTextInput(TextInputCallback c) throws IOException
{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  out.print(c.getPrompt());
  String text = in.readLine();
  if (text != null)
    c.setText(text);
}
项目:JamVM-PH    文件:AWTCallbackHandler.java   
protected synchronized void handleTextInput(TextInputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setTitle(c.getPrompt());
  dialog.setLayout(new BorderLayout());
  Label label = new Label(c.getPrompt());
  TextArea text = new TextArea(10, 40);
  if (c.getDefaultText() != null)
    {
      text.setText(c.getDefaultText());
    }
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  ok.setActionCommand(ACTION_OK);
  ok.addActionListener(this);
  Button cancel = new Button(messages.getString("callback.cancel"));
  cancel.setActionCommand(ACTION_CANCEL);
  cancel.addActionListener(this);
  dialog.add(label, BorderLayout.NORTH);
  dialog.add(text, BorderLayout.CENTER);
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  buttons.add(cancel);
  dialog.add(buttons, BorderLayout.SOUTH);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  if (actionCommand.equals(ACTION_OK))
    {
      c.setText(text.getText());
    }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:classpath    文件:GenKeyCmd.java   
private String parseUserPrompt(TextInputCallback ticb)
{
  String result = ticb.getText();
  if (result == null || result.trim().length() == 0)
    result = ticb.getDefaultText();
  else if (result.trim().equals(".")) //$NON-NLS-1$
    result = null;
  else
    result = result.trim();

  return result;
}
项目:classpath    文件:AbstractCallbackHandler.java   
public void handle(Callback[] callbacks)
  throws IOException, UnsupportedCallbackException
{
  if (callbacks == null)
    throw new NullPointerException();
  for (int i = 0; i < callbacks.length; i++)
    {
      if (callbacks[i] == null)
        continue;
      if (callbacks[i] instanceof ChoiceCallback)
        handleChoice((ChoiceCallback) callbacks[i]);
      else if (callbacks[i] instanceof ConfirmationCallback)
        handleConfirmation((ConfirmationCallback) callbacks[i]);
      else if (callbacks[i] instanceof LanguageCallback)
        handleLanguage((LanguageCallback) callbacks[i]);
      else if (callbacks[i] instanceof NameCallback)
        handleName((NameCallback) callbacks[i]);
      else if (callbacks[i] instanceof PasswordCallback)
        handlePassword((PasswordCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextInputCallback)
        handleTextInput((TextInputCallback) callbacks[i]);
      else if (callbacks[i] instanceof TextOutputCallback)
        handleTextOutput((TextOutputCallback) callbacks[i]);
      else
        handleOther(callbacks[i]);
    }
}
项目:classpath    文件:ConsoleCallbackHandler.java   
protected void handleTextInput(TextInputCallback c) throws IOException
{
  BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  out.print(c.getPrompt());
  String text = in.readLine();
  if (text != null)
    c.setText(text);
}
项目:classpath    文件:AWTCallbackHandler.java   
protected synchronized void handleTextInput(TextInputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setTitle(c.getPrompt());
  dialog.setLayout(new BorderLayout());
  Label label = new Label(c.getPrompt());
  TextArea text = new TextArea(10, 40);
  if (c.getDefaultText() != null)
    {
      text.setText(c.getDefaultText());
    }
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  ok.setActionCommand(ACTION_OK);
  ok.addActionListener(this);
  Button cancel = new Button(messages.getString("callback.cancel"));
  cancel.setActionCommand(ACTION_CANCEL);
  cancel.addActionListener(this);
  dialog.add(label, BorderLayout.NORTH);
  dialog.add(text, BorderLayout.CENTER);
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  buttons.add(cancel);
  dialog.add(buttons, BorderLayout.SOUTH);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  if (actionCommand.equals(ACTION_OK))
    {
      c.setText(text.getText());
    }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:freeVM    文件:TextInputCallbackTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertTrue(test instanceof TextInputCallback);
    assertEquals(((TextInputCallback) golden).getDefaultText(),
            ((TextInputCallback) test).getDefaultText());
    assertEquals(((TextInputCallback) golden).getPrompt(),
            ((TextInputCallback) test).getPrompt());
    assertEquals(((TextInputCallback) golden).getText(),
            ((TextInputCallback) test).getText());
}
项目:freeVM    文件:TextInputCallbackTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertTrue(test instanceof TextInputCallback);
    assertEquals(((TextInputCallback) golden).getDefaultText(),
            ((TextInputCallback) test).getDefaultText());
    assertEquals(((TextInputCallback) golden).getPrompt(),
            ((TextInputCallback) test).getPrompt());
    assertEquals(((TextInputCallback) golden).getText(),
            ((TextInputCallback) test).getText());
}
项目:tomcat7    文件:JAASCallbackHandler.java   
/**
 * Retrieve the information requested in the provided <code>Callbacks</code>.
 * This implementation only recognizes {@link NameCallback},
 * {@link PasswordCallback} and {@link TextInputCallback}.
 * {@link TextInputCallback} is used to pass the various additional
 * parameters required for DIGEST authentication. 
 *
 * @param callbacks The set of <code>Callback</code>s to be processed
 *
 * @exception IOException if an input/output error occurs
 * @exception UnsupportedCallbackException if the login method requests
 *  an unsupported callback type
 */
@Override
public void handle(Callback callbacks[])
    throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getContainer().getLogger().isTraceEnabled())
                realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username));
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            final char[] passwordcontents;
            if (password != null) {
                passwordcontents = password.toCharArray();
            } else {
                passwordcontents = new char[0];
            }
            ((PasswordCallback) callbacks[i]).setPassword
                (passwordcontents);
        } else if (callbacks[i] instanceof TextInputCallback) {
            TextInputCallback cb = ((TextInputCallback) callbacks[i]);
            if (cb.getPrompt().equals("nonce")) {
                cb.setText(nonce);
            } else if (cb.getPrompt().equals("nc")) {
                cb.setText(nc);
            } else if (cb.getPrompt().equals("cnonce")) {
                cb.setText(cnonce);
            } else if (cb.getPrompt().equals("qop")) {
                cb.setText(qop);
            } else if (cb.getPrompt().equals("realmName")) {
                cb.setText(realmName);
            } else if (cb.getPrompt().equals("md5a2")) {
                cb.setText(md5a2);
            } else if (cb.getPrompt().equals("authMethod")) {
                cb.setText(authMethod);
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
项目:lams    文件:JAASCallbackHandler.java   
/**
 * Retrieve the information requested in the provided <code>Callbacks</code>.
 * This implementation only recognizes {@link NameCallback},
 * {@link PasswordCallback} and {@link TextInputCallback}.
 * {@link TextInputCallback} is ued to pass the various additional
 * parameters required for DIGEST authentication. 
 *
 * @param callbacks The set of <code>Callback</code>s to be processed
 *
 * @exception IOException if an input/output error occurs
 * @exception UnsupportedCallbackException if the login method requests
 *  an unsupported callback type
 */
public void handle(Callback callbacks[])
    throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getContainer().getLogger().isTraceEnabled())
                realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username));
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            final char[] passwordcontents;
            if (password != null) {
                passwordcontents = password.toCharArray();
            } else {
                passwordcontents = new char[0];
            }
            ((PasswordCallback) callbacks[i]).setPassword
                (passwordcontents);
        } else if (callbacks[i] instanceof TextInputCallback) {
            TextInputCallback cb = ((TextInputCallback) callbacks[i]);
            if (cb.getPrompt().equals("nonce")) {
                cb.setText(nonce);
            } else if (cb.getPrompt().equals("nc")) {
                cb.setText(nc);
            } else if (cb.getPrompt().equals("cnonce")) {
                cb.setText(cnonce);
            } else if (cb.getPrompt().equals("qop")) {
                cb.setText(qop);
            } else if (cb.getPrompt().equals("realmName")) {
                cb.setText(realmName);
            } else if (cb.getPrompt().equals("md5a2")) {
                cb.setText(md5a2);
            } else if (cb.getPrompt().equals("authMethod")) {
                cb.setText(authMethod);
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
项目:apache-tomcat-7.0.73-with-comment    文件:JAASCallbackHandler.java   
/**
 * Retrieve the information requested in the provided <code>Callbacks</code>.
 * This implementation only recognizes {@link NameCallback},
 * {@link PasswordCallback} and {@link TextInputCallback}.
 * {@link TextInputCallback} is used to pass the various additional
 * parameters required for DIGEST authentication. 
 *
 * @param callbacks The set of <code>Callback</code>s to be processed
 *
 * @exception IOException if an input/output error occurs
 * @exception UnsupportedCallbackException if the login method requests
 *  an unsupported callback type
 */
@Override
public void handle(Callback callbacks[])
    throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getContainer().getLogger().isTraceEnabled())
                realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username));
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            final char[] passwordcontents;
            if (password != null) {
                passwordcontents = password.toCharArray();
            } else {
                passwordcontents = new char[0];
            }
            ((PasswordCallback) callbacks[i]).setPassword
                (passwordcontents);
        } else if (callbacks[i] instanceof TextInputCallback) {
            TextInputCallback cb = ((TextInputCallback) callbacks[i]);
            if (cb.getPrompt().equals("nonce")) {
                cb.setText(nonce);
            } else if (cb.getPrompt().equals("nc")) {
                cb.setText(nc);
            } else if (cb.getPrompt().equals("cnonce")) {
                cb.setText(cnonce);
            } else if (cb.getPrompt().equals("qop")) {
                cb.setText(qop);
            } else if (cb.getPrompt().equals("realmName")) {
                cb.setText(realmName);
            } else if (cb.getPrompt().equals("md5a2")) {
                cb.setText(md5a2);
            } else if (cb.getPrompt().equals("authMethod")) {
                cb.setText(authMethod);
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
项目:lazycat    文件:JAASCallbackHandler.java   
/**
 * Retrieve the information requested in the provided <code>Callbacks</code>
 * . This implementation only recognizes {@link NameCallback},
 * {@link PasswordCallback} and {@link TextInputCallback}.
 * {@link TextInputCallback} is used to pass the various additional
 * parameters required for DIGEST authentication.
 *
 * @param callbacks
 *            The set of <code>Callback</code>s to be processed
 *
 * @exception IOException
 *                if an input/output error occurs
 * @exception UnsupportedCallbackException
 *                if the login method requests an unsupported callback type
 */
@Override
public void handle(Callback callbacks[]) throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getContainer().getLogger().isTraceEnabled())
                realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username));
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            final char[] passwordcontents;
            if (password != null) {
                passwordcontents = password.toCharArray();
            } else {
                passwordcontents = new char[0];
            }
            ((PasswordCallback) callbacks[i]).setPassword(passwordcontents);
        } else if (callbacks[i] instanceof TextInputCallback) {
            TextInputCallback cb = ((TextInputCallback) callbacks[i]);
            if (cb.getPrompt().equals("nonce")) {
                cb.setText(nonce);
            } else if (cb.getPrompt().equals("nc")) {
                cb.setText(nc);
            } else if (cb.getPrompt().equals("cnonce")) {
                cb.setText(cnonce);
            } else if (cb.getPrompt().equals("qop")) {
                cb.setText(qop);
            } else if (cb.getPrompt().equals("realmName")) {
                cb.setText(realmName);
            } else if (cb.getPrompt().equals("md5a2")) {
                cb.setText(md5a2);
            } else if (cb.getPrompt().equals("authMethod")) {
                cb.setText(authMethod);
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
项目:javify    文件:GenKeyCmd.java   
/**
 * @param name the X.500 distinguished name of the principal for whom the
 *          key/certificate are being generated.
 * @throws UnsupportedCallbackException if no implementation of a name
 *           callback is available.
 * @throws IOException if an I/O related exception occurs during the process.
 * @throws IllegalArgumentException if the designated, or captured, value is
 *           not a valid X.500 distinguished name.
 */
private void setDName(String name) throws IOException,
    UnsupportedCallbackException
{
  if (name != null && name.trim().length() > 0)
    name = name.trim();
  else
    {
      // prompt user to provide one
      String dnTxt = Messages.getString("GenKeyCmd.0"); //$NON-NLS-1$
      String oDefault =  Messages.getString("GenKeyCmd.6"); //$NON-NLS-1$
      String lDefault =  Messages.getString("GenKeyCmd.7"); //$NON-NLS-1$
      String stDefault = Messages.getString("GenKeyCmd.8"); //$NON-NLS-1$
      String cDefault =  Messages.getString("GenKeyCmd.9"); //$NON-NLS-1$
      String cnPrompt = Messages.getString("GenKeyCmd.10"); //$NON-NLS-1$
      String oPrompt =  Messages.getFormattedString("GenKeyCmd.11", oDefault); //$NON-NLS-1$
      String ouPrompt = Messages.getString("GenKeyCmd.13"); //$NON-NLS-1$
      String lPrompt =  Messages.getFormattedString("GenKeyCmd.14", lDefault); //$NON-NLS-1$
      String stPrompt = Messages.getFormattedString("GenKeyCmd.16", stDefault); //$NON-NLS-1$
      String cPrompt =  Messages.getFormattedString("GenKeyCmd.18", cDefault); //$NON-NLS-1$

      TextOutputCallback dnCB = new TextOutputCallback(TextOutputCallback.INFORMATION,
                                                       dnTxt);
      TextInputCallback cnCB = new TextInputCallback(cnPrompt);
      TextInputCallback oCB =  new TextInputCallback(oPrompt, oDefault);
      TextInputCallback ouCB = new TextInputCallback(ouPrompt);
      TextInputCallback lCB =  new TextInputCallback(lPrompt, lDefault);
      TextInputCallback sCB =  new TextInputCallback(stPrompt, stDefault);
      TextInputCallback cCB =  new TextInputCallback(cPrompt, cDefault);
      getCallbackHandler().handle(new Callback[] { dnCB, cnCB, oCB, ouCB, lCB, sCB, cCB });
      StringBuilder sb = new StringBuilder();

      // handle CN
      name = parseUserPrompt(cnCB);
      if (name != null && name.length() > 0)
        sb.append("CN=").append(name); //$NON-NLS-1$

      // handle O
      name = parseUserPrompt(oCB);
      if (name != null && name.length() > 0)
        sb.append(",O=").append(name); //$NON-NLS-1$

      // handle OU
      name = parseUserPrompt(ouCB);
      if (name != null && name.length() > 0)
        sb.append(",OU=").append(name.trim()); //$NON-NLS-1$

      // handle L
      name = parseUserPrompt(lCB);
      if (name != null && name.length() > 0)
        sb.append(",L=").append(name.trim()); //$NON-NLS-1$

      // handle ST
      name = parseUserPrompt(sCB);
      if (name != null && name.length() > 0)
        sb.append(",ST=").append(name.trim()); //$NON-NLS-1$

      // handle C
      name = parseUserPrompt(cCB);
      if (name != null && name.length() > 0)
        sb.append(",C=").append(name.trim()); //$NON-NLS-1$

      name = sb.toString().trim();
    }
  if (Configuration.DEBUG)
    log.fine("dName=[" + name + "]"); //$NON-NLS-1$ //$NON-NLS-2$
  distinguishedName = new X500DistinguishedName(name);
}
项目:javify    文件:DefaultCallbackHandler.java   
protected void handleTextInput(TextInputCallback c)
{
  c.setText("");
}
项目:javify    文件:SwingCallbackHandler.java   
protected void handleTextInput (final TextInputCallback callback)
  throws IOException
{
  final JDialog dialog = new JDialog ();
  Container content = dialog.getContentPane ();
  content.setLayout (new GridBagLayout ());

  content.add (new JLabel (callback.getPrompt ()),
                           new GridBagConstraints (0, 0, 1, 1, 0, 0,
                                                   GridBagConstraints.NORTHWEST,
                                                   GridBagConstraints.NONE,
                                                   new Insets (10, 10, 15, 5), 0, 0));

  final JTextArea text = new JTextArea (24, 80);
  text.setEditable (true);
  String _text;
  if ((_text = callback.getDefaultText ()) != null)
    text.setText (_text);
  text.setFont (new Font ("Monospaced", Font.PLAIN, 12));
  JScrollPane textPane = new JScrollPane (text,
                                          JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                          JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  content.add (textPane,
               new GridBagConstraints (0, 1, 1, 1, 1, 1,
                                       GridBagConstraints.CENTER,
                                       GridBagConstraints.BOTH,
                                       new Insets (5, 10, 5, 10), 0, 0));

  ActionListener listener = new ActionListener ()
    {
      public void actionPerformed (ActionEvent ae)
      {
        String cmd = ae.getActionCommand ();
        if (cmd.equals ("okay"))
          callback.setText (text.getText ());
        dialog.setVisible (false);
        synchronized (callback)
          {
            callback.notify ();
          }
      }
    };

  JPanel buttons = new JPanel ();
  buttons.setLayout (new FlowLayout (FlowLayout.RIGHT));
  JButton cancel = new JButton (messages.getString ("callback.cancel"));
  JButton okay = new JButton (messages.getString ("callback.ok"));
  cancel.setActionCommand ("cancel");
  cancel.addActionListener (listener);
  buttons.add (cancel);
  okay.setActionCommand ("okay");
  okay.addActionListener (listener);
  buttons.add (okay);
  content.add (buttons, new GridBagConstraints (0, 2, 1, 1, 0, 0,
                                                GridBagConstraints.SOUTHEAST,
                                                GridBagConstraints.NONE,
                                                new Insets (0, 10, 10, 10), 0, 0));

  dialog.setResizable (true);
  dialog.pack ();
  dialog.setVisible (true);
  dialog.getRootPane ().setDefaultButton (okay);
  waitForInput (dialog, callback);
}
项目:jvm-stm    文件:GenKeyCmd.java   
/**
 * @param name the X.500 distinguished name of the principal for whom the
 *          key/certificate are being generated.
 * @throws UnsupportedCallbackException if no implementation of a name
 *           callback is available.
 * @throws IOException if an I/O related exception occurs during the process.
 * @throws IllegalArgumentException if the designated, or captured, value is
 *           not a valid X.500 distinguished name.
 */
private void setDName(String name) throws IOException,
    UnsupportedCallbackException
{
  if (name != null && name.trim().length() > 0)
    name = name.trim();
  else
    {
      // prompt user to provide one
      String dnTxt = Messages.getString("GenKeyCmd.0"); //$NON-NLS-1$
      String oDefault =  Messages.getString("GenKeyCmd.6"); //$NON-NLS-1$
      String lDefault =  Messages.getString("GenKeyCmd.7"); //$NON-NLS-1$
      String stDefault = Messages.getString("GenKeyCmd.8"); //$NON-NLS-1$
      String cDefault =  Messages.getString("GenKeyCmd.9"); //$NON-NLS-1$
      String cnPrompt = Messages.getString("GenKeyCmd.10"); //$NON-NLS-1$
      String oPrompt =  Messages.getFormattedString("GenKeyCmd.11", oDefault); //$NON-NLS-1$
      String ouPrompt = Messages.getString("GenKeyCmd.13"); //$NON-NLS-1$
      String lPrompt =  Messages.getFormattedString("GenKeyCmd.14", lDefault); //$NON-NLS-1$
      String stPrompt = Messages.getFormattedString("GenKeyCmd.16", stDefault); //$NON-NLS-1$
      String cPrompt =  Messages.getFormattedString("GenKeyCmd.18", cDefault); //$NON-NLS-1$

      TextOutputCallback dnCB = new TextOutputCallback(TextOutputCallback.INFORMATION,
                                                       dnTxt);
      TextInputCallback cnCB = new TextInputCallback(cnPrompt);
      TextInputCallback oCB =  new TextInputCallback(oPrompt, oDefault);
      TextInputCallback ouCB = new TextInputCallback(ouPrompt);
      TextInputCallback lCB =  new TextInputCallback(lPrompt, lDefault);
      TextInputCallback sCB =  new TextInputCallback(stPrompt, stDefault);
      TextInputCallback cCB =  new TextInputCallback(cPrompt, cDefault);
      getCallbackHandler().handle(new Callback[] { dnCB, cnCB, oCB, ouCB, lCB, sCB, cCB });
      StringBuilder sb = new StringBuilder();

      // handle CN
      name = parseUserPrompt(cnCB);
      if (name != null && name.length() > 0)
        sb.append("CN=").append(name); //$NON-NLS-1$

      // handle O
      name = parseUserPrompt(oCB);
      if (name != null && name.length() > 0)
        sb.append(",O=").append(name); //$NON-NLS-1$

      // handle OU
      name = parseUserPrompt(ouCB);
      if (name != null && name.length() > 0)
        sb.append(",OU=").append(name.trim()); //$NON-NLS-1$

      // handle L
      name = parseUserPrompt(lCB);
      if (name != null && name.length() > 0)
        sb.append(",L=").append(name.trim()); //$NON-NLS-1$

      // handle ST
      name = parseUserPrompt(sCB);
      if (name != null && name.length() > 0)
        sb.append(",ST=").append(name.trim()); //$NON-NLS-1$

      // handle C
      name = parseUserPrompt(cCB);
      if (name != null && name.length() > 0)
        sb.append(",C=").append(name.trim()); //$NON-NLS-1$

      name = sb.toString().trim();
    }
  if (Configuration.DEBUG)
    log.fine("dName=[" + name + "]"); //$NON-NLS-1$ //$NON-NLS-2$
  distinguishedName = new X500DistinguishedName(name);
}
项目:jvm-stm    文件:DefaultCallbackHandler.java   
protected void handleTextInput(TextInputCallback c)
{
  c.setText("");
}
项目:jvm-stm    文件:SwingCallbackHandler.java   
protected void handleTextInput (final TextInputCallback callback)
  throws IOException
{
  final JDialog dialog = new JDialog ();
  Container content = dialog.getContentPane ();
  content.setLayout (new GridBagLayout ());

  content.add (new JLabel (callback.getPrompt ()),
                           new GridBagConstraints (0, 0, 1, 1, 0, 0,
                                                   GridBagConstraints.NORTHWEST,
                                                   GridBagConstraints.NONE,
                                                   new Insets (10, 10, 15, 5), 0, 0));

  final JTextArea text = new JTextArea (24, 80);
  text.setEditable (true);
  String _text;
  if ((_text = callback.getDefaultText ()) != null)
    text.setText (_text);
  text.setFont (new Font ("Monospaced", Font.PLAIN, 12));
  JScrollPane textPane = new JScrollPane (text,
                                          JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                          JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  content.add (textPane,
               new GridBagConstraints (0, 1, 1, 1, 1, 1,
                                       GridBagConstraints.CENTER,
                                       GridBagConstraints.BOTH,
                                       new Insets (5, 10, 5, 10), 0, 0));

  ActionListener listener = new ActionListener ()
    {
      public void actionPerformed (ActionEvent ae)
      {
        String cmd = ae.getActionCommand ();
        if (cmd.equals ("okay"))
          callback.setText (text.getText ());
        dialog.setVisible (false);
        synchronized (callback)
          {
            callback.notify ();
          }
      }
    };

  JPanel buttons = new JPanel ();
  buttons.setLayout (new FlowLayout (FlowLayout.RIGHT));
  JButton cancel = new JButton (messages.getString ("callback.cancel"));
  JButton okay = new JButton (messages.getString ("callback.ok"));
  cancel.setActionCommand ("cancel");
  cancel.addActionListener (listener);
  buttons.add (cancel);
  okay.setActionCommand ("okay");
  okay.addActionListener (listener);
  buttons.add (okay);
  content.add (buttons, new GridBagConstraints (0, 2, 1, 1, 0, 0,
                                                GridBagConstraints.SOUTHEAST,
                                                GridBagConstraints.NONE,
                                                new Insets (0, 10, 10, 10), 0, 0));

  dialog.setResizable (true);
  dialog.pack ();
  dialog.setVisible (true);
  dialog.getRootPane ().setDefaultButton (okay);
  waitForInput (dialog, callback);
}
项目:class-guard    文件:JAASCallbackHandler.java   
/**
 * Retrieve the information requested in the provided <code>Callbacks</code>.
 * This implementation only recognizes {@link NameCallback},
 * {@link PasswordCallback} and {@link TextInputCallback}.
 * {@link TextInputCallback} is used to pass the various additional
 * parameters required for DIGEST authentication. 
 *
 * @param callbacks The set of <code>Callback</code>s to be processed
 *
 * @exception IOException if an input/output error occurs
 * @exception UnsupportedCallbackException if the login method requests
 *  an unsupported callback type
 */
@Override
public void handle(Callback callbacks[])
    throws IOException, UnsupportedCallbackException {

    for (int i = 0; i < callbacks.length; i++) {

        if (callbacks[i] instanceof NameCallback) {
            if (realm.getContainer().getLogger().isTraceEnabled())
                realm.getContainer().getLogger().trace(sm.getString("jaasCallback.username", username));
            ((NameCallback) callbacks[i]).setName(username);
        } else if (callbacks[i] instanceof PasswordCallback) {
            final char[] passwordcontents;
            if (password != null) {
                passwordcontents = password.toCharArray();
            } else {
                passwordcontents = new char[0];
            }
            ((PasswordCallback) callbacks[i]).setPassword
                (passwordcontents);
        } else if (callbacks[i] instanceof TextInputCallback) {
            TextInputCallback cb = ((TextInputCallback) callbacks[i]);
            if (cb.getPrompt().equals("nonce")) {
                cb.setText(nonce);
            } else if (cb.getPrompt().equals("nc")) {
                cb.setText(nc);
            } else if (cb.getPrompt().equals("cnonce")) {
                cb.setText(cnonce);
            } else if (cb.getPrompt().equals("qop")) {
                cb.setText(qop);
            } else if (cb.getPrompt().equals("realmName")) {
                cb.setText(realmName);
            } else if (cb.getPrompt().equals("md5a2")) {
                cb.setText(md5a2);
            } else if (cb.getPrompt().equals("authMethod")) {
                cb.setText(authMethod);
            } else {
                throw new UnsupportedCallbackException(callbacks[i]);
            }
        } else {
            throw new UnsupportedCallbackException(callbacks[i]);
        }
    }
}
项目:cn1    文件:TextInputCallbackTest.java   
@Override
protected Object[] getData() {
    TextInputCallback t = new TextInputCallback("prmpt","defText");
    t.setText("new text");
    return new Object[] { new TextInputCallback("prompt","defaultTextInput"), t };
}
项目:JamVM-PH    文件:GenKeyCmd.java   
/**
 * @param name the X.500 distinguished name of the principal for whom the
 *          key/certificate are being generated.
 * @throws UnsupportedCallbackException if no implementation of a name
 *           callback is available.
 * @throws IOException if an I/O related exception occurs during the process.
 * @throws IllegalArgumentException if the designated, or captured, value is
 *           not a valid X.500 distinguished name.
 */
private void setDName(String name) throws IOException,
    UnsupportedCallbackException
{
  if (name != null && name.trim().length() > 0)
    name = name.trim();
  else
    {
      // prompt user to provide one
      String dnTxt = Messages.getString("GenKeyCmd.0"); //$NON-NLS-1$
      String oDefault =  Messages.getString("GenKeyCmd.6"); //$NON-NLS-1$
      String lDefault =  Messages.getString("GenKeyCmd.7"); //$NON-NLS-1$
      String stDefault = Messages.getString("GenKeyCmd.8"); //$NON-NLS-1$
      String cDefault =  Messages.getString("GenKeyCmd.9"); //$NON-NLS-1$
      String cnPrompt = Messages.getString("GenKeyCmd.10"); //$NON-NLS-1$
      String oPrompt =  Messages.getFormattedString("GenKeyCmd.11", oDefault); //$NON-NLS-1$
      String ouPrompt = Messages.getString("GenKeyCmd.13"); //$NON-NLS-1$
      String lPrompt =  Messages.getFormattedString("GenKeyCmd.14", lDefault); //$NON-NLS-1$
      String stPrompt = Messages.getFormattedString("GenKeyCmd.16", stDefault); //$NON-NLS-1$
      String cPrompt =  Messages.getFormattedString("GenKeyCmd.18", cDefault); //$NON-NLS-1$

      TextOutputCallback dnCB = new TextOutputCallback(TextOutputCallback.INFORMATION,
                                                       dnTxt);
      TextInputCallback cnCB = new TextInputCallback(cnPrompt);
      TextInputCallback oCB =  new TextInputCallback(oPrompt, oDefault);
      TextInputCallback ouCB = new TextInputCallback(ouPrompt);
      TextInputCallback lCB =  new TextInputCallback(lPrompt, lDefault);
      TextInputCallback sCB =  new TextInputCallback(stPrompt, stDefault);
      TextInputCallback cCB =  new TextInputCallback(cPrompt, cDefault);
      getCallbackHandler().handle(new Callback[] { dnCB, cnCB, oCB, ouCB, lCB, sCB, cCB });
      StringBuilder sb = new StringBuilder();

      // handle CN
      name = parseUserPrompt(cnCB);
      if (name != null && name.length() > 0)
        sb.append("CN=").append(name); //$NON-NLS-1$

      // handle O
      name = parseUserPrompt(oCB);
      if (name != null && name.length() > 0)
        sb.append(",O=").append(name); //$NON-NLS-1$

      // handle OU
      name = parseUserPrompt(ouCB);
      if (name != null && name.length() > 0)
        sb.append(",OU=").append(name.trim()); //$NON-NLS-1$

      // handle L
      name = parseUserPrompt(lCB);
      if (name != null && name.length() > 0)
        sb.append(",L=").append(name.trim()); //$NON-NLS-1$

      // handle ST
      name = parseUserPrompt(sCB);
      if (name != null && name.length() > 0)
        sb.append(",ST=").append(name.trim()); //$NON-NLS-1$

      // handle C
      name = parseUserPrompt(cCB);
      if (name != null && name.length() > 0)
        sb.append(",C=").append(name.trim()); //$NON-NLS-1$

      name = sb.toString().trim();
    }
  if (Configuration.DEBUG)
    log.fine("dName=[" + name + "]"); //$NON-NLS-1$ //$NON-NLS-2$
  distinguishedName = new X500DistinguishedName(name);
}
项目:JamVM-PH    文件:DefaultCallbackHandler.java   
protected void handleTextInput(TextInputCallback c)
{
  c.setText("");
}
项目:JamVM-PH    文件:SwingCallbackHandler.java   
protected void handleTextInput (final TextInputCallback callback)
  throws IOException
{
  final JDialog dialog = new JDialog ();
  Container content = dialog.getContentPane ();
  content.setLayout (new GridBagLayout ());

  content.add (new JLabel (callback.getPrompt ()),
                           new GridBagConstraints (0, 0, 1, 1, 0, 0,
                                                   GridBagConstraints.NORTHWEST,
                                                   GridBagConstraints.NONE,
                                                   new Insets (10, 10, 15, 5), 0, 0));

  final JTextArea text = new JTextArea (24, 80);
  text.setEditable (true);
  String _text;
  if ((_text = callback.getDefaultText ()) != null)
    text.setText (_text);
  text.setFont (new Font ("Monospaced", Font.PLAIN, 12));
  JScrollPane textPane = new JScrollPane (text,
                                          JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                                          JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
  content.add (textPane,
               new GridBagConstraints (0, 1, 1, 1, 1, 1,
                                       GridBagConstraints.CENTER,
                                       GridBagConstraints.BOTH,
                                       new Insets (5, 10, 5, 10), 0, 0));

  ActionListener listener = new ActionListener ()
    {
      public void actionPerformed (ActionEvent ae)
      {
        String cmd = ae.getActionCommand ();
        if (cmd.equals ("okay"))
          callback.setText (text.getText ());
        dialog.setVisible (false);
        synchronized (callback)
          {
            callback.notify ();
          }
      }
    };

  JPanel buttons = new JPanel ();
  buttons.setLayout (new FlowLayout (FlowLayout.RIGHT));
  JButton cancel = new JButton (messages.getString ("callback.cancel"));
  JButton okay = new JButton (messages.getString ("callback.ok"));
  cancel.setActionCommand ("cancel");
  cancel.addActionListener (listener);
  buttons.add (cancel);
  okay.setActionCommand ("okay");
  okay.addActionListener (listener);
  buttons.add (okay);
  content.add (buttons, new GridBagConstraints (0, 2, 1, 1, 0, 0,
                                                GridBagConstraints.SOUTHEAST,
                                                GridBagConstraints.NONE,
                                                new Insets (0, 10, 10, 10), 0, 0));

  dialog.setResizable (true);
  dialog.pack ();
  dialog.setVisible (true);
  dialog.getRootPane ().setDefaultButton (okay);
  waitForInput (dialog, callback);
}