01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: * @author Igor A. Pyankov
19: * @version $Revision: 1.2 $
20: */package org.apache.harmony.x.print.ipp.util;
21:
22: import java.awt.GridLayout;
23: import java.net.Authenticator;
24: import java.net.PasswordAuthentication;
25:
26: import javax.swing.JLabel;
27: import javax.swing.JOptionPane;
28: import javax.swing.JPanel;
29: import javax.swing.JPasswordField;
30: import javax.swing.JTextField;
31:
32: public class IppHttpAuthenticator extends Authenticator {
33: protected PasswordAuthentication getPasswordAuthentication() {
34: JTextField username = new JTextField();
35: JTextField password = new JPasswordField();
36: JPanel panel = new JPanel(new GridLayout(2, 2));
37:
38: panel.add(new JLabel("username"));
39: panel.add(username);
40: panel.add(new JLabel("password"));
41: panel.add(password);
42:
43: int option = JOptionPane
44: .showConfirmDialog(null, new Object[] {
45: "Site: " + getRequestingHost(),
46: "Realm: " + getRequestingPrompt(), panel },
47: "Enter Username and Password",
48: JOptionPane.OK_CANCEL_OPTION,
49: JOptionPane.PLAIN_MESSAGE);
50:
51: if (option == JOptionPane.OK_OPTION) {
52: String user = username.getText();
53: char pass[] = password.getText().toCharArray();
54:
55: return new PasswordAuthentication(user, pass);
56: }
57: return null;
58: }
59:
60: }
|