KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencrx > kernel > layer > application > UserHomes


1 /*
2  * ====================================================================
3  * Project: opencrx, http://www.opencrx.org/
4  * Name: $Id: UserHomes.java,v 1.5 2006/03/31 23:23:05 wfro Exp $
5  * Description: openCRX application plugin
6  * Revision: $Revision: 1.5 $
7  * Owner: CRIXP AG, Switzerland, http://www.crixp.com
8  * Date: $Date: 2006/03/31 23:23:05 $
9  * ====================================================================
10  *
11  * This software is published under the BSD license
12  * as listed below.
13  *
14  * Copyright (c) 2004-2005, CRIXP Corp., Switzerland
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  *
21  * * Redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer.
23  *
24  * * Redistributions in binary form must reproduce the above copyright
25  * notice, this list of conditions and the following disclaimer in
26  * the documentation and/or other materials provided with the
27  * distribution.
28  *
29  * * Neither the name of CRIXP Corp. nor the names of the contributors
30  * to openCRX may be used to endorse or promote products derived
31  * from this software without specific prior written permission
32  *
33  *
34  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
35  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
36  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
37  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
38  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
39  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
40  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
41  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
43  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
44  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
45  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
46  * POSSIBILITY OF SUCH DAMAGE.
47  *
48  * ------------------
49  *
50  * This product includes software developed by the Apache Software
51  * Foundation (http://www.apache.org/).
52  *
53  * This product includes software developed by contributors to
54  * openMDX (http://www.openmdx.org/)
55  */

