001: /**
002: *
003: * Bonita
004: * Copyright (C) 1999 Bull S.A.
005: * Bull 68 route de versailles 78434 Louveciennes Cedex France
006: * Further information: bonita@objectweb.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: *
024: --------------------------------------------------------------------------
025: * $Id: ClientUpdateBn.java,v 1.1 2004/07/30 14:57:58 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.client.importLdap;
029:
030: /*
031: *
032: * ClientUpdateBn.java
033: *
034: *
035: * This program is free software; you can redistribute it and/or
036: * modify it under the terms of the GNU Lesser General Public License
037: * as published by the Free Software Foundation; either version 2
038: * of the License, or (at your option) any later version.
039: *
040: * This program is distributed in the hope that it will be useful,
041: * but WITHOUT ANY WARRANTY; without even the implied warranty of
042: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
043: * GNU Lesser General Public License for more details.
044: *
045: * You should have received a copy of the GNU Lesser General Public License
046: * along with this program; if not, write to the Free Software
047: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
048: */
049:
050: // utilisation du BnLdap Bean
051: import hero.interfaces.BnLdap;
052: import hero.interfaces.BnLdapHome;
053: import hero.interfaces.BnLdapUtil;
054:
055: // for J2EE security / for authentication with projectManagerBean
056: import javax.security.auth.login.LoginContext;
057: import javax.security.auth.login.LoginException;
058:
059: /**
060: * Sample for Session Bean.
061: * Usage:
062: * java bnldap.ClientUpdateBn
063: */
064: public class ClientUpdateBn {
065:
066: /****************************************************************
067: main
068: ***************************************************************/
069: public static void main(String args[]) {
070:
071: /****************************
072: Authentication
073: *****************************/
074: char[] password = args[1].toCharArray();
075: SimpleCallbackHandler handler = new SimpleCallbackHandler(
076: args[0], password);
077: try {
078: LoginContext lc = new LoginContext("TestClient", handler);
079: lc.login();
080: } catch (LoginException e) {
081: System.err
082: .println("Error Client while trying the authentication");
083: e.printStackTrace();
084:
085: }
086:
087: // Connecting to BnLdapHome thru JNDI
088: BnLdapHome home = null;
089: try {
090: home = BnLdapUtil.getHome();
091: } catch (Exception e) {
092: System.err.println("Cannot lookup BnLdapHome: " + e);
093: System.exit(2);
094: }
095:
096: // BnLdapBean creation
097: BnLdap t1 = null;
098: try {
099: System.out.println("Create a bean bnLdap");
100: t1 = home.create();
101: } catch (Exception e) {
102: System.err.println("Cannot create BnLdapBean : " + e);
103: System.exit(2);
104: }
105:
106: /*******************************
107: Import users in bonita database
108: ********************************/
109:
110: try {
111: t1.importLdapUsers();
112: } catch (Exception e) {
113: System.err
114: .println("Error Importing users from Ldap to Bonita database: "
115: + e);
116: System.exit(2);
117: }
118:
119: /**********************
120: Remove Session Bean: BnLdapbean
121: **********************/
122: try {
123: t1.remove();
124: } catch (Exception e) {
125: System.out.println("Exception removing the BnLdap bean: "
126: + e);
127: System.exit(2);
128: }
129: System.out.println("BnLdapbean removed.");
130: }
131:
132: }
|