KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > passwdchanger > PasswdChangerService


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2002 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.passwdchanger;
20
21 import org.lucane.common.*;
22 import org.lucane.server.*;
23 import org.lucane.common.concepts.UserConcept;
24 import org.lucane.common.net.ObjectConnection;
25 import org.lucane.server.store.UserStore;
26
27 import java.util.StringTokenizer JavaDoc;
28
29 public class PasswdChangerService
30   extends Service
31 {
32   Server parent;
33
34   public PasswdChangerService()
35   {
36   }
37
38   public void process(ObjectConnection sc, Message message)
39   {
40     String JavaDoc line = (String JavaDoc)message.getData();
41     String JavaDoc from = message.getSender().getName();
42     
43     if(line != null)
44     {
45       StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc(line);
46       String JavaDoc command = stk.nextToken();
47       String JavaDoc data = null;
48
49       try
50       {
51         data = stk.nextToken("\0");
52       }
53       catch(Exception JavaDoc e)
54       {
55         data = "";
56       }
57
58       if(command.equals("CHANGE_PASSWD"))
59         this.changePasswd(from, data, sc);
60     }
61   }
62
63   public void init(Server parent)
64   {
65     this.parent = parent;
66   }
67
68   private void changePasswd(String JavaDoc who, String JavaDoc data, ObjectConnection sc)
69   {
70     UserStore um = parent.getStore().getUserStore();
71     UserConcept user = null;
72     try {
73         user = um.getUser(who);
74     } catch(Exception JavaDoc e) {}
75     
76     StringTokenizer JavaDoc stk = new StringTokenizer JavaDoc(data);
77     String JavaDoc pold = stk.nextToken();
78     String JavaDoc pnew = stk.nextToken();
79     String JavaDoc pass = user.getPassword();
80
81     if(! pass.equals(pold))
82     {
83         try {
84               sc.write("BAD_PASSWD");
85         } catch(Exception JavaDoc e) {}
86       return;
87     }
88     
89     user.setPassword(pnew);
90     try {
91         um.updateUser(user);
92         sc.write("PASSWD_CHANGED");
93     } catch(Exception JavaDoc e) {
94         Logging.getLogger().warning("error : " + e);
95     }
96   }
97 }
Popular Tags