/*
 *  Copyright 2011-2012 Rudolf Biczok
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.pamther.internal.nativelib.types;

import javax.security.auth.callback.Callback;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;

import org.pamther.internal.nativelib.MsgStyle;
import org.pamther.jaas.NewPasswordCallback;

/**
 * This is the place where incoming PAM messages gets dispatched and transformed
 * into {@link Callback} instances.
 * 
 * @author <a href="https://bitbucket.org/RCBiczok">Rudolf Biczok</a>
 */
class MessageDispatcher {

	/**
	 * Transforms the given message into a {@link Callback}.
	 * 
	 * @param message
	 *            the message returned by PAM module.
	 * @param type
	 *            the PAM message type returned by the PAM module.
	 * @return the {@link Callback} equivalent of the given message.
	 */
	Callback dispatch(final String message, final int type) {

		Callback callback = null;

		if (message.equals("Password: ")) {
			callback = new PasswordCallback(message,
					type == MsgStyle.PAM_PROMPT_ECHO_ON.getCode());
		} else if (message.equals("Enter new UNIX password: ")
				|| message.equals("Retype new UNIX password: ")) {
			callback = new NewPasswordCallback(message,
					type == MsgStyle.PAM_PROMPT_ECHO_ON.getCode());
		} else if (message.equals("login: ")) {
			callback = new NameCallback(message);
		}

		return callback;
	}
}

@@ -801,16 +801,72 @@
 allback;
+%0Aimport javax.security.auth.callback.TextOutputCallback;
 %0A%0Aimport
@@ -1752,17 +1752,19 @@
 : %22)%0A%09%09%09
-%09
+   
 %7C%7C messa
@@ -1791,32 +1791,113 @@
 w UNIX password:
+ %22) %7C%7C message.equals(%22New Password: %22) %7C%7C message.equals(%22Re-enter new Password:
  %22)) %7B%0A%09%09%09callba
@@ -2021,32 +2021,32 @@
 s(%22login: %22)) %7B%0A
-
 %09%09%09callback = ne
@@ -2073,16 +2073,288 @@
 ge);%0A%09%09%7D
+ else if (type == MsgStyle.PAM_ERROR_MSG.getCode()) %7B%0A%09%09    callback = new TextOutputCallback(TextOutputCallback.ERROR, message);%0A%09%09%7D else if (type == MsgStyle.PAM_TEXT_INFO.getCode()) %7B%0A%09%09    callback = new TextOutputCallback(TextOutputCallback.INFORMATION, message);%0A%09%09%7D
 %0A%0A%09%09retu

Use NewPasswordCallback to determin needed information instead of comparing the messages itself