CallbackHandler.java 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. package javax.security.auth.callback;
  18. import java.io.IOException;
  19. /**
  20. * Needs to be implemented by classes that want to handle authentication
  21. * {@link Callback}s. A single method {@link #handle(Callback[])} must be
  22. * provided that checks the type of the incoming {@code Callback}s and reacts
  23. * accordingly. {@code CallbackHandler}s can be installed per application. It is
  24. * also possible to configure a system-default {@code CallbackHandler} by
  25. * setting the {@code auth.login.defaultCallbackHandler} property in the
  26. * standard {@code security.properties} file.
  27. */
  28. public interface CallbackHandler {
  29. /**
  30. * Handles the actual {@link Callback}. A {@code CallbackHandler} needs to
  31. * implement this method. In the method, it is free to select which {@code
  32. * Callback}s it actually wants to handle and in which way. For example, a
  33. * console-based {@code CallbackHandler} might choose to sequentially ask
  34. * the user for login and password, if it implements these {@code Callback}
  35. * s, whereas a GUI-based one might open a single dialog window for both
  36. * values. If a {@code CallbackHandler} is not able to handle a specific
  37. * {@code Callback}, it needs to throw an
  38. * {@link UnsupportedCallbackException}.
  39. *
  40. * @param callbacks
  41. * the array of {@code Callback}s that need handling
  42. * @throws IOException
  43. * if an I/O related error occurs
  44. * @throws UnsupportedCallbackException
  45. * if the {@code CallbackHandler} is not able to handle a
  46. * specific {@code Callback}
  47. */
  48. void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException;
  49. }