@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()); } } }
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()); } }
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()); } }
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); } }
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); } } }
@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"); } } }
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); } } }
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()); }
@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()); } }
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; }
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]); } }
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(); }
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: } }
/** * <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; }
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"); } }
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); }
@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()); } }
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"); } } }
/** * 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"); } }
/** * 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) { } }