1 /* 2 * Copyright (C) 2003-2005 SINTEF 3 * Author: fredrik dot vraalsen at sintef dot no 4 * Webpage: http://coras.sourceforge.net/ 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU Lesser General Public License 8 * as published by the Free Software Foundation; either version 2.1 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 * Lesser General Public License for more details. 15 * 16 * You should have received a copy of the GNU Lesser General Public 17 * License along with this program; if not, write to the Free 18 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 19 * 02111-1307 USA 20 */ 21 package no.sintef.assetrepository.admin; 22 23 import java.net.URL; 24 import java.rmi.RemoteException; 25 26 import javax.ejb.CreateException; 27 import javax.naming.NamingException; 28 import javax.security.auth.login.LoginContext; 29 import javax.security.auth.login.LoginException; 30 import javax.swing.JFrame; 31 import javax.swing.JOptionPane; 32 33 import no.sintef.assetrepository.interfaces.AssetServices; 34 import no.sintef.assetrepository.interfaces.AssetServicesUtil; 35 import no.sintef.assetrepository.interfaces.AssetTypeValue; 36 37 /*** 38 * @author fvr 39 * 40 * TODO To change the template for this generated type comment go to 41 * Window - Preferences - Java - Code Style - Code Templates 42 */ 43 public class AdminUIold extends JFrame { 44 45 public static void main(String[] args) { 46 URL authURL = AdminUIold.class.getClassLoader().getResource("auth.conf"); 47 String authLocation = (authURL != null ? authURL.toString() : "auth.conf"); 48 System.setProperty("java.security.auth.login.config", authLocation); 49 50 AdminUIold ui = new AdminUIold("AssetRepository Admin UI"); 51 ui.login(); 52 ui.doStuff(); 53 } 54 55 /*** 56 * @param string 57 */ 58 public AdminUIold(String string) { 59 super(string); 60 show(); 61 } 62 63 public void doStuff() { 64 try { 65 AssetServices services = AssetServicesUtil.getHome().create(); 66 AssetTypeValue assetType; 67 68 /* 69 assetType = services.createAssetType(); 70 assetType.setName("RiskAssessmentProject"); 71 assetType.setDescription("CORAS Platform Risk Assessment Project"); 72 services.modifyAssetType(assetType); 73 74 assetType = services.createAssetType(); 75 assetType.setName("ExperiencePackage"); 76 assetType.setDescription("CORAS Experience Package"); 77 services.modifyAssetType(assetType); 78 79 assetType = services.createAssetType(); 80 assetType.setName("RiskAssessmentResult"); 81 assetType.setDescription("CORAS Platform Risk Assessment Result"); 82 services.modifyAssetType(assetType); 83 84 Collection assetTypes = services.getAllAssetTypes(); 85 for (Iterator i = assetTypes.iterator(); i.hasNext();) { 86 assetType = (AssetTypeValue) i.next(); 87 System.out.println("Found AssetType " + assetType.getId()); 88 System.out.println("Name: " + assetType.getName()); 89 System.out.println("Description: " + assetType.getDescription()); 90 System.out.println(); 91 } 92 93 Collection assets = services.getAllAssets(); 94 for (Iterator i = assets.iterator(); i.hasNext();) { 95 AssetValue assetValue = (AssetValue) i.next(); 96 Asset asset = new Asset(assetValue); 97 System.out.println("Found Asset " + assetValue.getId()); 98 System.out.println("Type: " + assetValue.getAssetType()); 99 System.out.println("Checked out by: " + assetValue.getCheckedOutBy()); 100 System.out.println("Checked out date: " + assetValue.getCheckedOutDate()); 101 System.out.println("Name: " + asset.getName()); 102 System.out.println("Description: " + asset.getDescription()); 103 System.out.println(); 104 } 105 */ 106 } catch (RemoteException e) { 107 // TODO Auto-generated catch block 108 e.printStackTrace(); 109 } catch (CreateException e) { 110 // TODO Auto-generated catch block 111 e.printStackTrace(); 112 } catch (NamingException e) { 113 // TODO Auto-generated catch block 114 e.printStackTrace(); 115 } 116 System.exit(0); 117 } 118 119 private void login() { 120 LoginDialog loginDialog = new LoginDialog(this); 121 LoginContext lc = null; 122 try { 123 lc = new LoginContext("asset-repository", loginDialog); 124 loginDialog.setLoginContext(lc); 125 loginDialog.setLocationRelativeTo(this); 126 loginDialog.show(); 127 } catch (LoginException e) { 128 e.printStackTrace(); 129 } 130 if (!loginDialog.loginSucceeded()) { 131 JOptionPane.showMessageDialog(this, 132 "Login failed, program exiting.", 133 "Login failed", 134 JOptionPane.ERROR_MESSAGE); 135 System.exit(0); 136 } 137 lc = null; 138 } 139 140 }