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

项目:MyVirtualDirectory    文件:UpnPwdCallbackHandler.java   
@Override
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {

    for (Callback callback : callbacks) {
        if (callback instanceof TextOutputCallback) {
             TextOutputCallback tc = (TextOutputCallback) callback;
             switch (tc.getMessageType()) {
                case TextOutputCallback.INFORMATION: logger.info(tc.getMessage()); break;
                case TextOutputCallback.ERROR: logger.error(tc.getMessage()); break;
                case TextOutputCallback.WARNING: logger.warn(tc.getMessage()); break;
             }
        } else if (callback instanceof NameCallback) {
            NameCallback nc = (NameCallback) callback;
            nc.setName(upn);
        } else if (callback instanceof PasswordCallback) {
            PasswordCallback pc = (PasswordCallback) callback;
            pc.setPassword(this.password.toCharArray());
        }
    }

}
项目: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    文件:LoginTest.java   
private void handleTextOutputCallback(TextOutputCallback toc) {
    debugMessage("Got TextOutputCallback");
    // display the message according to the specified type

    switch (toc.getMessageType()) {
        case TextOutputCallback.INFORMATION:
            debugMessage(toc.getMessage());
            break;
        case TextOutputCallback.ERROR:
            debugMessage("ERROR: " + toc.getMessage());
            break;
        case TextOutputCallback.WARNING:
            debugMessage("WARNING: " + toc.getMessage());
            break;
        default:
            debugMessage("Unsupported message type: " +
                toc.getMessageType());
    }
}
项目: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    文件:FailedLoginTest.java   
private void handleTextOutputCallback(TextOutputCallback toc) {
    debugMessage("Got TextOutputCallback");
    // display the message according to the specified type

    switch (toc.getMessageType()) {
        case TextOutputCallback.INFORMATION:
            debugMessage(toc.getMessage());
            break;
        case TextOutputCallback.ERROR:
            debugMessage("ERROR: " + toc.getMessage());
            break;
        case TextOutputCallback.WARNING:
            debugMessage("WARNING: " + toc.getMessage());
            break;
        default:
            debugMessage("Unsupported message type: " +
                toc.getMessageType());
    }
}
项目:apex-core    文件:DefaultCallbackHandler.java   
protected void processCallback(Callback callback) throws IOException, UnsupportedCallbackException
{
  if (callback instanceof NameCallback) {
    NameCallback namecb = (NameCallback)callback;
    namecb.setName(context.getValue(SecurityContext.USER_NAME));
  } else if (callback instanceof PasswordCallback) {
    PasswordCallback passcb = (PasswordCallback)callback;
    passcb.setPassword(context.getValue(SecurityContext.PASSWORD));
  } else if (callback instanceof RealmCallback) {
    RealmCallback realmcb = (RealmCallback)callback;
    realmcb.setText(context.getValue(SecurityContext.REALM));
  } else if (callback instanceof TextOutputCallback) {
    TextOutputCallback textcb = (TextOutputCallback)callback;
    if (textcb.getMessageType() == TextOutputCallback.INFORMATION) {
      logger.info(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.WARNING) {
      logger.warn(textcb.getMessage());
    } else if (textcb.getMessageType() == TextOutputCallback.ERROR) {
      logger.error(textcb.getMessage());
    } else {
      logger.debug("Auth message type {}, message {}", textcb.getMessageType(), textcb.getMessage());
    }
  } else {
    throw new UnsupportedCallbackException(callback);
  }
}
项目:TayzGrid    文件:PlainCallbackHandler.java   
public void handle(Callback[] callbacks) throws IOException,
    UnsupportedCallbackException {
  for (Callback cb : callbacks) {
    if (cb instanceof TextOutputCallback) {
      // TODO: Implement this
      throw new UnsupportedCallbackException(cb);
    } else if (cb instanceof NameCallback) {
      NameCallback nc = (NameCallback) cb;
      nc.setName(username);
    } else if (cb instanceof PasswordCallback) {
      PasswordCallback pc = (PasswordCallback) cb;
      pc.setPassword(password);
    } else {
      throw new UnsupportedCallbackException(cb);
    }
  }
}
项目:ontopia    文件:TMLoginModuleTest.java   
@Override
   public void handle(Callback[] callbacks)
     throws IOException, UnsupportedCallbackException {

     for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof NameCallback) {
         // prompt the user for a username
         NameCallback nc = (NameCallback)callbacks[i];
  String username = tokens[index++];
         nc.setName(username);

       } else if (callbacks[i] instanceof PasswordCallback) {      
         // prompt the user for sensitive information
         PasswordCallback pc = (PasswordCallback)callbacks[i];
  String password = tokens[index++];
         pc.setPassword(password.toCharArray());

} else if (callbacks[i] instanceof TextOutputCallback) {
  // ignore

       } else {
         throw new UnsupportedCallbackException(callbacks[i], 
                     "Unrecognized Callback");
       }
     }
   }