56
57 package org.opencrx.kernel.layer.application;
58
59 import java.io.BufferedReader JavaDoc;
60 import java.io.ByteArrayInputStream JavaDoc;
61 import java.io.IOException JavaDoc;
62 import java.io.InputStreamReader JavaDoc;
63 import java.io.UnsupportedEncodingException JavaDoc;
64 import java.security.MessageDigest JavaDoc;
65 import java.security.NoSuchAlgorithmException JavaDoc;
66 import java.util.ArrayList JavaDoc;
67 import java.util.Arrays JavaDoc;
68 import java.util.HashSet JavaDoc;
69 import java.util.Iterator JavaDoc;
70 import java.util.List JavaDoc;
71 import java.util.Set JavaDoc;
72 import java.util.StringTokenizer JavaDoc;
73
74 import org.opencrx.kernel.generic.SecurityKeys;
75 import org.openmdx.application.log.AppLog;
76 import org.openmdx.base.accessor.jmi.cci.RefPackage_1_0;
77 import org.openmdx.base.exception.ServiceException;
78 import org.openmdx.base.text.conversion.Base64;
79 import org.openmdx.compatibility.base.dataprovider.cci.AttributeSelectors;
80 import org.openmdx.compatibility.base.dataprovider.cci.AttributeSpecifier;
81 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject;
82 import org.openmdx.compatibility.base.dataprovider.cci.DataproviderObject_1_0;
83 import org.openmdx.compatibility.base.dataprovider.cci.Directions;
84 import org.openmdx.compatibility.base.dataprovider.cci.RequestCollection;
85 import org.openmdx.compatibility.base.dataprovider.cci.ServiceHeader;
86 import org.openmdx.compatibility.base.dataprovider.cci.SystemAttributes;
87 import org.openmdx.compatibility.base.naming.Path;
88 import org.openmdx.compatibility.base.query.FilterOperators;
89 import org.openmdx.compatibility.base.query.FilterProperty;
90 import org.openmdx.compatibility.base.query.Quantors;
91 import org.openmdx.kernel.exception.BasicException;
92 import org.openmdx.kernel.id.UUIDs;
93 import org.openmdx.model1.accessor.basic.cci.Model_1_0;
94
95 public class UserHomes {
96
97     //-----------------------------------------------------------------------
98
public UserHomes(
99         Model_1_0 model,
100         OpenCrxKernel_1 plugin,
101         RequestCollection delegation,
102         String JavaDoc passwordEncodingAlgorithm,
103         RefPackage_1_0 rootPkg
104     ) {
105         this.model = model;
106         this.plugin = plugin;
107         this.delegation = delegation;
108         this.passwordEncodingAlgorithm = passwordEncodingAlgorithm;
109         this.rootPkg = rootPkg;
110     }
111     
112     //-------------------------------------------------------------------------
113
void refreshCharts(
114       ServiceHeader header,
115       DataproviderObject_1_0 userHome
116     ) throws ServiceException {
117
118       Path chartReference = userHome.path().getChild("chart");
119       List JavaDoc charts = new ArrayList JavaDoc();
120       
121       // calculate new charts
122
// id=0,1
123
charts.addAll(
124         Arrays.asList(
125           this.plugin.getContracts().calculateUserHomeCharts(
126             header,
127             userHome.path(),
128             chartReference
129           )
130         )
131       );
132       // id=2,3
133
charts.addAll(
134         Arrays.asList(
135           this.plugin.activities.calculateUserHomeCharts(
136             header,
137             userHome.path(),
138             chartReference
139           )
140         )
141       );
142       
143       // replace existing charts with new charts
144
Set JavaDoc exclude = new HashSet JavaDoc();
145       for(Iterator JavaDoc i = charts.iterator(); i.hasNext(); ) {
146           DataproviderObject chart = (DataproviderObject)i.next();
147           try {
148               DataproviderObject existing = this.plugin.retrieveObjectForModification(chart.path());
149               existing.attributeNames().clear();
150               existing.addClones(chart, true);
151               exclude.add(chart.path());
152           }
153           catch(ServiceException e) {
154               try {
155                   if(e.getExceptionCode() == BasicException.Code.NOT_FOUND) {
156                       this.delegation.addCreateRequest(
157                           chart
158                       );
159                       exclude.add(chart.path());
160                   }
161               }
162               catch(ServiceException e0) {
163                   AppLog.error(e0.getMessage(), e0.getCause(), 1);
164               }
165           }
166       }
167       
168       // remove old charts
169
this.plugin.removeAll(
170           chartReference,
171           null,
172           0,
173           exclude
174       );
175     }
176
177     //-------------------------------------------------------------------------
178
private byte[] getPasswordDigest(
179         String JavaDoc password,
180         String JavaDoc algorithm
181     ) {
182         try {
183             MessageDigest JavaDoc md = MessageDigest.getInstance(algorithm);
184             md.update(password.getBytes("UTF-8"));
185             return md.digest();
186         }
187         catch(NoSuchAlgorithmException JavaDoc e) {
188         }
189         catch(UnsupportedEncodingException JavaDoc e) {
190         }
191         return null;
192     }
193     
194     //-------------------------------------------------------------------------
195
/**
196      * Creates a password credential for the specified subject. The password
197      * is not set by this method. This must be done with changePassword.
198      */

199     private DataproviderObject createPasswordCredential(
200         Path subjectIdentity,
201         List JavaDoc errors
202     ) {
203         String JavaDoc providerName = subjectIdentity.get(2);
204         
205         // create password credential
206
Path passwordIdentity = new Path("xri:@openmdx:org.openmdx.security.authentication1/provider");
207         passwordIdentity = passwordIdentity.getDescendant(
208             new String JavaDoc[]{
209                 providerName,
210                 "segment",
211                 "Root", // credentials are stored in Root segment
212
"credential",
213                 UUIDs.getGenerator().next().toString()
214             }
215         );
216         DataproviderObject passwordCredential = new DataproviderObject(
217             passwordIdentity
218         );
219         passwordCredential.values(SystemAttributes.OBJECT_CLASS).add("org:openmdx:security:authentication1:Password");
220         passwordCredential.values("subject").add(subjectIdentity);
221         passwordCredential.values("locked").add(Boolean.FALSE);
222         try {
223             this.delegation.addCreateRequest(passwordCredential);
224         }
225         catch(Exception JavaDoc e) {
226             ServiceException e0 = new ServiceException(e);
227             AppLog.warning(e0.getMessage(), e0.getCause(), 1);
228             errors.add("can not create password credential");
229             errors.add("reason is " + e.getMessage());
230             return null;
231         }
232         return passwordCredential;
233     }
234     
235     //-------------------------------------------------------------------------
236
private int changePassword(
237         Path passwordCredentialIdentity,
238         String JavaDoc oldPassword,
239         String JavaDoc password
240     ) {
241         DataproviderObject changePasswordParams = new DataproviderObject(
242             passwordCredentialIdentity.getChild("change")
243         );
244         changePasswordParams.values(SystemAttributes.OBJECT_CLASS).add(
245             "org:openmdx:security:authentication1:PasswordChangeParams"
246         );
247         if(oldPassword != null) {
248             changePasswordParams.values("oldPassword").add(this.getPasswordDigest(oldPassword, this.passwordEncodingAlgorithm));
249         }
250         if(password == null) {
251             return MISSING_NEW_PASSWORD;
252         }
253         changePasswordParams.values("password").add(this.getPasswordDigest(password, this.passwordEncodingAlgorithm));
254         try {
255             RequestCollection runAsRootDelegation = this.plugin.getRunAsRootDelegation();
256             runAsRootDelegation.addOperationRequest(changePasswordParams);
257         }
258         catch(ServiceException e) {
259             AppLog.warning(e.getMessage(), e.getCause(), 1);
260             return CAN_NOT_CHANGE_PASSWORD;
261         }
262         return CHANGE_PASSWORD_OK;
263     }
264     
265     //-------------------------------------------------------------------------
266
public int changePassword(
267         DataproviderObject_1_0 userHome,
268         Path realmIdentity,
269         boolean verifyOldPassword,
270         String JavaDoc oldPassword,
271         String JavaDoc newPassword,
272         String JavaDoc newPasswordVerification
273     ) {
274         if(newPassword == null) {
275             return MISSING_NEW_PASSWORD;
276         }
277         if(newPasswordVerification == null) {
278             return MISSING_NEW_PASSWORD_VERIFICATION;
279         }
280         if(!newPassword.equals(newPasswordVerification)) {
281             return PASSWORD_VERIFICATION_MISMATCH;
282         }
283         if(verifyOldPassword && oldPassword == null) {
284             return MISSING_OLD_PASSWORD;
285         }
286         
287         // qualifier of user home is the principal name
288
String JavaDoc principalName = userHome.path().getBase();
289         
290         // get principal
291
DataproviderObject principal = null;
292         try {
293             principal =
294                 new DataproviderObject(
295                     this.delegation.addGetRequest(
296                         realmIdentity.getDescendant(new String JavaDoc[]{"principal", principalName}),
297                         AttributeSelectors.ALL_ATTRIBUTES,
298                         new AttributeSpecifier[]{}
299                     )
300                 );
301         }
302         catch(Exception JavaDoc e) {
303             ServiceException e0 = new ServiceException(e);
304             AppLog.warning(e0.getMessage(), e0.getCause(), 1);
305             return CAN_NOT_RETRIEVE_REQUESTED_PRINCIPAL;
306         }
307
308         return this.changePassword(
309             (Path)principal.values("credential").get(0),
310             verifyOldPassword ? oldPassword : null,
311             newPassword
312         );
313     }
314     
315     //-------------------------------------------------------------------------
316
/**
317      * Creates a new user. The owner of the created objects are set as follows:
318      * <ul>
319      * <li>user subject: segment administrator
320      * <li>all other objects (user home, password): user
321      * </ul>
322      */

323     DataproviderObject_1_0 createUserHome(
324         Path loginRealmIdentity,
325         Path realmIdentity,
326         Path contactIdentity,
327         Path primaryGroup,
328         String JavaDoc principalName,
329         boolean isAdministrator,
330         String JavaDoc initialPassword,
331         String JavaDoc initialPasswordVerification,
332         List JavaDoc errors
333     ) {
334         if(principalName == null) {
335             errors.add("missing principalName");
336             return null;
337         }
338         if(contactIdentity == null) {
339             errors.add("missing contact");
340             return null;
341         }
342         
343         // Get login principal. Get subject and set password credential
344
Path subjectIdentity = null;
345         try {
346             DataproviderObject_1_0 loginPrincipal = this.plugin.retrieveObjectForModification(
347                 loginRealmIdentity.getDescendant(new String JavaDoc[]{"principal", principalName})
348             );
349             if(loginPrincipal.values("subject").size() == 0) {
350                 errors.add("Undefined subject for principal " + loginPrincipal.path());
351                 return null;
352             }
353             subjectIdentity = (Path)loginPrincipal.values("subject").get(0);
354             // Create password credential
355
if((initialPassword != null) && (initialPassword.length() > 0)) {
356                 DataproviderObject passwordCredential = this.createPasswordCredential(
357                     subjectIdentity,
358                     errors
359                 );
360                 if(passwordCredential == null) {
361                     return null;
362                 }
363                 // Set initial password
364
this.changePassword(
365                     passwordCredential.path(),
366                     null,
367                     initialPassword
368                 );
369                 // Update principal's credential
370
loginPrincipal.clearValues("credential").add(passwordCredential.path());
371             }
372             if((loginPrincipal.getValues("credential") == null) || (loginPrincipal.getValues("credential").size() == 0)) {
373                 errors.add("No credential specified for principal " + principalName);
374             }
375         }
376         catch(Exception JavaDoc e) {
377             ServiceException e1 = new ServiceException(e);
378             AppLog.warning(e1.getMessage(), e1.getCause(), 1);
379             errors.add("can not retrieve principal " + principalName + " in realm " + loginRealmIdentity);
380             errors.add("reason is " + e.getMessage());
381             return null;
382         }
383         
384         // Add user principal
385
Path userIdentity = this.plugin.createPrincipal(
386             principalName + "." + SecurityKeys.USER_SUFFIX,
387             realmIdentity,
388             SecurityKeys.PRINCIPAL_TYPE_USER,
389             new Path[]{},
390             subjectIdentity,
391             errors
392         );
393         if(errors.size() > 0) return null;
394
395         Path groupAdministratorsIdentity = userIdentity.getParent().getChild(SecurityKeys.USER_GROUP_ADMINISTRATORS);
396         Path groupUsersIdentity = userIdentity.getParent().getChild(SecurityKeys.USER_GROUP_USERS);
397         
398         // Add principal
399
this.plugin.createPrincipal(
400             principalName,
401             realmIdentity,
402             SecurityKeys.PRINCIPAL_TYPE_PRINCIPAL,
403             isAdministrator
404                 ? new Path[]{
405                     groupAdministratorsIdentity,
406                     groupUsersIdentity,
407                     userIdentity
408                 }
409                 : new Path[]{
410                     groupUsersIdentity,
411                     userIdentity
412                 },
413             subjectIdentity,
414             errors
415         );
416         if(errors.size() > 0) return null;
417
418         // Add principal to Root realm (each principal should be registered
419
// in the Root realm because the Root segment provides data common
420
// to all segments, e.g. code tables
421
this.plugin.createPrincipal(
422             principalName,
423             realmIdentity.getParent().getChild("Root"),
424             SecurityKeys.PRINCIPAL_TYPE_PRINCIPAL,
425             new Path[]{},
426             subjectIdentity,
427             errors
428         );
429         if(errors.size() > 0) return null;
430
431         // Add user principal to Root realm
432
this.plugin.createPrincipal(
433             principalName + "." + SecurityKeys.USER_SUFFIX,
434             realmIdentity.getParent().getChild("Root"),
435             SecurityKeys.PRINCIPAL_TYPE_USER,
436             new Path[]{},
437             subjectIdentity,
438             errors
439         );
440         if(errors.size() > 0) return null;
441         
442         String JavaDoc providerName = contactIdentity.get(2);
443         String JavaDoc segmentName = contactIdentity.get(4);
444         
445         initialPassword = initialPassword == null ? "" : initialPassword;
446         initialPasswordVerification = initialPasswordVerification == null ? "" : initialPasswordVerification;
447         if(!initialPassword.equals(initialPasswordVerification)) {
448             errors.add("the passwords you typed do not match");
449             return null;
450         }
451         
452         /**
453          * User home
454          */

455         Path userHomeReference = new Path("xri:@openmdx:org.opencrx.kernel.home1");
456         userHomeReference = userHomeReference.getDescendant(
457             new String JavaDoc[]{"provider", providerName, "segment", segmentName, "userHome"}
458         );
459         DataproviderObject_1_0 userHome = null;
460         try {
461             userHome = this.delegation.addGetRequest(
462                 userHomeReference.getChild(principalName),
463                 AttributeSelectors.ALL_ATTRIBUTES,
464                 new AttributeSpecifier[]{}
465             );
466         }
467         catch(Exception JavaDoc e) {
468             DataproviderObject newUserHome = new DataproviderObject(
469                 userHomeReference.getChild(principalName)
470             );
471             newUserHome.values(SystemAttributes.OBJECT_CLASS).add("org:opencrx:kernel:home1:UserHome");
472             newUserHome.values("contact").add(contactIdentity);
473             newUserHome.clearValues("primaryGroup").add(primaryGroup);
474             // owning user of home is user itself
475
newUserHome.values("owningUser").add(userIdentity);
476             // owning group of home is segment administrator
477
newUserHome.values("owningGroup").addAll(
478                 Arrays.asList(
479                     new Path[]{
480                         groupAdministratorsIdentity
481                     }
482                 )
483             );
484             // access level delete
485
newUserHome.values("accessLevelDelete").add(
486                 new Short JavaDoc((short)0)
487             );
488             newUserHome.values("accessLevelDelete").add(new Short JavaDoc(SecurityKeys.ACCESS_LEVEL_PRIVATE));
489             this.plugin.initCharts(newUserHome, null);
490             
491             try {
492                 this.delegation.addCreateRequest(newUserHome);
493             }
494             catch(Exception JavaDoc e0) {
495                 ServiceException e1 = new ServiceException(e0);
496                 AppLog.warning(e1.getMessage(), e1.getCause(), 1);
497                 errors.add("can not create user home");
498                 errors.add("reason is " + e.getMessage());
499                 return null;
500             }
501             userHome = newUserHome;
502         }
503         return userHome;
504     }
505
506     //-----------------------------------------------------------------------
507
private DataproviderObject_1_0 retrieveUserHome(
508         Path userHomeSegment,
509         String JavaDoc principalName
510     ) {
511         try {
512             return this.plugin.retrieveObjectFromDelegation(
513                 userHomeSegment.getDescendant(new String JavaDoc[]{"userHome", principalName})
514             );
515         }
516         catch(Exception JavaDoc e) {
517             return null;
518         }
519     }
520     
521     //-----------------------------------------------------------------------
522
private DataproviderObject_1_0 retrieveContact(
523         Path accountSegment,
524         String JavaDoc aliasName,
525         String JavaDoc fullName
526     ) {
527         try {
528             FilterProperty[] filter = null;
529             if(!"-".equals(aliasName)) {
530                 filter = new FilterProperty[]{
531                     new FilterProperty(
532                         Quantors.THERE_EXISTS,
533                         "aliasName",
534                         FilterOperators.IS_IN,
535                         new String JavaDoc[]{aliasName}
536                     )
537                 };
538             }
539             else if(!"-".equals(fullName)) {
540                 filter = new FilterProperty[]{
541                     new FilterProperty(
542                         Quantors.THERE_EXISTS,
543                         "fullName",
544                         FilterOperators.IS_IN,
545                         new String JavaDoc[]{fullName}
546                     )
547                 };
548             }
549             List JavaDoc accounts = this.delegation.addFindRequest(
550                 accountSegment.getChild("account"),
551                 filter
552             );
553             if(accounts.size() > 0) {
554                 return (DataproviderObject_1_0)accounts.iterator().next();
555             }
556             else {
557                 return null;
558             }
559         }
560         catch(Exception JavaDoc e) {
561             return null;
562         }
563     }
564         
565     //-----------------------------------------------------------------------
566
private DataproviderObject_1_0 retrievePrincipal(
567         Path realm,
568         String JavaDoc principalName
569     ) {
570         try {
571             return this.plugin.retrieveObjectFromDelegation(
572                 realm.getDescendant(new String JavaDoc[]{"principal", principalName})
573             );
574         }
575         catch(Exception JavaDoc e) {
576             return null;
577         }
578     }
579     
580     //-------------------------------------------------------------------------
581
public String JavaDoc importUsers(
582         DataproviderObject_1_0 homeSegment,
583         byte[] item
584     ) throws ServiceException {
585         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(
586             new InputStreamReader JavaDoc(new ByteArrayInputStream JavaDoc(item))
587         );
588         DataproviderObject_1_0 realm = this.plugin.retrieveObjectFromDelegation(
589             new Path("xri:@openmdx:org.openmdx.security.realm1/provider/" + homeSegment.path().get(2) + "/segment/Root/realm/" + homeSegment.path().get(4))
590         );
591         DataproviderObject_1_0 accountSegment = this.plugin.retrieveObjectFromDelegation(
592             new Path("xri:@openmdx:org.opencrx.kernel.account1/provider/" + homeSegment.path().get(2) + "/segment/" + homeSegment.path().get(4))
593         );
594         Path loginRealmIdentity =
595             new Path("xri:@openmdx:org.openmdx.security.realm1/provider/" + homeSegment.path().get(2) + "/segment/Root/realm/Default");
596
597         int nCreatedUsers = 0;
598         int nFailedUsersNoPrimaryGroup = 0;
599         int nFailedUsersNoContact = 0;
600         int nFailedUsersOther = 0;
601         int nExistingUsers = 0;
602         try {
603             while(reader.ready()) {
604                 String JavaDoc l = reader.readLine();
605                 if(l.startsWith("User")) {
606                     StringTokenizer JavaDoc t = new StringTokenizer JavaDoc(l, ";");
607                     String JavaDoc command = t.nextToken();
608                     String JavaDoc principalName = t.nextToken();
609                     String JavaDoc accountAlias = t.nextToken();
610                     String JavaDoc accountFullName = t.nextToken();
611                     String JavaDoc primaryGroupName = t.nextToken();
612                     String JavaDoc password = t.nextToken();
613                     if(this.retrieveUserHome(homeSegment.path(), principalName) == null) {
614                         try {
615                             DataproviderObject_1_0 contact = this.retrieveContact(accountSegment.path(), accountAlias, accountFullName);
616                             if(contact != null) {
617                                 DataproviderObject_1_0 primaryGroup = this.retrievePrincipal(realm.path(), primaryGroupName);
618                                 if(primaryGroup != null) {
619                                     List JavaDoc errors = new ArrayList JavaDoc();
620                                     this.createUserHome(
621                                         loginRealmIdentity,
622                                         realm.path(),
623                                         contact.path(),
624                                         primaryGroup.path(),
625                                         principalName,
626                                         false,
627                                         password,
628                                         password,
629                                         errors
630                                     );
631                                     if(errors.size() == 0) {
632                                         nCreatedUsers++;
633                                     }
634                                     else {
635                                         nFailedUsersOther++;
636                                     }
637                                 }
638                                 else {
639                                     AppLog.info("Group " + primaryGroup + " for user " + principalName + " not found");
640                                     nFailedUsersNoPrimaryGroup++;
641                                 }
642                             }
643                             else {
644                                 AppLog.info("Contact " + accountAlias + "/" + accountFullName + " for user " + principalName + " not found");
645                                 nFailedUsersNoContact++;
646                             }
647                         }
648                         catch(Exception JavaDoc e) {
649                             new ServiceException(e).log();
650                             nFailedUsersOther++;
651                         }
652                     }
653                     else {
654                         nExistingUsers++;
655                     }
656                 }
657             }
658         }
659         catch(IOException JavaDoc e) {
660             new ServiceException(e).log();
661         }
662         return
663             "Users=(created:" + nCreatedUsers + ",existing:" + nExistingUsers + ",failed no primary group:" + nFailedUsersNoPrimaryGroup + ",failed no contact:" + nFailedUsersNoContact + ",failed other:" + nFailedUsersOther + ");";
664     }
665     
666     //-------------------------------------------------------------------------
667
public void encodeEMailAccountPassword(
668         DataproviderObject object,
669         DataproviderObject_1_0 oldValues
670     ) throws ServiceException {
671         String JavaDoc objectClass = (String JavaDoc)object.values(SystemAttributes.OBJECT_CLASS).get(0);
672         if(this.model.isSubtypeOf(objectClass, "org:opencrx:kernel:home1:EMailAccount")) {
673             if(object.getValues("incomingPassword") != null) {
674                 try {
675                     String JavaDoc password = (String JavaDoc)object.values("incomingPassword").get(0);
676                     if((password != null) && !password.startsWith(SecurityKeys.PASSWORD_ENCODING_SCHEME)) {
677                         object.clearValues("incomingPassword").add(
678                             SecurityKeys.PASSWORD_ENCODING_SCHEME + Base64.encode(password.getBytes("UTF-8"))
679                         );
680                     }
681                 } catch(UnsupportedEncodingException JavaDoc e) {}
682             }
683             if(object.getValues("outgoingPassword") != null) {
684                 try {
685                     String JavaDoc password = (String JavaDoc)object.values("outgoingPassword").get(0);
686                     if((password != null) && !password.startsWith(SecurityKeys.PASSWORD_ENCODING_SCHEME)) {
687                         object.clearValues("outgoingPassword").add(
688                             SecurityKeys.PASSWORD_ENCODING_SCHEME + Base64.encode(password.getBytes("UTF-8"))
689                         );
690                     }
691                 } catch(UnsupportedEncodingException JavaDoc e) {}
692             }
693         }
694     }
695     
696     //-------------------------------------------------------------------------
697
public List JavaDoc completeUserHome(
698       ServiceHeader header,
699       DataproviderObject_1_0 userHome
700     ) throws ServiceException {
701         List JavaDoc additionalFetchedObjects = new ArrayList JavaDoc();
702         try {
703             List JavaDoc charts = this.delegation.addFindRequest(
704                 userHome.path().getChild("chart"),
705                 null,
706                 AttributeSelectors.ALL_ATTRIBUTES,
707                 null,
708                 0, Integer.MAX_VALUE,
709                 Directions.ASCENDING
710             );
711             for(
712                 int i = 0;
713                 i < 4;
714                 i++
715             ) {
716                 // Touch so that attributes are in fetch set
717
userHome.values("favoriteChart" + i);
718                 userHome.values("favoriteChart" + i + "MimeType");
719                 userHome.values("favoriteChart" + i + "Name");
720                 userHome.values("favoriteChart" + i + "Description");
721                 if(userHome.getValues("chart" + i).size() > 0) {
722                     for(
723                         Iterator JavaDoc j = charts.iterator();
724                         j.hasNext();
725                     ) {
726                         DataproviderObject_1_0 chart = (DataproviderObject_1_0)j.next();
727                         if(chart.path().equals(userHome.getValues("chart" + i).get(0))) {
728                             userHome.values("favoriteChart" + i).addAll(
729                                 chart.values("chart")
730                             );
731                             userHome.values("favoriteChart" + i + "MimeType").addAll(
732                                 chart.values("chartMimeType")
733                             );
734                             userHome.values("favoriteChart" + i + "Name").addAll(
735                                 chart.values("chartName")
736                             );
737                             userHome.values("favoriteChart" + i + "Description").addAll(
738                                 chart.values("description")
739                             );
740                             additionalFetchedObjects.add(chart);
741                             break;
742                         }
743                     }
744                 }
745             }
746         }
747         // ignore if charts can not be retrieved
748
catch(ServiceException e) {}
749         return additionalFetchedObjects;
750     }
751     
752     //-------------------------------------------------------------------------
753
// Members
754
//-------------------------------------------------------------------------
755
private static final short CHANGE_PASSWORD_OK = 0;
756     private static final short MISSING_NEW_PASSWORD = 1;
757     private static final short MISSING_NEW_PASSWORD_VERIFICATION = 2;
758     private static final short PASSWORD_VERIFICATION_MISMATCH = 3;
759     private static final short CAN_NOT_RETRIEVE_REQUESTED_PRINCIPAL = 4;
760     private static final short CAN_NOT_CHANGE_PASSWORD = 5;
761     private static final short MISSING_OLD_PASSWORD = 6;
762
763     private final Model_1_0 model;
764     private final OpenCrxKernel_1 plugin;
765     private final RequestCollection delegation;
766     private final String JavaDoc passwordEncodingAlgorithm;
767     private final RefPackage_1_0 rootPkg;
768         
769 }
770
771 //--- End of File -----------------------------------------------------------
772
Popular Tags