1 Reply Latest reply on Nov 11, 2003 1:13 AM by micke

    EJB and Applets

    Scott Parmley Newbie

      Hello everyone! I am writing an Applet which I would like to be able to utilize some a session or entity bean. I seem to be able to get a handle to the ejb desired, but get the following exception once I try to invoke a bean method:

      java.security.AccessControlException: access denied (java.lang.RuntimePermission org.jboss.security.SecurityAssociation.getPrincipalInfo)

      at java.security.AccessControlContext.checkPermission(Unknown Source)

      at java.security.AccessController.checkPermission(Unknown Source)

      at java.lang.SecurityManager.checkPermission(Unknown Source)

      at org.jboss.security.SecurityAssociation.getPrincipal(SecurityAssociation.java:112)

      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:39)

      at org.jboss.proxy.ejb.HomeInterceptor.invoke(HomeInterceptor.java:173)

      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)

      at $Proxy0.create(Unknown Source)

      at com.paradigm.applet.MVGrid.getLLR295Facade(Unknown Source)

      at com.paradigm.applet.MVGrid.access$300(Unknown Source)

      at com.paradigm.applet.MVGrid$5.run(Unknown Source)



      I'm not using any security, that I am aware of. Bellow is my applet code (not pretty). The two methods of most interest are getLLR295Facade() and validate(). The exception is thrown in the validate method.

      Any incite here would be very much appreciated.

      Thanks,
      -Scott

      /*
       * MVGrid.java
       *
       * Created on October 27, 2003, 3:41 PM
       */
      
      package com.paradigm.applet;
      
      import com.paradigm.ejb.LLR295FacadeHome;
      import com.paradigm.ejb.LLR295Facade;
      import com.paradigm.valueObject.AAData;
      import com.paradigm.base.ValueObject;
      import com.paradigm.exception.*;
      import com.paradigm.base.LoginConfig;
      import com.paradigm.base.SimpleLoginConfig;
      
      import java.rmi.*;
      import javax.rmi.*;
      import javax.naming.*;
      import javax.ejb.CreateException;
      
      import java.util.StringTokenizer;
      import java.util.HashMap;
      import java.util.TreeMap;
      import java.util.TreeSet;
      import java.util.ArrayList;
      import java.util.Iterator;
      import java.util.Enumeration;
      import java.util.Vector;
      import java.util.Set;
      import java.util.Properties;
      
      import javax.swing.JApplet;
      import javax.swing.JTable;
      import javax.swing.table.TableCellEditor;
      import javax.swing.table.DefaultTableModel;
      import javax.swing.table.TableColumn;
      import javax.swing.table.DefaultTableColumnModel;
      import javax.swing.event.TableModelEvent;
      import javax.swing.event.TableModelListener;
      import javax.swing.event.ListSelectionListener;
      import javax.swing.event.ListSelectionEvent;
      import javax.swing.event.CellEditorListener;
      import javax.swing.event.ChangeEvent;
      import javax.swing.DefaultCellEditor;
      import javax.swing.JTextField;
      
      
      import com.paradigm.applet.particle.Particle;
      import com.paradigm.applet.particle.GridParticle;
      import com.paradigm.applet.particle.ColumnParticle;
      /**
       *
       * @author parmley
       */
      public class MVGrid extends JApplet {
      
       /** Initializes the applet MVGrid */
       public void init() {
       initComponents();
       setGridColumns();
      
       mvTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
       public void valueChanged(ListSelectionEvent evt) {
       int col = mvTable.getSelectedColumn();
       int row = mvTable.getSelectedRow();
       if(columns[col].isEditable()) {
       mvTable.editCellAt(row,col);
       }
       }
       });
      
       }
      
       /** This method is called from within the init() method to
       * initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is
       * always regenerated by the Form Editor.
       */
       private void initComponents() {
       scrollPane = new javax.swing.JScrollPane();
       mvTable = new javax.swing.JTable();
      
       mvTable.setFont(new java.awt.Font("Dialog", 0, 10));
       mvTable.setModel(new javax.swing.table.DefaultTableModel(
       new Object [][] {
      
       },
       new String [] {
       "-"
       }
       ) {
       boolean[] canEdit = new boolean [] {
       false
       };
      
       public boolean isCellEditable(int rowIndex, int columnIndex) {
       return canEdit [columnIndex];
       }
       });
       mvTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
       mvTable.setDoubleBuffered(true);
       mvTable.setEditingColumn(0);
       scrollPane.setViewportView(mvTable);
      
       getContentPane().add(scrollPane, java.awt.BorderLayout.CENTER);
      
       }
      
      
       public void setGridColumns() {
       // Not ideal. This is temporary.//
       StringTokenizer stNames = new StringTokenizer(this.getParameter("label"), ",");
       StringTokenizer stEdit = new StringTokenizer(this.getParameter("writeable"), ",");
       StringTokenizer stKey = new StringTokenizer(this.getParameter("key"), ",");
       StringTokenizer stSize = new StringTokenizer(this.getParameter("size"), ",");
      
       if(tcol == null) {
       tcol = new DefaultTableColumnModel();
       }
      
       if(tmodel == null) {
       tmodel = new DefaultTableModel();
       tmodel.setColumnCount(stNames.countTokens());
       mvTable.setModel(tmodel);
       }
      
      
       System.out.println("Setting "+stNames.countTokens()+" columns.");
      
       columns = new ColumnParticle[stNames.countTokens()];
       titles = new String[stNames.countTokens()];
       colWriteable = new boolean[stNames.countTokens()];
       mvGrid = new Object[0][stNames.countTokens()];
      
       int x=0;
       while(stNames.hasMoreTokens()) {
      
       String rname = stNames.nextToken();
       String redit = stEdit.nextToken();
       String rkey = stKey.nextToken();
       String rsize = stSize.nextToken();
      
       columns[x] = new ColumnParticle();
       columns[x].setLabel(rname);
       columns[x].setEditable(Boolean.valueOf(redit).booleanValue());
       columns[x].setKey(Boolean.valueOf(rkey).booleanValue());
       System.out.println("Column "+x+" key? "+columns[x].isKey());
       columns[x].setSize(Integer.parseInt(rsize));
       columns[x].setIndex(x);
       titles[x] = columns[x].getLabel();
       colWriteable[x] = columns[x].isEditable();
       TableColumn col = columns[x].toColumn();
      
       if(columns[x].isKey()) {
       System.out.println("Setting editor for column "+x);
       DefaultCellEditor editor = new DefaultCellEditor(new JTextField());
      
       editor.addCellEditorListener(new CellEditorListener() {
       public void editingCanceled(ChangeEvent evt) {
      
       }
       public void editingStopped(ChangeEvent evt) {
       validate();
       }
       });
      
       col.setCellEditor(editor);
       }
      
       tcol.addColumn(col);
       x++;
       }
       mvTable.setColumnModel(tcol);
      
       stNames = null;
       stEdit = null;
       stKey = null;
       stSize = null;
       }
      
       public void finalize() {
       try {
       super.finalize();
       }
       catch(Throwable e) {
       e.printStackTrace();
       }
       mvGrid = null;
       titles = null;
       this.destroy();
       }
      
       public void addRow() {
       new Thread() {
       public void run() {
       synchronized(tmodel) {
       tmodel.addRow(new Object[columns.length]);
       }
       }
       }.start();
       }
      
       public void deleteRow() {
       int[] i = mvTable.getSelectedRows();
       if( i.length > 0) {
       for(int x=0; x<i.length; x++) {
       tmodel.removeRow(i[x]-x);
       }
       }
       mvTable.repaint();
       }
      
       public void debugJSObject(Object obj) {
       System.out.println("OBJECT: "+obj+" TYPE: "+obj.getClass().getName());
       }
      
       public void insertRow() {
       tmodel.insertRow(mvTable.getSelectedRow(), new Object[columns.length]);
       }
      
       public String getKeys() {
       int keyCol = 0;
       int rows = tmodel.getRowCount();
       StringBuffer sbuff = new StringBuffer();
      
       // Consider firing the stop edit event here. -SCP//
      
       colIterator: for(int x=0; x<columns.length; x++) {
       if(columns[x].isKey()) {
       keyCol = x;
       break colIterator;
       }
       }
      
       for(int x=0; x<rows; x++) {
       sbuff.append(tmodel.getValueAt(x, keyCol)+",");
       }
      
       return sbuff.toString();
       }
      
       public void validate() {
      
       final int col = mvTable.getSelectedColumn();
       final int row = mvTable.getSelectedRow();
       final String value = mvTable.getValueAt(row,col) != null?(String)mvTable.getValueAt(row,col):null;
       if(value != null) {
       new Thread() {
       public void run() {
       synchronized(tmodel) {
       LLR295Facade facade = getLLR295Facade();
       ValueObject params = new ValueObject();
       try {
       params.setElement(1,0,0, "COMPANY.MASTER;1");
       params.setElement(2,0,0, "value");
       }
       catch(SystemException e) {
       e.printStackTrace();
       }
       System.out.println("AADataRemoteHome recieved.");
      
       try {
       //System.setProperty("java.security.debug", "access,failure");
       ArrayList result = facade.getAAData("123456987",params, getLoginConfig());
       //AAData dat = (AAData)result.get(0);
       //tmodel.setValueAt(dat.getDescription()+"", row, col+1);
       }
       catch(ApplicationException e) {
       tmodel.setValueAt(e.getMessage(), row, col+1);
       }
       catch(RemoteException e) {
       e.printStackTrace();
       }
       }
       }
       }.start();
       }
       }
      
       private LLR295Facade getLLR295Facade() {
       String host = this.getCodeBase().getHost ();
      
       Properties p = new Properties();
       //p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       p.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
       p.put("java.naming.provider.url", host);
       //p.put(Context.PROVIDER_URL, host);
       p.put("java.naming.factory.url.pkgs","org.jboss.naming:org.jnp.interfaces");
       //p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      
       // Need JNDI Setup Params for this Applet! -SCP//
       try {
       if(llrFacade == null) {
       InitialContext context = new InitialContext(p);
       Object ref = null;
       LLR295FacadeHome home = null;
      
      
       //DEBUG//
       System.out.println("Looking up context: LLR295FacadeBean");
       ref = context.lookup("LLR295FacadeBean");
      
       home = (LLR295FacadeHome)PortableRemoteObject.narrow(ref, LLR295FacadeHome.class);
      
       //DEBUG//
       System.out.println("Home interface recieved.");
       llrFacade = (LLR295Facade)home.create();
       }
       return llrFacade;
       }
       catch(NamingException e) {
       System.out.println("LLR295Facade[NamingException]: Failed to load facade bean. msg="+e.getMessage());
       e.printStackTrace();
       return null;
       }
       catch(CreateException e) {
       System.out.println("LLR295Facade[CreateException]: Failed to load facade bean. msg="+e.getMessage());
       e.printStackTrace();
       return null;
       }
       catch(RemoteException e) {
       System.out.println("LLR295Facade[RemoteException]: Failed to load facade bean. msg="+e.getMessage());
       e.printStackTrace();
       return null;
       }
       }
      
       private LoginConfig getLoginConfig() {
       if(config == null) {
       config = new SimpleLoginConfig();
       config.setAcctPath("uojSB.DEMO");
       config.setHostIP("helios");
       config.setSysUserId("unidata");
       config.setSysPassword("query1");
       config.setAppUserId("bqt1");
       config.setAppPassword("XXXX");
       }
       return config;
       }
       private LoginConfig config;
       private LLR295Facade llrFacade;
       private DefaultTableColumnModel tcol;
       private DefaultTableModel tmodel;
       private ColumnParticle[] columns;
       private volatile String currentCell;
       private ArrayList rows;
       private Object[][] mvGrid;
       private String[] titles;
       private boolean[] colWriteable;
      
       // Variables declaration - do not modify
       private javax.swing.JTable mvTable;
       private javax.swing.JScrollPane scrollPane;
       // End of variables declaration
      
      }