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