Source Code Cross Referenced for SudoPanel.java in  » Installer » IzPack » com » izforge » izpack » panels » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Installer » IzPack » com.izforge.izpack.panels 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * IzPack - Copyright 2001-2008 Julien Ponge, All Rights Reserved.
003:         * 
004:         * http://izpack.org/
005:         * http://izpack.codehaus.org/
006:         * 
007:         * Copyright 2003 Jan Blok
008:         * 
009:         * Licensed under the Apache License, Version 2.0 (the "License");
010:         * you may not use this file except in compliance with the License.
011:         * You may obtain a copy of the License at
012:         * 
013:         *     http://www.apache.org/licenses/LICENSE-2.0
014:         *     
015:         * Unless required by applicable law or agreed to in writing, software
016:         * distributed under the License is distributed on an "AS IS" BASIS,
017:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018:         * See the License for the specific language governing permissions and
019:         * limitations under the License.
020:         */
021:
022:        package com.izforge.izpack.panels;
023:
024:        import java.awt.BorderLayout;
025:        import java.awt.Dimension;
026:        import java.awt.event.ActionEvent;
027:        import java.awt.event.ActionListener;
028:        import java.io.File;
029:        import java.io.FileOutputStream;
030:        import java.util.ArrayList;
031:        import java.util.List;
032:        import java.util.Properties;
033:
034:        import javax.swing.BorderFactory;
035:        import javax.swing.Box;
036:        import javax.swing.BoxLayout;
037:        import javax.swing.JLabel;
038:        import javax.swing.JOptionPane;
039:        import javax.swing.JPanel;
040:        import javax.swing.JPasswordField;
041:        import javax.swing.JTextField;
042:
043:        import com.izforge.izpack.ExecutableFile;
044:        import com.izforge.izpack.ParsableFile;
045:        import com.izforge.izpack.gui.LabelFactory;
046:        import com.izforge.izpack.installer.InstallData;
047:        import com.izforge.izpack.installer.InstallerFrame;
048:        import com.izforge.izpack.installer.IzPanel;
049:        import com.izforge.izpack.installer.ScriptParser;
050:        import com.izforge.izpack.util.FileExecutor;
051:        import com.izforge.izpack.util.OsConstraint;
052:        import com.izforge.izpack.util.VariableSubstitutor;
053:
054:        /**
055:         * The packs selection panel class.
056:         * 
057:         * @author Jan Blok
058:         * @since November 27, 2003
059:         */
060:        public class SudoPanel extends IzPanel implements  ActionListener {
061:
062:            /**
063:             * 
064:             */
065:            private static final long serialVersionUID = 3689628116465561651L;
066:
067:            private JTextField passwordField;
068:
069:            private boolean isValid = false;
070:
071:            /**
072:             * The constructor.
073:             * 
074:             * @param parent The parent window.
075:             * @param idata The installation data.
076:             */
077:            public SudoPanel(InstallerFrame parent, InstallData idata) {
078:                super (parent, idata);
079:
080:                setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
081:
082:                add(LabelFactory
083:                        .create(
084:                                /* parent.langpack.getString("SudoPanel.info") */"For installing administrator privileges are necessary",
085:                                JLabel.TRAILING));
086:
087:                add(Box.createRigidArea(new Dimension(0, 5)));
088:
089:                add(LabelFactory
090:                        .create(
091:                                /* parent.langpack.getString("SudoPanel.tip") */"Please note that passwords are case-sensitive",
092:                                parent.icons.getImageIcon("tip"),
093:                                JLabel.TRAILING));
094:
095:                add(Box.createRigidArea(new Dimension(0, 5)));
096:
097:                JPanel spacePanel = new JPanel();
098:                spacePanel.setAlignmentX(LEFT_ALIGNMENT);
099:                spacePanel.setAlignmentY(CENTER_ALIGNMENT);
100:                spacePanel.setBorder(BorderFactory.createEmptyBorder(80, 30, 0,
101:                        50));
102:                spacePanel.setLayout(new BorderLayout(5, 5));
103:                spacePanel
104:                        .add(
105:                                LabelFactory
106:                                        .create(
107:                                        /* parent.langpack.getString("SudoPanel.specifyAdminPassword") */"Please specify your password:"),
108:                                BorderLayout.NORTH);
109:                passwordField = new JPasswordField();
110:                passwordField.addActionListener(this );
111:                JPanel space2Panel = new JPanel();
112:                space2Panel.setLayout(new BorderLayout());
113:                space2Panel.add(passwordField, BorderLayout.NORTH);
114:                space2Panel.add(Box.createRigidArea(new Dimension(0, 5)),
115:                        BorderLayout.CENTER);
116:                spacePanel.add(space2Panel, BorderLayout.CENTER);
117:                add(spacePanel);
118:            }
119:
120:            /** Called when the panel becomes active. */
121:            public void panelActivate() {
122:                passwordField.requestFocus();
123:            }
124:
125:            /**
126:             * Actions-handling method.
127:             * 
128:             * @param e The event.
129:             */
130:            public void actionPerformed(ActionEvent e) {
131:                doSudoCmd();
132:            }
133:
134:            // check if sudo password is correct (so sudo can be used in all other
135:            // scripts, even without password, lasts for 5 minutes)
136:            private void doSudoCmd() {
137:                String pass = passwordField.getText();
138:
139:                File file = null;
140:                try {
141:                    // write file in /tmp
142:                    file = new File("/tmp/cmd_sudo.sh");// ""c:/temp/run.bat""
143:                    FileOutputStream fos = new FileOutputStream(file);
144:                    fos
145:                            .write("echo $password | sudo -S ls\nexit $?"
146:                                    .getBytes()); // "echo
147:                    // $password
148:                    // >
149:                    // pipo.txt"
150:                    fos.close();
151:
152:                    // execute
153:                    Properties vars = new Properties();
154:                    vars.put("password", pass);
155:
156:                    List<OsConstraint> oses = new ArrayList<OsConstraint>();
157:                    oses.add(new OsConstraint("unix", null, null, null));
158:
159:                    ArrayList<ParsableFile> plist = new ArrayList<ParsableFile>();
160:                    ParsableFile pf = new ParsableFile(file.getAbsolutePath(),
161:                            null, null, oses);
162:                    plist.add(pf);
163:                    ScriptParser sp = new ScriptParser(plist,
164:                            new VariableSubstitutor(vars));
165:                    sp.parseFiles();
166:
167:                    ArrayList<ExecutableFile> elist = new ArrayList<ExecutableFile>();
168:                    ExecutableFile ef = new ExecutableFile(file
169:                            .getAbsolutePath(), ExecutableFile.POSTINSTALL,
170:                            ExecutableFile.ABORT, oses, false);
171:                    elist.add(ef);
172:                    FileExecutor fe = new FileExecutor(elist);
173:                    int retval = fe.executeFiles(ExecutableFile.POSTINSTALL,
174:                            this );
175:                    if (retval == 0) {
176:                        idata.setVariable("password", pass);
177:                        isValid = true;
178:                    }
179:                    // else is already showing dialog
180:                    // {
181:                    // JOptionPane.showMessageDialog(this, "Cannot execute 'sudo' cmd,
182:                    // check your password", "Error", JOptionPane.ERROR_MESSAGE);
183:                    // }
184:                } catch (Exception e) {
185:                    // JOptionPane.showMessageDialog(this, "Cannot execute 'sudo' cmd,
186:                    // check your password", "Error", JOptionPane.ERROR_MESSAGE);
187:                    e.printStackTrace();
188:                    isValid = false;
189:                }
190:                try {
191:                    if (file != null && file.exists())
192:                        file.delete();// you don't
193:                    // want the file
194:                    // with password
195:                    // tobe arround,
196:                    // in case of
197:                    // error
198:                } catch (Exception e) {
199:                    // ignore
200:                }
201:            }
202:
203:            /**
204:             * Indicates wether the panel has been validated or not.
205:             * 
206:             * @return Always true.
207:             */
208:            public boolean isValidated() {
209:                if (!isValid) {
210:                    doSudoCmd();
211:                }
212:                if (!isValid) {
213:                    JOptionPane.showInternalMessageDialog(this , "Password",
214:                            "Password is not valid", JOptionPane.ERROR_MESSAGE);
215:                }
216:                return isValid;
217:            }
218:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.