risdenk commented on a change in pull request #231: KNOX-2128 - Custom DataSource and SQL Commands for KnoxShell and KnoxShellTable URL: https://github.com/apache/knox/pull/231#discussion_r363334971
########## File path: gateway-shell/src/main/java/org/apache/knox/gateway/shell/commands/KnoxLoginDialog.java ########## @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.knox.gateway.shell.commands; + +import java.awt.Component; +import java.awt.Window; +import java.awt.event.HierarchyEvent; +import java.awt.event.HierarchyListener; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import javax.swing.Box; +import javax.swing.JLabel; +import javax.swing.JOptionPane; +import javax.swing.JPasswordField; +import javax.swing.JTextField; +import javax.swing.SwingUtilities; + +import org.apache.knox.gateway.shell.CredentialCollectionException; +import org.apache.knox.gateway.shell.CredentialCollector; + +public class KnoxLoginDialog implements CredentialCollector { + public static final String COLLECTOR_TYPE = "LoginDialog"; + + public char[] pass; + public String username; + String name; + public boolean ok; + + @Override + public void collect() throws CredentialCollectionException { + JLabel jl = new JLabel("Enter Your username: "); + JTextField juf = new JTextField(24); + JLabel jl2 = new JLabel("Enter Your password: "); + JPasswordField jpf = new JPasswordField(24); + Box box1 = Box.createHorizontalBox(); + box1.add(jl); + box1.add(juf); + Box box2 = Box.createHorizontalBox(); + box2.add(jl2); + box2.add(jpf); + Box box = Box.createVerticalBox(); + box.add(box1); + box.add(box2); + + // JDK-5018574 : Unable to set focus to another component in JOptionPane + workAroundFocusIssue(juf); + + int x = JOptionPane.showConfirmDialog(null, box, + "KnoxShell Login", JOptionPane.OK_CANCEL_OPTION); + + if (x == JOptionPane.OK_OPTION) { + ok = true; + username = juf.getText(); + pass = jpf.getPassword(); + } + } + + @Override + public String string() { + return new String(pass); + } + + @Override + public char[] chars() { + return pass; + } + + @Override + public byte[] bytes() { + return null; + } + + @Override + public String type() { + return "dialog"; + } + + @Override + public String name() { + return name; + } + + @Override + public void setPrompt(String prompt) { + } + + @Override + public void setName(String name) { + this.name = name; + } + + private void workAroundFocusIssue(JTextField field) { Review comment: Can a comment be added to this method on what the workaround is for? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
