1 5 6 package org.exoplatform.services.security.impl.mock; 7 8 9 import javax.security.auth.Subject ; 10 import javax.security.auth.callback.*; 11 12 import java.io.IOException ; 13 import java.security.Principal ; 14 import java.security.acl.Group ; 15 16 public class MockCallbackHandler implements CallbackHandler { 17 private String login; 18 private char[] password; 19 20 public MockCallbackHandler(String login, String password) { 21 this.login = login; 22 this.password = password.toCharArray(); 23 } 24 25 public MockCallbackHandler(String login, char[] password) { 26 this.login = login; 27 this.password = password; 28 } 29 30 public void handle(Callback[] callbacks) 31 throws IOException , UnsupportedCallbackException { 32 for (int i = 0; i < callbacks.length; i++) { 33 if (callbacks[i] instanceof NameCallback) { 34 ((NameCallback) callbacks[i]).setName(login); 35 } else if (callbacks[i] instanceof PasswordCallback) { 36 ((PasswordCallback) callbacks[i]).setPassword(password); 37 } else { 38 throw new UnsupportedCallbackException(callbacks[i], "Callback class not supported"); 39 } 40 } 41 } 42 } 43 44 45 | Popular Tags |