1 package hero.session; 2 3 import javax.ejb.CreateException ; 4 import javax.ejb.EJBException ; 5 import javax.ejb.SessionBean ; 6 import javax.ejb.SessionContext ; 7 import javax.naming.Context ; 8 import hero.interfaces.*; 9 import hero.util.HeroException; 10 11 12 40 public class InsertAuthRoleUserBean implements SessionBean 41 { 42 private SessionContext mContext; 43 44 53 public void initializeUser(String name,String password,String email) { 54 55 Context lContext; 56 BnUserLocalHome uhome = null; 57 BnUserLocal user; 58 BnUserValue uv; 59 60 try { 61 uhome = hero.interfaces.BnUserUtil.getLocalHome(); 62 try { 63 BnUserLocal us = uhome.findByName(name); 64 throw new HeroException("BnUser " + name + " already exist in the system "); 65 } catch (javax.ejb.FinderException nn) { 66 user = uhome.create(new BnUserValue()); 67 uv=user.getBnUserValue(); 68 uv.setName(name); 70 uv.setPassword(password); 71 uv.setEmail(email); 72 uv.setCreationDate(null); 73 uv.setModificationDate(null); 74 uv.setJabber(null); 75 user.setBnUserValue(uv); 76 } 77 } catch (java.lang.Exception e) { 78 e.printStackTrace(System.out); 79 } 80 81 } 82 83 92 public void initializeAuthRole(String name,String rolegroup) { 93 94 Context lContext; 95 BnAuthRoleLocalHome arhome = null; 96 BnAuthRoleLocal arole; 97 try { 98 arhome = hero.interfaces.BnAuthRoleUtil.getLocalHome(); 99 try { 100 BnAuthRoleLocal us = arhome.findByName(name); 101 throw new HeroException("BnAuthRole " + name + " already exist in the system "); 102 } catch (javax.ejb.FinderException nn) { 103 BnAuthRoleValue arv = new BnAuthRoleValue(); 104 arv.setName(name); 105 arv.setBnRoleGroup(rolegroup); 106 arole = arhome.create(arv); 107 } 108 } catch (java.lang.Exception e) { 109 e.printStackTrace(System.out); 110 } 111 112 } 113 114 122 public void initialize(String User,String AuthRole) { 123 124 Context lContext; 125 BnUserLocalHome uhome = null; 126 BnAuthRoleLocalHome arhome = null; 127 BnUserLocal user; 128 BnAuthRoleLocal authRole; 129 try { 130 uhome = hero.interfaces.BnUserUtil.getLocalHome(); 131 arhome = hero.interfaces.BnAuthRoleUtil.getLocalHome(); 132 user=uhome.findByName(User); 133 authRole=arhome.findByName(AuthRole); 134 135 if (!authRole.getBnUsers().contains(user)) 136 authRole.getBnUsers().add(user); 137 if (!user.getBnAuthRoles().contains(authRole)) 138 user.getBnAuthRoles().add(authRole); 139 140 } catch (java.lang.Exception e) { 141 e.printStackTrace(System.out); 142 } 143 144 } 145 146 153 public void ejbCreate() throws CreateException {} 154 155 156 160 public void setSessionContext( SessionContext aContext ) throws EJBException 161 { 162 mContext = aContext; 163 } 164 165 public void ejbActivate() 166 throws EJBException 167 { 168 } 169 170 public void ejbPassivate() 171 throws EJBException 172 { 173 } 174 175 public void ejbRemove() 176 throws EJBException 177 { 178 } 179 180 } 181 | Popular Tags |