0001: /* UserGroupManagerAdminEJBBean.java */
0002: package org.enhydra.shark.ws;
0003:
0004: import javax.naming.InitialContext;
0005: import javax.transaction.Status;
0006: import javax.transaction.UserTransaction;
0007:
0008: import org.enhydra.shark.Shark;
0009: import org.enhydra.shark.api.admin.UserGroupManagerAdmin;
0010: import org.enhydra.shark.api.client.wfmc.wapi.WMSessionHandle;
0011: import org.enhydra.shark.api.common.SharkConstants;
0012: import org.enhydra.shark.api.internal.working.CallbackUtilities;
0013: import org.enhydra.shark.ejb.SharkEJBUtilities;
0014:
0015: /**
0016: * @author V.Puskas
0017: * @author S.Bojanic
0018: * @author T.Jovanovic
0019: * @version 0.1
0020: */
0021: public class UserGroupManagerAdminWrapper implements
0022: UserGroupManagerAdmin {
0023:
0024: /**
0025: * @ejb:interface-method
0026: * view-type="all"
0027: * Method configure is called at Shark start up, to configure implementation of
0028: * UserGroupManager.
0029: *
0030: * @param cus an instance of CallbackUtilities used to get properties for configuring
0031: * userg roup manager in Shark.
0032: * @exception Exception Thrown if configuring doesn't succeed.
0033: */
0034: public void configure(CallbackUtilities cus) throws Exception {
0035: if (SharkEJBUtilities.getEnvType() == 1) {
0036: UserTransaction t = null;
0037: try {
0038: t = (UserTransaction) new InitialContext()
0039: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0040: t.begin();
0041: getSharkObject().configure(cus);
0042: t.commit();
0043:
0044: } catch (Exception ex) {
0045: try {
0046: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0047: t.rollback();
0048: } catch (Exception ex1) {
0049: ex1.printStackTrace();
0050: }
0051: throw ex;
0052: }
0053:
0054: } else {
0055: getSharkObject().configure(cus);
0056: }
0057:
0058: }
0059:
0060: /**
0061: * @ejb:interface-method
0062: * view-type="all"
0063: * Returns Ids of all user groups.
0064: *
0065: * @return List of user group Ids.
0066: * @throws Exception If something unexpected happens.
0067: */
0068: public String[] getAllGroupnames(WMSessionHandle shandle)
0069: throws Exception {
0070: if (SharkEJBUtilities.getEnvType() == 1) {
0071: UserTransaction t = null;
0072: String[] retVal = null;
0073: try {
0074: t = (UserTransaction) new InitialContext()
0075: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0076: t.begin();
0077: retVal = getSharkObject().getAllGroupnames(shandle);
0078: t.commit();
0079:
0080: } catch (Exception ex) {
0081: try {
0082: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0083: t.rollback();
0084: } catch (Exception ex1) {
0085: ex1.printStackTrace();
0086: }
0087: throw ex;
0088: }
0089:
0090: return retVal;
0091: } else {
0092: return getSharkObject().getAllGroupnames(shandle);
0093: }
0094: }
0095:
0096: /**
0097: * @ejb:interface-method
0098: * view-type="all"
0099: * Returns Ids of all groups for the given user.
0100: *
0101: * @param userName name of the given user.
0102: * @return List of all group ids for the given user.
0103: * @throws Exception If something unexpected happens.
0104: */
0105: public String[] getAllGroupnamesForUser(WMSessionHandle shandle,
0106: String userName) throws Exception {
0107: if (SharkEJBUtilities.getEnvType() == 1) {
0108: UserTransaction t = null;
0109: String[] retVal = null;
0110: try {
0111: t = (UserTransaction) new InitialContext()
0112: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0113: t.begin();
0114: retVal = getSharkObject().getAllGroupnamesForUser(
0115: shandle, userName);
0116: t.commit();
0117:
0118: } catch (Exception ex) {
0119: try {
0120: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0121: t.rollback();
0122: } catch (Exception ex1) {
0123: ex1.printStackTrace();
0124: }
0125: throw ex;
0126: }
0127:
0128: return retVal;
0129: } else {
0130: return getSharkObject().getAllGroupnamesForUser(shandle,
0131: userName);
0132: }
0133: }
0134:
0135: /**
0136: * @ejb:interface-method
0137: * view-type="all"
0138: * Returns Ids of all users.
0139: *
0140: * @return List of user Ids.
0141: * @throws Exception If something unexpected happens.
0142: */
0143:
0144: public String[] getAllUsers(WMSessionHandle shandle)
0145: throws Exception {
0146: if (SharkEJBUtilities.getEnvType() == 1) {
0147: UserTransaction t = null;
0148: String[] retVal = null;
0149: try {
0150: t = (UserTransaction) new InitialContext()
0151: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0152: t.begin();
0153: retVal = getSharkObject().getAllUsers(shandle);
0154: t.commit();
0155:
0156: } catch (Exception ex) {
0157: try {
0158: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0159: t.rollback();
0160: } catch (Exception ex1) {
0161: ex1.printStackTrace();
0162: }
0163: throw ex;
0164: }
0165:
0166: return retVal;
0167: } else {
0168: return getSharkObject().getAllUsers(shandle);
0169: }
0170: }
0171:
0172: /**
0173: * @ejb:interface-method
0174: * view-type="all"
0175: * Returns all users that belong to the given groups.
0176: *
0177: * @param groupNames names of the given groups.
0178: * @return List of all users that belong to given groups.
0179: * @throws Exception If something unexpected happens.
0180: */
0181: public String[] getAllUsersForGroups(WMSessionHandle shandle,
0182: String[] groupNames) throws Exception {
0183: if (SharkEJBUtilities.getEnvType() == 1) {
0184: UserTransaction t = null;
0185: String[] retVal = null;
0186: try {
0187: t = (UserTransaction) new InitialContext()
0188: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0189: t.begin();
0190: retVal = getSharkObject().getAllUsersForGroups(shandle,
0191: groupNames);
0192: t.commit();
0193:
0194: } catch (Exception ex) {
0195: try {
0196: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0197: t.rollback();
0198: } catch (Exception ex1) {
0199: ex1.printStackTrace();
0200: }
0201: throw ex;
0202: }
0203:
0204: return retVal;
0205: } else {
0206: return getSharkObject().getAllUsersForGroups(shandle,
0207: groupNames);
0208: }
0209: }
0210:
0211: /**
0212: * @ejb:interface-method
0213: * view-type="all"
0214: * Returns all users that are immediate children of the given group.
0215: *
0216: * @param groupName name of the given group.
0217: * @return List of all immediate (direct) users that belong to the given group.
0218: * @throws Exception If something unexpected happens.
0219: */
0220: public String[] getAllImmediateUsersForGroup(
0221: WMSessionHandle shandle, String groupName) throws Exception {
0222: if (SharkEJBUtilities.getEnvType() == 1) {
0223: UserTransaction t = null;
0224: String[] retVal = null;
0225: try {
0226: t = (UserTransaction) new InitialContext()
0227: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0228: t.begin();
0229: retVal = getSharkObject().getAllImmediateUsersForGroup(
0230: shandle, groupName);
0231: t.commit();
0232:
0233: } catch (Exception ex) {
0234: try {
0235: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0236: t.rollback();
0237: } catch (Exception ex1) {
0238: ex1.printStackTrace();
0239: }
0240: throw ex;
0241: }
0242:
0243: return retVal;
0244: } else {
0245: return getSharkObject().getAllImmediateUsersForGroup(
0246: shandle, groupName);
0247: }
0248: }
0249:
0250: /**
0251: * @ejb:interface-method
0252: * view-type="all"
0253: * Returns all groups that belong to the given groups.
0254: *
0255: * @param groupNames names of the given groups.
0256: * @return List of all groups that belong to the given groups.
0257: * @throws Exception If something unexpected happens.
0258: */
0259: public String[] getAllSubgroupsForGroups(WMSessionHandle shandle,
0260: String[] groupNames) throws Exception {
0261: if (SharkEJBUtilities.getEnvType() == 1) {
0262: UserTransaction t = null;
0263: String[] retVal = null;
0264: try {
0265: t = (UserTransaction) new InitialContext()
0266: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0267: t.begin();
0268: retVal = getSharkObject().getAllSubgroupsForGroups(
0269: shandle, groupNames);
0270: t.commit();
0271:
0272: } catch (Exception ex) {
0273: try {
0274: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0275: t.rollback();
0276: } catch (Exception ex1) {
0277: ex1.printStackTrace();
0278: }
0279: throw ex;
0280: }
0281:
0282: return retVal;
0283: } else {
0284: return getSharkObject().getAllSubgroupsForGroups(shandle,
0285: groupNames);
0286: }
0287: }
0288:
0289: /**
0290: * @ejb:interface-method
0291: * view-type="all"
0292: * Returns all groups that are immediate children of the given group (which are on the
0293: * first level bellow the level of the given group).
0294: *
0295: * @param groupName name of the given group.
0296: * @return List of all groups that are immediate children of the given group.
0297: * @throws Exception If something unexpected happens.
0298: */
0299: public String[] getAllImmediateSubgroupsForGroup(
0300: WMSessionHandle shandle, String groupName) throws Exception {
0301: if (SharkEJBUtilities.getEnvType() == 1) {
0302: UserTransaction t = null;
0303: String[] retVal = null;
0304: try {
0305: t = (UserTransaction) new InitialContext()
0306: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0307: t.begin();
0308: retVal = getSharkObject()
0309: .getAllImmediateSubgroupsForGroup(shandle,
0310: groupName);
0311: t.commit();
0312:
0313: } catch (Exception ex) {
0314: try {
0315: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0316: t.rollback();
0317: } catch (Exception ex1) {
0318: ex1.printStackTrace();
0319: }
0320: throw ex;
0321: }
0322:
0323: return retVal;
0324: } else {
0325: return getSharkObject().getAllImmediateSubgroupsForGroup(
0326: shandle, groupName);
0327: }
0328: }
0329:
0330: /**
0331: * @ejb:interface-method
0332: * view-type="all"
0333: * Returns true if user group with given name exists.
0334: *
0335: * @param groupName name of the given group.
0336: * @return true if user group exists, otherwise false.
0337: * @throws Exception If something unexpected happens.
0338: */
0339: public boolean doesGroupExist(WMSessionHandle shandle,
0340: String groupName) throws Exception {
0341: if (SharkEJBUtilities.getEnvType() == 1) {
0342: UserTransaction t = null;
0343: boolean retVal = false;
0344: try {
0345: t = (UserTransaction) new InitialContext()
0346: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0347: t.begin();
0348: retVal = getSharkObject().doesGroupExist(shandle,
0349: groupName);
0350: t.commit();
0351:
0352: } catch (Exception ex) {
0353: try {
0354: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0355: t.rollback();
0356: } catch (Exception ex1) {
0357: ex1.printStackTrace();
0358: }
0359: throw ex;
0360: }
0361:
0362: return retVal;
0363: } else {
0364: return getSharkObject().doesGroupExist(shandle, groupName);
0365: }
0366: }
0367:
0368: /**
0369: * @ejb:interface-method
0370: * view-type="all"
0371: * Returns true if group <i>subgroupName</i> is subgroup of group <i>groupName</i>.
0372: *
0373: * @param groupName name of the given group.
0374: * @param subgroupName name of the given subgroup.
0375: * @return true if group <i>subgroupName</i> is subgroup of group <i>groupName</i>,
0376: * otherwise false.
0377: * @throws Exception If something unexpected happens.
0378: */
0379: public boolean doesGroupBelongToGroup(WMSessionHandle shandle,
0380: String groupName, String subgroupName) throws Exception {
0381: if (SharkEJBUtilities.getEnvType() == 1) {
0382: UserTransaction t = null;
0383: boolean retVal = false;
0384: try {
0385: t = (UserTransaction) new InitialContext()
0386: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0387: t.begin();
0388: retVal = getSharkObject().doesGroupBelongToGroup(
0389: shandle, groupName, subgroupName);
0390: t.commit();
0391:
0392: } catch (Exception ex) {
0393: try {
0394: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0395: t.rollback();
0396: } catch (Exception ex1) {
0397: ex1.printStackTrace();
0398: }
0399: throw ex;
0400: }
0401:
0402: return retVal;
0403: } else {
0404: return getSharkObject().doesGroupBelongToGroup(shandle,
0405: groupName, subgroupName);
0406: }
0407: }
0408:
0409: /**
0410: * @ejb:interface-method
0411: * view-type="all"
0412: * Returns a group description.
0413: *
0414: * @param groupName name of the given group.
0415: * @return Group description.
0416: * @throws Exception If something unexpected happens.
0417: */
0418: public String getGroupDescription(WMSessionHandle shandle,
0419: String groupName) throws Exception {
0420: if (SharkEJBUtilities.getEnvType() == 1) {
0421: UserTransaction t = null;
0422: String retVal = null;
0423: try {
0424: t = (UserTransaction) new InitialContext()
0425: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0426: t.begin();
0427: retVal = getSharkObject().getGroupDescription(shandle,
0428: groupName);
0429: t.commit();
0430:
0431: } catch (Exception ex) {
0432: try {
0433: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0434: t.rollback();
0435: } catch (Exception ex1) {
0436: ex1.printStackTrace();
0437: }
0438: throw ex;
0439: }
0440:
0441: return retVal;
0442: } else {
0443: return getSharkObject().getGroupDescription(shandle,
0444: groupName);
0445: }
0446: }
0447:
0448: /**
0449: * @ejb:interface-method
0450: * view-type="all"
0451: * Returns true if the given user belongs to the given group.
0452: *
0453: * @param groupName name of the given group.
0454: * @param username username used to uniquely identify shark user.
0455: * @return true if the given user belongs to the given group, otherwise false.
0456: * @throws Exception If something unexpected happens.
0457: */
0458: public boolean doesUserBelongToGroup(WMSessionHandle shandle,
0459: String groupName, String username) throws Exception {
0460: if (SharkEJBUtilities.getEnvType() == 1) {
0461: UserTransaction t = null;
0462: boolean retVal = false;
0463: try {
0464: t = (UserTransaction) new InitialContext()
0465: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0466: t.begin();
0467: retVal = getSharkObject().doesUserBelongToGroup(
0468: shandle, groupName, username);
0469: t.commit();
0470:
0471: } catch (Exception ex) {
0472: try {
0473: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0474: t.rollback();
0475: } catch (Exception ex1) {
0476: ex1.printStackTrace();
0477: }
0478: throw ex;
0479: }
0480:
0481: return retVal;
0482: } else {
0483: return getSharkObject().doesUserBelongToGroup(shandle,
0484: groupName, username);
0485: }
0486: }
0487:
0488: /**
0489: * @ejb:interface-method
0490: * view-type="all"
0491: * Returns true if user with given username exists.
0492: *
0493: * @param username username of the shark user.
0494: * @return true if the user with the given username exists, otherwise false.
0495: * @throws Exception If something unexpected happens.
0496: */
0497: public boolean doesUserExist(WMSessionHandle shandle,
0498: String username) throws Exception {
0499: if (SharkEJBUtilities.getEnvType() == 1) {
0500: UserTransaction t = null;
0501: boolean retVal = false;
0502: try {
0503: t = (UserTransaction) new InitialContext()
0504: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0505: t.begin();
0506: retVal = getSharkObject().doesUserExist(shandle,
0507: username);
0508: t.commit();
0509:
0510: } catch (Exception ex) {
0511: try {
0512: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0513: t.rollback();
0514: } catch (Exception ex1) {
0515: ex1.printStackTrace();
0516: }
0517: throw ex;
0518: }
0519:
0520: return retVal;
0521: } else {
0522: return getSharkObject().doesUserExist(shandle, username);
0523: }
0524: }
0525:
0526: /**
0527: * @ejb:interface-method
0528: * view-type="all"
0529: * Returns string representing the password for the shark user with the given username.
0530: *
0531: * @param username username of the shark user.
0532: * @return password of the shark user.
0533: * @throws Exception If something unexpected happens.
0534: */
0535: public String getUserPassword(WMSessionHandle shandle,
0536: String username) throws Exception {
0537: if (SharkEJBUtilities.getEnvType() == 1) {
0538: UserTransaction t = null;
0539: String retVal = null;
0540: try {
0541: t = (UserTransaction) new InitialContext()
0542: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0543: t.begin();
0544: retVal = getSharkObject().getUserPassword(shandle,
0545: username);
0546: t.commit();
0547:
0548: } catch (Exception ex) {
0549: try {
0550: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0551: t.rollback();
0552: } catch (Exception ex1) {
0553: ex1.printStackTrace();
0554: }
0555: throw ex;
0556: }
0557:
0558: return retVal;
0559: } else {
0560: return getSharkObject().getUserPassword(shandle, username);
0561: }
0562: }
0563:
0564: /**
0565: * @ejb:interface-method
0566: * view-type="all"
0567: * Returns string representing the real name for the shark user with the given username
0568: * (first and last name).
0569: *
0570: * @param username username of the shark user.
0571: * @return Real name of the shark user.
0572: * @throws Exception If something unexpected happens.
0573: */
0574: public String getUserRealName(WMSessionHandle shandle,
0575: String username) throws Exception {
0576: if (SharkEJBUtilities.getEnvType() == 1) {
0577: UserTransaction t = null;
0578: String retVal = null;
0579: try {
0580: t = (UserTransaction) new InitialContext()
0581: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0582: t.begin();
0583: retVal = getSharkObject().getUserRealName(shandle,
0584: username);
0585: t.commit();
0586:
0587: } catch (Exception ex) {
0588: try {
0589: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0590: t.rollback();
0591: } catch (Exception ex1) {
0592: ex1.printStackTrace();
0593: }
0594: throw ex;
0595: }
0596:
0597: return retVal;
0598: } else {
0599: return getSharkObject().getUserRealName(shandle, username);
0600: }
0601: }
0602:
0603: /**
0604: * @ejb:interface-method
0605: * view-type="all"
0606: * Returns string representing user's first name.
0607: *
0608: * @param username username of the shark user.
0609: * @return First name of the shark user.
0610: * @throws Exception If something unexpected happens.
0611: */
0612: public String getUserFirstName(WMSessionHandle shandle,
0613: String username) throws Exception {
0614: if (SharkEJBUtilities.getEnvType() == 1) {
0615: UserTransaction t = null;
0616: String retVal = null;
0617: try {
0618: t = (UserTransaction) new InitialContext()
0619: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0620: t.begin();
0621: retVal = getSharkObject().getUserFirstName(shandle,
0622: username);
0623: t.commit();
0624:
0625: } catch (Exception ex) {
0626: try {
0627: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0628: t.rollback();
0629: } catch (Exception ex1) {
0630: ex1.printStackTrace();
0631: }
0632: throw ex;
0633: }
0634:
0635: return retVal;
0636: } else {
0637: return getSharkObject().getUserFirstName(shandle, username);
0638: }
0639: }
0640:
0641: /**
0642: * @ejb:interface-method
0643: * view-type="all"
0644: * Returns string representing user's last name.
0645: *
0646: * @param username username of the shark user.
0647: * @return Last name of the shark user.
0648: * @throws Exception If something unexpected happens.
0649: */
0650: public String getUserLastName(WMSessionHandle shandle,
0651: String username) throws Exception {
0652: if (SharkEJBUtilities.getEnvType() == 1) {
0653: UserTransaction t = null;
0654: String retVal = null;
0655: try {
0656: t = (UserTransaction) new InitialContext()
0657: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0658: t.begin();
0659: retVal = getSharkObject().getUserLastName(shandle,
0660: username);
0661: t.commit();
0662:
0663: } catch (Exception ex) {
0664: try {
0665: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0666: t.rollback();
0667: } catch (Exception ex1) {
0668: ex1.printStackTrace();
0669: }
0670: throw ex;
0671: }
0672:
0673: return retVal;
0674: } else {
0675: return getSharkObject().getUserLastName(shandle, username);
0676: }
0677: }
0678:
0679: /**
0680: * @ejb:interface-method
0681: * view-type="all"
0682: * Returns string representing email address for the user with the given username.
0683: *
0684: * @param username username of the shark user.
0685: * @return Email of the shark user.
0686: * @throws Exception If something unexpected happens.
0687: */
0688: public String getUserEMailAddress(WMSessionHandle shandle,
0689: String username) throws Exception {
0690: if (SharkEJBUtilities.getEnvType() == 1) {
0691: UserTransaction t = null;
0692: String retVal = null;
0693: try {
0694: t = (UserTransaction) new InitialContext()
0695: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0696: t.begin();
0697: retVal = getSharkObject().getUserEMailAddress(shandle,
0698: username);
0699: t.commit();
0700:
0701: } catch (Exception ex) {
0702: try {
0703: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0704: t.rollback();
0705: } catch (Exception ex1) {
0706: ex1.printStackTrace();
0707: }
0708: throw ex;
0709: }
0710:
0711: return retVal;
0712: } else {
0713: return getSharkObject().getUserEMailAddress(shandle,
0714: username);
0715: }
0716: }
0717:
0718: /**
0719: * @ejb:interface-method
0720: * view-type="all"
0721: * Return the list of objects that match specified expression evaluation.<br>
0722: *
0723: * TODO determine the exact format of the expression parameter so that
0724: * Shark knows how to create it and the client knows how to process
0725: * it
0726: */
0727: public String[] getObjects(WMSessionHandle sessionHandle,
0728: String expression) throws Exception {
0729: if (SharkEJBUtilities.getEnvType() == 1) {
0730: UserTransaction t = null;
0731: String[] retVal = null;
0732: try {
0733: t = (UserTransaction) new InitialContext()
0734: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0735: t.begin();
0736: retVal = getSharkObject().getObjects(sessionHandle,
0737: expression);
0738: t.commit();
0739:
0740: } catch (Exception ex) {
0741: try {
0742: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0743: t.rollback();
0744: } catch (Exception ex1) {
0745: ex1.printStackTrace();
0746: }
0747: throw ex;
0748: }
0749:
0750: return retVal;
0751: } else {
0752: return getSharkObject().getObjects(sessionHandle,
0753: expression);
0754: }
0755: }
0756:
0757: /**
0758: * @ejb:interface-method
0759: * view-type="all"
0760: * Return all groups that match the specified expression evaluation.<br>
0761: *
0762: * TODO determine the exact format of the expression parameter so that
0763: * Shark knows how to create it and the client knows how to process
0764: * it
0765: */
0766: public String[] getGroups(WMSessionHandle sessionHandle,
0767: String expression) throws Exception {
0768: if (SharkEJBUtilities.getEnvType() == 1) {
0769: UserTransaction t = null;
0770: String[] retVal = null;
0771: try {
0772: t = (UserTransaction) new InitialContext()
0773: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0774: t.begin();
0775: retVal = getSharkObject().getGroups(sessionHandle,
0776: expression);
0777: t.commit();
0778:
0779: } catch (Exception ex) {
0780: try {
0781: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0782: t.rollback();
0783: } catch (Exception ex1) {
0784: ex1.printStackTrace();
0785: }
0786: throw ex;
0787: }
0788:
0789: return retVal;
0790: } else {
0791: return getSharkObject()
0792: .getGroups(sessionHandle, expression);
0793: }
0794: }
0795:
0796: /**
0797: * @ejb:interface-method
0798: * view-type="all"
0799: * Creates a new user group.
0800: *
0801: * @param groupName name of the given group.
0802: * @param description group description.
0803: *
0804: * @throws Exception If something unexpected happens.
0805: */
0806: public void createGroup(String groupName, String description)
0807: throws Exception {
0808: if (SharkEJBUtilities.getEnvType() == 1) {
0809: UserTransaction t = null;
0810: try {
0811: t = (UserTransaction) new InitialContext()
0812: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0813: t.begin();
0814: getSharkObject().createGroup(groupName, description);
0815: t.commit();
0816:
0817: } catch (Exception ex) {
0818: try {
0819: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0820: t.rollback();
0821: } catch (Exception ex1) {
0822: ex1.printStackTrace();
0823: }
0824: throw ex;
0825: }
0826: } else {
0827: getSharkObject().createGroup(groupName, description);
0828: }
0829: }
0830:
0831: /**
0832: * @ejb:interface-method
0833: * view-type="all"
0834: * Removes user group.
0835: *
0836: * @param groupName name of the given group.
0837: *
0838: * @throws Exception If something unexpected happens.
0839: */
0840: public void removeGroup(String groupName) throws Exception {
0841: if (SharkEJBUtilities.getEnvType() == 1) {
0842: UserTransaction t = null;
0843: try {
0844: t = (UserTransaction) new InitialContext()
0845: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0846: t.begin();
0847: getSharkObject().removeGroup(groupName);
0848: t.commit();
0849:
0850: } catch (Exception ex) {
0851: try {
0852: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0853: t.rollback();
0854: } catch (Exception ex1) {
0855: ex1.printStackTrace();
0856: }
0857: throw ex;
0858: }
0859:
0860: } else {
0861: getSharkObject().removeGroup(groupName);
0862: }
0863: }
0864:
0865: /**
0866: * @ejb:interface-method
0867: * view-type="all"
0868: * Allows administrator to update data about group.
0869: *
0870: * @param groupName name of the given group.
0871: * @param description group description.
0872: *
0873: * @throws Exception If something unexpected happens.
0874: */
0875: public void updateGroup(String groupName, String description)
0876: throws Exception {
0877: if (SharkEJBUtilities.getEnvType() == 1) {
0878: UserTransaction t = null;
0879: try {
0880: t = (UserTransaction) new InitialContext()
0881: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0882: t.begin();
0883: getSharkObject().updateGroup(groupName, description);
0884: t.commit();
0885:
0886: } catch (Exception ex) {
0887: try {
0888: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0889: t.rollback();
0890: } catch (Exception ex1) {
0891: ex1.printStackTrace();
0892: }
0893: throw ex;
0894: }
0895:
0896: } else {
0897: getSharkObject().updateGroup(groupName, description);
0898: }
0899: }
0900:
0901: /**
0902: * @ejb:interface-method
0903: * view-type="all"
0904: * Adds an existing group <i>subgroupName</i> to the group <i>groupName</i>.
0905: *
0906: * @param groupName name of the given group.
0907: * @param subgroupName name of the given subgroup to be added.
0908: *
0909: * @throws Exception If something unexpected happens.
0910: */
0911: public void addGroupToGroup(String groupName, String subgroupName)
0912: throws Exception {
0913: if (SharkEJBUtilities.getEnvType() == 1) {
0914: UserTransaction t = null;
0915: try {
0916: t = (UserTransaction) new InitialContext()
0917: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0918: t.begin();
0919: getSharkObject().addGroupToGroup(groupName,
0920: subgroupName);
0921: t.commit();
0922:
0923: } catch (Exception ex) {
0924: try {
0925: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0926: t.rollback();
0927: } catch (Exception ex1) {
0928: ex1.printStackTrace();
0929: }
0930: throw ex;
0931: }
0932: } else {
0933: getSharkObject().addGroupToGroup(groupName, subgroupName);
0934: }
0935: }
0936:
0937: /**
0938: * @ejb:interface-method
0939: * view-type="all"
0940: * Removes group <i>subgroupName</i> from the group <i>groupName</i>.
0941: *
0942: * @param groupName name of the given group.
0943: * @param subgroupName name of the given subgroup to be removed.
0944: *
0945: * @throws Exception If something unexpected happens.
0946: */
0947: public void removeGroupFromGroup(String groupName,
0948: String subgroupName) throws Exception {
0949: if (SharkEJBUtilities.getEnvType() == 1) {
0950: UserTransaction t = null;
0951: try {
0952: t = (UserTransaction) new InitialContext()
0953: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0954: t.begin();
0955: getSharkObject().removeGroupFromGroup(groupName,
0956: subgroupName);
0957: t.commit();
0958:
0959: } catch (Exception ex) {
0960: try {
0961: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0962: t.rollback();
0963: } catch (Exception ex1) {
0964: ex1.printStackTrace();
0965: }
0966: throw ex;
0967: }
0968: } else {
0969: getSharkObject().removeGroupFromGroup(groupName,
0970: subgroupName);
0971: }
0972: }
0973:
0974: /**
0975: * @ejb:interface-method
0976: * view-type="all"
0977: * Deletes group <i>groupName</i> and all its child groups that don't belong
0978: * to any other group except this one.
0979: *
0980: * @param groupName name of the given group.
0981: *
0982: * @throws Exception If something unexpected happens.
0983: */
0984: public void removeGroupTree(String groupName) throws Exception {
0985: if (SharkEJBUtilities.getEnvType() == 1) {
0986: UserTransaction t = null;
0987: try {
0988: t = (UserTransaction) new InitialContext()
0989: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
0990: t.begin();
0991: getSharkObject().removeGroupTree(groupName);
0992: t.commit();
0993:
0994: } catch (Exception ex) {
0995: try {
0996: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
0997: t.rollback();
0998: } catch (Exception ex1) {
0999: ex1.printStackTrace();
1000: }
1001: throw ex;
1002: }
1003: } else {
1004: getSharkObject().removeGroupTree(groupName);
1005: }
1006: }
1007:
1008: /**
1009: * @ejb:interface-method
1010: * view-type="all"
1011: * Removes all users from group <i>group</i> that don't belong to any other
1012: * group except this one.
1013: *
1014: * @param groupName name of the given group.
1015: *
1016: * @throws Exception If something unexpected happens.
1017: */
1018: public void removeUsersFromGroupTree(String groupName)
1019: throws Exception {
1020: if (SharkEJBUtilities.getEnvType() == 1) {
1021: UserTransaction t = null;
1022: try {
1023: t = (UserTransaction) new InitialContext()
1024: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1025: t.begin();
1026: getSharkObject().removeUsersFromGroupTree(groupName);
1027: t.commit();
1028:
1029: } catch (Exception ex) {
1030: try {
1031: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1032: t.rollback();
1033: } catch (Exception ex1) {
1034: ex1.printStackTrace();
1035: }
1036: throw ex;
1037: }
1038:
1039: } else {
1040: getSharkObject().removeUsersFromGroupTree(groupName);
1041: }
1042: }
1043:
1044: /**
1045: * @ejb:interface-method
1046: * view-type="all"
1047: * Moves group <i>subgroupName</i> from the group <i>currentParentGroup</i> to
1048: * group <i>newParentGroup</i>.
1049: *
1050: * @param currentParentGroup current group that contains group subgroupName.
1051: * @param newParentGroup new group where group subgroupName will be moved to.
1052: * @param subgroupName subgroup that will be moved.
1053: *
1054: * @throws Exception If something unexpected happens.
1055: */
1056: public void moveGroup(String currentParentGroup,
1057: String newParentGroup, String subgroupName)
1058: throws Exception {
1059: if (SharkEJBUtilities.getEnvType() == 1) {
1060: UserTransaction t = null;
1061: try {
1062: t = (UserTransaction) new InitialContext()
1063: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1064: t.begin();
1065: getSharkObject().moveGroup(currentParentGroup,
1066: newParentGroup, subgroupName);
1067: t.commit();
1068:
1069: } catch (Exception ex) {
1070: try {
1071: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1072: t.rollback();
1073: } catch (Exception ex1) {
1074: ex1.printStackTrace();
1075: }
1076: throw ex;
1077: }
1078:
1079: } else {
1080: getSharkObject().moveGroup(currentParentGroup,
1081: newParentGroup, subgroupName);
1082: }
1083: }
1084:
1085: /**
1086: * @ejb:interface-method
1087: * view-type="all"
1088: * Adds an existing user with a given username to the given group.
1089: *
1090: * @param groupName name of the given group.
1091: * @param username username used to uniquely identify shark user.
1092: *
1093: * @throws Exception If something unexpected happens.
1094: */
1095: public void addUserToGroup(String groupName, String username)
1096: throws Exception {
1097: if (SharkEJBUtilities.getEnvType() == 1) {
1098: UserTransaction t = null;
1099: try {
1100: t = (UserTransaction) new InitialContext()
1101: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1102: t.begin();
1103: getSharkObject().addUserToGroup(groupName, username);
1104: t.commit();
1105:
1106: } catch (Exception ex) {
1107: try {
1108: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1109: t.rollback();
1110: } catch (Exception ex1) {
1111: ex1.printStackTrace();
1112: }
1113: throw ex;
1114: }
1115:
1116: } else {
1117: getSharkObject().addUserToGroup(groupName, username);
1118: }
1119: }
1120:
1121: /**
1122: * @ejb:interface-method
1123: * view-type="all"
1124: * Removes the user from the group.
1125: *
1126: * @param groupName name of the given group.
1127: * @param username username used to uniquely identify shark user.
1128: *
1129: * @throws Exception If something unexpected happens.
1130: */
1131: public void removeUserFromGroup(String groupName, String username)
1132: throws Exception {
1133: if (SharkEJBUtilities.getEnvType() == 1) {
1134: UserTransaction t = null;
1135: try {
1136: t = (UserTransaction) new InitialContext()
1137: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1138: t.begin();
1139: getSharkObject().removeUserFromGroup(groupName,
1140: username);
1141: t.commit();
1142:
1143: } catch (Exception ex) {
1144: try {
1145: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1146: t.rollback();
1147: } catch (Exception ex1) {
1148: ex1.printStackTrace();
1149: }
1150: throw ex;
1151: }
1152:
1153: } else {
1154: getSharkObject().removeUserFromGroup(groupName, username);
1155: }
1156: }
1157:
1158: /**
1159: * @ejb:interface-method
1160: * view-type="all"
1161: * Moves user <i>username</i> from the group <i>currentGroup</i> to group
1162: * <i>newGroup</i>.
1163: *
1164: * @param currentGroup current group that contains the user.
1165: * @param newGroup new group where the user will be moved to.
1166: * @param username the user that will be moved.
1167: *
1168: * @throws Exception If something unexpected happens.
1169: */
1170:
1171: public void moveUser(String currentGroup, String newGroup,
1172: String username) throws Exception {
1173: if (SharkEJBUtilities.getEnvType() == 1) {
1174: UserTransaction t = null;
1175: try {
1176: t = (UserTransaction) new InitialContext()
1177: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1178: t.begin();
1179: getSharkObject().moveUser(currentGroup, newGroup,
1180: username);
1181: t.commit();
1182:
1183: } catch (Exception ex) {
1184: try {
1185: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1186: t.rollback();
1187: } catch (Exception ex1) {
1188: ex1.printStackTrace();
1189: }
1190: throw ex;
1191: }
1192:
1193: } else {
1194: getSharkObject().moveUser(currentGroup, newGroup, username);
1195: }
1196: }
1197:
1198: /**
1199: * @ejb:interface-method
1200: * view-type="all"
1201: * Allows administrator to create new user. After its creation, the client
1202: * application will always be able to log onto shark using username and
1203: * password defined for the user.
1204: *
1205: * @param groupName groupName used to uniquely identify group -
1206: * this parameter is mandatory.
1207: * @param username username used to uniquely identify user -
1208: * this parameter is mandatory.
1209: * @param password password used to authenticate -
1210: * this parameter is mandatory.
1211: * @param firstName the user's first name.
1212: * @param lastName the user's last name.
1213: * @param emailAddress email address of the user.
1214: *
1215: * @throws Exception If something unexpected happens (i.e the user with
1216: * given username already exists).
1217: */
1218: public void createUser(String groupName, String username,
1219: String password, String firstName, String lastName,
1220: String emailAddress) throws Exception {
1221: if (SharkEJBUtilities.getEnvType() == 1) {
1222: UserTransaction t = null;
1223: try {
1224: t = (UserTransaction) new InitialContext()
1225: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1226: t.begin();
1227: getSharkObject().createUser(groupName, username,
1228: password, firstName, lastName, emailAddress);
1229: t.commit();
1230:
1231: } catch (Exception ex) {
1232: try {
1233: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1234: t.rollback();
1235: } catch (Exception ex1) {
1236: ex1.printStackTrace();
1237: }
1238: throw ex;
1239: }
1240:
1241: } else {
1242: getSharkObject().createUser(groupName, username, password,
1243: firstName, lastName, emailAddress);
1244: }
1245: }
1246:
1247: /**
1248: * @ejb:interface-method
1249: * view-type="all"
1250: * Allows administrator to update data about user.
1251: *
1252: * @param username username used to uniquely identify user -
1253: * this parameter is mandatory.
1254: * @param firstName the user's first name.
1255: * @param lastName the user's last name.
1256: * @param emailAddress email address of the user.
1257: *
1258: * @throws Exception If something unexpected happens (i.e the user with
1259: * given username does not exist).
1260: */
1261: public void updateUser(String username, String firstName,
1262: String lastName, String emailAddress) throws Exception {
1263: if (SharkEJBUtilities.getEnvType() == 1) {
1264: UserTransaction t = null;
1265: try {
1266: t = (UserTransaction) new InitialContext()
1267: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1268: t.begin();
1269: getSharkObject().updateUser(username, firstName,
1270: lastName, emailAddress);
1271: t.commit();
1272:
1273: } catch (Exception ex) {
1274: try {
1275: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1276: t.rollback();
1277: } catch (Exception ex1) {
1278: ex1.printStackTrace();
1279: }
1280: throw ex;
1281: }
1282: } else {
1283: getSharkObject().updateUser(username, firstName, lastName,
1284: emailAddress);
1285: }
1286: }
1287:
1288: /**
1289: * @ejb:interface-method
1290: * view-type="all"
1291: * Allows administrator to remove the user.
1292: *
1293: * @param username username used to uniquely identify user.
1294: *
1295: * @throws Exception If something unexpected happens (i.e the user with
1296: * given username does not exist, or this is a user that can't be removed).
1297: */
1298: public void removeUser(String username) throws Exception {
1299: if (SharkEJBUtilities.getEnvType() == 1) {
1300: UserTransaction t = null;
1301: try {
1302: t = (UserTransaction) new InitialContext()
1303: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1304: t.begin();
1305: getSharkObject().removeUser(username);
1306: t.commit();
1307:
1308: } catch (Exception ex) {
1309: try {
1310: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1311: t.rollback();
1312: } catch (Exception ex1) {
1313: ex1.printStackTrace();
1314: }
1315: throw ex;
1316: }
1317:
1318: } else {
1319: getSharkObject().removeUser(username);
1320: }
1321: }
1322:
1323: /**
1324: * @ejb:interface-method
1325: * view-type="all"
1326: * Sets user password.
1327: *
1328: * @param username username of the shark user.
1329: * @param password new password of the shark user.
1330: *
1331: * @throws Exception If something unexpected happens.
1332: */
1333: public void setPassword(String username, String password)
1334: throws Exception {
1335: if (SharkEJBUtilities.getEnvType() == 1) {
1336: UserTransaction t = null;
1337: try {
1338: t = (UserTransaction) new InitialContext()
1339: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1340: t.begin();
1341: getSharkObject().setPassword(username, password);
1342: t.commit();
1343:
1344: } catch (Exception ex) {
1345: try {
1346: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1347: t.rollback();
1348: } catch (Exception ex1) {
1349: ex1.printStackTrace();
1350: }
1351: throw ex;
1352: }
1353:
1354: } else {
1355: getSharkObject().setPassword(username, password);
1356: }
1357: }
1358:
1359: /**
1360: * @ejb:interface-method
1361: * view-type="all"
1362: * Validates user.
1363: *
1364: * @param username user name.
1365: * @param pwd user password.
1366: *
1367: * @return true if user is validated, otherwise false.
1368: *
1369: * @exception Exception If something unexpected happens.
1370: */
1371: public boolean validateUser(String username, String pwd)
1372: throws Exception {
1373: if (SharkEJBUtilities.getEnvType() == 1) {
1374: UserTransaction t = null;
1375: boolean retVal = false;
1376: try {
1377: t = (UserTransaction) new InitialContext()
1378: .lookup(SharkEJBUtilities.TOMCAT_USER_TRANS_JNDI_NAME);
1379: t.begin();
1380: retVal = getSharkObject().validateUser(username, pwd);
1381: t.commit();
1382:
1383: } catch (Exception ex) {
1384: try {
1385: if (t.getStatus() != Status.STATUS_NO_TRANSACTION)
1386: t.rollback();
1387: } catch (Exception ex1) {
1388: ex1.printStackTrace();
1389: }
1390: throw ex;
1391: }
1392:
1393: return retVal;
1394: } else {
1395: return getSharkObject().validateUser(username, pwd);
1396: }
1397: }
1398:
1399: protected UserGroupManagerAdmin getSharkObject() throws Exception {
1400: return (UserGroupManagerAdmin) Shark.getInstance().getPlugIn(
1401: SharkConstants.PLUGIN_USER_GROUP);
1402: }
1403: }
|