项目:arcus-java-client    文件:PlainCallbackHandler.java   
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for(Callback cb : callbacks) {
        if(cb instanceof TextOutputCallback) {
            // Not implementing this one yet...
        } else if(cb instanceof NameCallback) {
            NameCallback nc=(NameCallback)cb;
            nc.setName(username);
        } else if(cb instanceof PasswordCallback) {
            PasswordCallback pc=(PasswordCallback)cb;
            pc.setPassword(password);
        } else {
            throw new UnsupportedCallbackException(cb);
        }
    }
}
项目:freeVM    文件:TextOutputCallbackTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertTrue(test instanceof TextOutputCallback);
    assertEquals(((TextOutputCallback) golden).getMessage(),
            ((TextOutputCallback) test).getMessage());
    assertEquals(((TextOutputCallback) golden).getMessageType(),
            ((TextOutputCallback) test).getMessageType());

}
项目:ditb    文件:TestHBaseSaslRpcClient.java   
@Test
public void testSaslClientCallbackHandlerWithException() {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
  when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());
  final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
  try {
    saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
  } catch (UnsupportedCallbackException expEx) {
    //expected
  } catch (Exception ex) {
    fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage());
  }
}
项目:javify    文件:KeyCloneCmd.java   
private boolean prompt4NewPassword(CallbackHandler handler,
                                   Callback[] prompts, Callback[] errors)
    throws IOException, UnsupportedCallbackException
{
  String p = Messages.getFormattedString("KeyCloneCmd.28", //$NON-NLS-1$
                                         new String[] { destinationAlias,
                                                        String.valueOf(keyPasswordChars) });
  PasswordCallback pcb = new PasswordCallback(p, false);
  prompts[0] = pcb;
  handler.handle(prompts);
  char[] pwd1 = pcb.getPassword();
  pcb.clearPassword();
  if (pwd1 == null || pwd1.length == 0)
    {
      newKeyPasswordChars = (char[]) keyPasswordChars.clone();
      return true;
    }

  if (pwd1.length < 6)
    {
      errors[0] = new TextOutputCallback(TextOutputCallback.ERROR,
                                         Messages.getString("StorePasswdCmd.21")); //$NON-NLS-1$
      handler.handle(errors);
      return false;
    }

  newKeyPasswordChars = pwd1;
  return true;
}
项目: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    文件:AWTCallbackHandler.java   
protected synchronized void handleTextOutput(TextOutputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setLayout(new GridLayout(2, 1));
  switch (c.getMessageType() /*c.getStyle()*/)
    {
    case ConfirmationCallback.ERROR:
      dialog.setTitle(messages.getString("callback.error"));
      break;
    case ConfirmationCallback.INFORMATION:
      dialog.setTitle(messages.getString("callback.information"));
      break;
    case ConfirmationCallback.WARNING:
      dialog.setTitle(messages.getString("callback.warning"));
      break;
    default:
      dialog.setTitle("");
    }
  Label label = new Label(c.getMessage());
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  ok.addActionListener(this);
  dialog.add(label);
  dialog.add(buttons);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:impersonation-policy    文件:ImpersonationModule.java   
private void customizeCallbacks(int state, String msg) throws AuthLoginException {
    switch (state) {

        case STATE_ERROR: {
            TextOutputCallback toc = new TextOutputCallback(TextOutputCallback.ERROR, "Impersonation failed");
            replaceCallback(STATE_ERROR, 0, toc);
            break;
        }

        default:
    }
}
项目:jvm-stm    文件:KeyCloneCmd.java   
private boolean prompt4NewPassword(CallbackHandler handler,
                                   Callback[] prompts, Callback[] errors)
    throws IOException, UnsupportedCallbackException
{
  String p = Messages.getFormattedString("KeyCloneCmd.28", //$NON-NLS-1$
                                         new String[] { destinationAlias,
                                                        String.valueOf(keyPasswordChars) });
  PasswordCallback pcb = new PasswordCallback(p, false);
  prompts[0] = pcb;
  handler.handle(prompts);
  char[] pwd1 = pcb.getPassword();
  pcb.clearPassword();
  if (pwd1 == null || pwd1.length == 0)
    {
      newKeyPasswordChars = (char[]) keyPasswordChars.clone();
      return true;
    }

  if (pwd1.length < 6)
    {
      errors[0] = new TextOutputCallback(TextOutputCallback.ERROR,
                                         Messages.getString("StorePasswdCmd.21")); //$NON-NLS-1$
      handler.handle(errors);
      return false;
    }

  newKeyPasswordChars = pwd1;
  return true;
}
项目: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    文件:AWTCallbackHandler.java   
protected synchronized void handleTextOutput(TextOutputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setLayout(new GridLayout(2, 1));
  switch (c.getMessageType() /*c.getStyle()*/)
    {
    case ConfirmationCallback.ERROR:
      dialog.setTitle(messages.getString("callback.error"));
      break;
    case ConfirmationCallback.INFORMATION:
      dialog.setTitle(messages.getString("callback.information"));
      break;
    case ConfirmationCallback.WARNING:
      dialog.setTitle(messages.getString("callback.warning"));
      break;
    default:
      dialog.setTitle("");
    }
  Label label = new Label(c.getMessage());
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  ok.addActionListener(this);
  dialog.add(label);
  dialog.add(buttons);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:pbase    文件:TestHBaseSaslRpcClient.java   
@Test
public void testSaslClientCallbackHandlerWithException() {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
  when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());
  final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
  try {
    saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
  } catch (UnsupportedCallbackException expEx) {
    //expected
  } catch (Exception ex) {
    fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage());
  }
}
项目:HIndex    文件:TestHBaseSaslRpcClient.java   
@Test
public void testSaslClientCallbackHandlerWithException() {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
  when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());
  final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
  try {
    saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
  } catch (UnsupportedCallbackException expEx) {
    //expected
  } catch (Exception ex) {
    fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage());
  }
}
项目:jspresso-ce    文件:DevelopmentLoginModule.java   
/**
 * <p>
 * This method is called if the LoginContext's overall authentication failed.
 * (the relevant REQUIRED, REQUISITE, SUFFICIENT and OPTIONAL LoginModules did
 * not succeed).
 * <p>
 * If this LoginModule's own authentication attempt succeeded (checked by
 * retrieving the private state saved by the {@code login} and
 * {@code commit} methods), then this method cleans up any state that was
 * originally saved.
 * <p>
 *
 * @return false if this LoginModule's own login and/or commit attempts
 *         failed, and true otherwise.
 */
