KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > security > impl > mock > MockCallbackHandler


1 /*
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5
6 package org.exoplatform.services.security.impl.mock;
7
8
9 import javax.security.auth.Subject JavaDoc;
10 import javax.security.auth.callback.*;
11
12 import java.io.IOException JavaDoc;
13 import java.security.Principal JavaDoc;
14 import java.security.acl.Group JavaDoc;
15
16 public class MockCallbackHandler implements CallbackHandler {
17   private String JavaDoc login;
18   private char[] password;
19
20   public MockCallbackHandler(String JavaDoc login, String JavaDoc password) {
21     this.login = login;
22     this.password = password.toCharArray();
23   }
24
25   public MockCallbackHandler(String JavaDoc login, char[] password) {
26     this.login = login;
27     this.password = password;
28   }
29
30   public void handle(Callback[] callbacks)
31       throws IOException JavaDoc, 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