Shuyi Chen | d7955ce | 2013-05-22 14:51:55 -0700 | [diff] [blame] | 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 | |
| 18 | package org.apache.harmony.javax.security.auth.callback; |
| 19 | |
| 20 | import java.io.IOException; |
| 21 | |
| 22 | /** |
| 23 | * Needs to be implemented by classes that want to handle authentication |
| 24 | * {@link Callback}s. A single method {@link #handle(Callback[])} must be |
| 25 | * provided that checks the type of the incoming {@code Callback}s and reacts |
| 26 | * accordingly. {@code CallbackHandler}s can be installed per application. It is |
| 27 | * also possible to configure a system-default {@code CallbackHandler} by |
| 28 | * setting the {@code auth.login.defaultCallbackHandler} property in the |
| 29 | * standard {@code security.properties} file. |
| 30 | */ |
| 31 | public interface CallbackHandler { |
| 32 | |
| 33 | /** |
| 34 | * Handles the actual {@link Callback}. A {@code CallbackHandler} needs to |
| 35 | * implement this method. In the method, it is free to select which {@code |
| 36 | * Callback}s it actually wants to handle and in which way. For example, a |
| 37 | * console-based {@code CallbackHandler} might choose to sequentially ask |
| 38 | * the user for login and password, if it implements these {@code Callback} |
| 39 | * s, whereas a GUI-based one might open a single dialog window for both |
| 40 | * values. If a {@code CallbackHandler} is not able to handle a specific |
| 41 | * {@code Callback}, it needs to throw an |
| 42 | * {@link UnsupportedCallbackException}. |
| 43 | * |
| 44 | * @param callbacks |
| 45 | * the array of {@code Callback}s that need handling |
| 46 | * @throws IOException |
| 47 | * if an I/O related error occurs |
| 48 | * @throws UnsupportedCallbackException |
| 49 | * if the {@code CallbackHandler} is not able to handle a |
| 50 | * specific {@code Callback} |
| 51 | */ |
| 52 | void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException; |
| 53 | |
| 54 | } |