@Override
public boolean abort() {
  if (!succeeded) {
    Callback[] callbacks = new Callback[1];
    callbacks[0] = new TextOutputCallback(TextOutputCallback.ERROR,
        LoginUtils.LOGIN_FAILED);
    try {
      callbackHandler.handle(callbacks);
    } catch (IOException | UnsupportedCallbackException ex) {
      // NO-OP.
    }
    return false;
  }
  if (!commitSucceeded) {
    // login succeeded but overall authentication failed
    succeeded = false;
    username = null;
    suffix = "";
    if (password != null) {
      for (int i = 0; i < password.length; i++) {
        password[i] = ' ';
      }
      password = null;
    }
    userPrincipal = null;
  } else {
    // overall authentication succeeded and commit succeeded,
    // but someone else's commit failed
    logout();
  }
  return true;
}
项目:jspresso-ce    文件:DialogCallbackHandler.java   
private Icon getIcon(TextOutputCallback callback)
    throws UnsupportedCallbackException {
  switch (callback.getMessageType()) {
    case TextOutputCallback.INFORMATION:
      return iconFactory.getInfoIcon(iconFactory.getSmallIconSize());
    case TextOutputCallback.WARNING:
      return iconFactory.getWarningIcon(iconFactory.getSmallIconSize());
    case TextOutputCallback.ERROR:
      return iconFactory.getErrorIcon(iconFactory.getSmallIconSize());
    default:
      throw new UnsupportedCallbackException(callback,
          "Unrecognized message type");
  }
}
项目:jspresso-ce    文件:DialogCallbackHandler.java   
private void processTextOutputCallback(JPanel messagePanel,
    TextOutputCallback toc) throws UnsupportedCallbackException {
  JLabel messageLabel = new JLabel(translationProvider.getTranslation(
      toc.getMessage(), locale), getIcon(toc), SwingConstants.LEADING);
  GridBagConstraints constraints = new GridBagConstraints();
  constraints.insets = DEFAULT_INSETS;
  constraints.gridx = GridBagConstraints.RELATIVE;
  constraints.gridy = GridBagConstraints.RELATIVE;
  constraints.gridwidth = GridBagConstraints.REMAINDER;
  constraints.weightx = 1.0d;
  constraints.fill = GridBagConstraints.HORIZONTAL;
  messagePanel.add(messageLabel, constraints);
}
项目:hbase    文件:TestHBaseSaslRpcClient.java   
@Test
public void testSaslClientCallbackHandlerWithException() {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(Bytes.toBytes(DEFAULT_USER_NAME));
  when(token.getPassword()).thenReturn(Bytes.toBytes(DEFAULT_USER_PASSWORD));
  final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
  try {
    saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
  } catch (UnsupportedCallbackException expEx) {
    //expected
  } catch (Exception ex) {
    fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage());
  }
}
项目:cn1    文件:Sasl3Test.java   
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback element : callbacks) {
        if (element instanceof TextOutputCallback) {
            TextOutputCallback toc = (TextOutputCallback) element;
            if (toc.getMessageType() != TextOutputCallback.INFORMATION) {
                throw new IOException("Unsupported message type: "
                        + toc.getMessageType());
            }
        } else {
            throw new UnsupportedCallbackException(element,
                    "Callback should be TextOutputCallback");
        }
    }
}
项目:cn1    文件:TextOutputCallbackTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertTrue(test instanceof TextOutputCallback);
    assertEquals(((TextOutputCallback) golden).getMessage(),
            ((TextOutputCallback) test).getMessage());
    assertEquals(((TextOutputCallback) golden).getMessageType(),
            ((TextOutputCallback) test).getMessageType());

}
项目:cn1    文件:TextOutputCallbackTest.java   
/**
 * Test for TextOutputCallback(int msgType,String msg) ctor 
 */
public final void testTextOutputCallback_02() {
    int[] m = { TextOutputCallback.INFORMATION, TextOutputCallback.WARNING,
            TextOutputCallback.ERROR };
    for (int i = 0; i < m.length; i++) {
        text = new TextOutputCallback(m[i], "message");
    }
}
项目:cn1    文件:TextOutputCallbackTest.java   
/**
 * Test for TextOutputCallback(int msgType,String msg) ctor, 
 * if mgsType is not INFORMATION, WARNING or ERROR, then expected IAE 
 */
public final void testTextOutputCallback_03() {
    try {
        text = new TextOutputCallback(5, "message");
        fail("messageType should be either INFORMATION, WARNING or ERROR");
    } catch (IllegalArgumentException e) {
    }
}
项目:PyroDB    文件:TestHBaseSaslRpcClient.java   
@Test
public void testSaslClientCallbackHandlerWithException() {
  final Token<? extends TokenIdentifier> token = createTokenMock();
  when(token.getIdentifier()).thenReturn(DEFAULT_USER_NAME.getBytes());
  when(token.getPassword()).thenReturn(DEFAULT_USER_PASSWORD.getBytes());
  final SaslClientCallbackHandler saslClCallbackHandler = new SaslClientCallbackHandler(token);
  try {
    saslClCallbackHandler.handle(new Callback[] { mock(TextOutputCallback.class) });
  } catch (UnsupportedCallbackException expEx) {
    //expected
  } catch (Exception ex) {
    fail("testSaslClientCallbackHandlerWithException error : " + ex.getMessage());
  }
}
项目:JamVM-PH    文件:KeyCloneCmd.java   
private boolean prompt4NewPassword(CallbackHandler handler,
                                   Callback[] prompts, Callback[] errors)
    throws IOException, UnsupportedCallbackException
{
  String p = Messages.getFormattedString("KeyCloneCmd.28", //$NON-NLS-1$
                                         new String[] { destinationAlias,
                                                        String.valueOf(keyPasswordChars) });
  PasswordCallback pcb = new PasswordCallback(p, false);
  prompts[0] = pcb;
  handler.handle(prompts);
  char[] pwd1 = pcb.getPassword();
  pcb.clearPassword();
  if (pwd1 == null || pwd1.length == 0)
    {
      newKeyPasswordChars = (char[]) keyPasswordChars.clone();
      return true;
    }

  if (pwd1.length < 6)
    {
      errors[0] = new TextOutputCallback(TextOutputCallback.ERROR,
                                         Messages.getString("StorePasswdCmd.21")); //$NON-NLS-1$
      handler.handle(errors);
      return false;
    }

  newKeyPasswordChars = pwd1;
  return true;
}
项目: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    文件:AWTCallbackHandler.java   
protected synchronized void handleTextOutput(TextOutputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setLayout(new GridLayout(2, 1));
  switch (c.getMessageType() /*c.getStyle()*/)
    {
    case ConfirmationCallback.ERROR:
      dialog.setTitle(messages.getString("callback.error"));
      break;
    case ConfirmationCallback.INFORMATION:
      dialog.setTitle(messages.getString("callback.information"));
      break;
    case ConfirmationCallback.WARNING:
      dialog.setTitle(messages.getString("callback.warning"));
      break;
    default:
      dialog.setTitle("");
    }
  Label label = new Label(c.getMessage());
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  ok.addActionListener(this);
  dialog.add(label);
  dialog.add(buttons);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:classpath    文件:KeyCloneCmd.java   
private boolean prompt4NewPassword(CallbackHandler handler,
                                   Callback[] prompts, Callback[] errors)
    throws IOException, UnsupportedCallbackException
{
  String p = Messages.getFormattedString("KeyCloneCmd.28", //$NON-NLS-1$
                                         new String[] { destinationAlias,
                                                        String.valueOf(keyPasswordChars) });
  PasswordCallback pcb = new PasswordCallback(p, false);
  prompts[0] = pcb;
  handler.handle(prompts);
  char[] pwd1 = pcb.getPassword();
  pcb.clearPassword();
  if (pwd1 == null || pwd1.length == 0)
    {
      newKeyPasswordChars = (char[]) keyPasswordChars.clone();
      return true;
    }

  if (pwd1.length < 6)
    {
      errors[0] = new TextOutputCallback(TextOutputCallback.ERROR,
                                         Messages.getString("StorePasswdCmd.21")); //$NON-NLS-1$
      handler.handle(errors);
      return false;
    }

  newKeyPasswordChars = pwd1;
  return true;
}
项目: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    文件:AWTCallbackHandler.java   
protected synchronized void handleTextOutput(TextOutputCallback c)
{
  Frame ownerFrame = new Frame();
  Dialog dialog = new Dialog(ownerFrame);
  dialog.setLayout(new GridLayout(2, 1));
  switch (c.getMessageType() /*c.getStyle()*/)
    {
    case ConfirmationCallback.ERROR:
      dialog.setTitle(messages.getString("callback.error"));
      break;
    case ConfirmationCallback.INFORMATION:
      dialog.setTitle(messages.getString("callback.information"));
      break;
    case ConfirmationCallback.WARNING:
      dialog.setTitle(messages.getString("callback.warning"));
      break;
    default:
      dialog.setTitle("");
    }
  Label label = new Label(c.getMessage());
  Panel buttons = new Panel();
  Button ok = new Button(messages.getString("callback.ok"));
  buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
  buttons.add(ok);
  ok.addActionListener(this);
  dialog.add(label);
  dialog.add(buttons);
  dialog.pack();
  dialog.show();
  try { wait(); }
  catch (InterruptedException ie) { }
  dialog.dispose();
  ownerFrame.dispose();
}
项目:freeVM    文件:Sasl3Test.java   
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback element : callbacks) {
        if (element instanceof TextOutputCallback) {
            TextOutputCallback toc = (TextOutputCallback) element;
            if (toc.getMessageType() != TextOutputCallback.INFORMATION) {
                throw new IOException("Unsupported message type: "
                        + toc.getMessageType());
            }
        } else {
            throw new UnsupportedCallbackException(element,
                    "Callback should be TextOutputCallback");
        }
    }
}
项目:freeVM    文件:TextOutputCallbackTest.java   
public void assertDeserialized(Serializable golden, Serializable test) {
    assertTrue(test instanceof TextOutputCallback);
    assertEquals(((TextOutputCallback) golden).getMessage(),
            ((TextOutputCallback) test).getMessage());
    assertEquals(((TextOutputCallback) golden).getMessageType(),
            ((TextOutputCallback) test).getMessageType());

}
项目:freeVM    文件:TextOutputCallbackTest.java   
/**
 * Test for TextOutputCallback(int msgType,String msg) ctor 
 */
public final void testTextOutputCallback_02() {
    int[] m = { TextOutputCallback.INFORMATION, TextOutputCallback.WARNING,
            TextOutputCallback.ERROR };
    for (int i = 0; i < m.length; i++) {
        text = new TextOutputCallback(m[i], "message");
    }
}
项目:freeVM    文件:TextOutputCallbackTest.java   
/**
 * Test for TextOutputCallback(int msgType,String msg) ctor, 
 * if mgsType is not INFORMATION, WARNING or ERROR, then expected IAE 
 */
public final void testTextOutputCallback_03() {
    try {
        text = new TextOutputCallback(5, "message");
        fail("messageType should be either INFORMATION, WARNING or ERROR");
    } catch (IllegalArgumentException e) {
    }
}
项目:freeVM    文件:Sasl3Test.java   
public void handle(Callback[] callbacks) throws IOException,
        UnsupportedCallbackException {
    for (Callback element : callbacks) {
        if (element instanceof TextOutputCallback) {
            TextOutputCallback toc = (TextOutputCallback) element;
            if (toc.getMessageType() != TextOutputCallback.INFORMATION) {
                throw new IOException("Unsupported message type: "
                        + toc.getMessageType());
            }
        } else {
            throw new UnsupportedCallbackException(element,
                    "Callback should be TextOutputCallback");
        }
    }
}