~ubuntu-branches/ubuntu/lucid/libswingx-java/lucid

« back to all changes in this revision

Viewing changes to src/java/org/jdesktop/swingx/auth/SimpleLoginService.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2009-12-30 21:58:46 UTC
  • mfrom: (4.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20091230215846-k1ndl4vhrkxk3wsp
Tags: 1:1.6-1
* New upstream release.
  - remove debian/patches/swingworker.diff (merged upstream)
  - update debian/patches/pom.diff
* Depends on java6-runtime-headless as we build java6 bytecode

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: SimpleLoginService.java,v 1.5 2006/05/23 19:07:51 rbair Exp $
3
 
 *
4
 
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5
 
 * Santa Clara, California 95054, U.S.A. All rights reserved.
6
 
 *
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Lesser General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2.1 of the License, or (at your option) any later version.
11
 
 * 
12
 
 * This library is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Lesser General Public License for more details.
16
 
 * 
17
 
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this library; if not, write to the Free Software
19
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
 
 */
21
 
 
22
 
package org.jdesktop.swingx.auth;
23
 
import java.util.Arrays;
24
 
import java.util.HashMap;
25
 
import java.util.Map;
26
 
 
27
 
/**
28
 
 * An implementation of LoginService that simply matches
29
 
 * the username/password against a list of known users and their passwords.
30
 
 * This is useful for demos or prototypes where a proper login server is not available.
31
 
 *
32
 
 * <em>This Implementation is NOT secure. DO NOT USE this in a real application</em>
33
 
 * To make this implementation more secure, the passwords should be passed in and
34
 
 * stored as the result of a one way hash algorithm. That way an attacker cannot 
35
 
 * simply read the password in memory to crack into the system.
36
 
 *
37
 
 * @author rbair
38
 
 */
39
 
public final class SimpleLoginService extends LoginService {
40
 
    private Map<String,char[]> passwordMap;
41
 
    
42
 
    /**
43
 
     * Creates a new SimpleLoginService based on the given password map.
44
 
     */
45
 
    public SimpleLoginService(Map<String,char[]> passwordMap) {
46
 
        if (passwordMap == null) {
47
 
            passwordMap = new HashMap<String,char[]>();
48
 
        }
49
 
        this.passwordMap = passwordMap;
50
 
    }
51
 
 
52
 
    /**
53
 
     * Attempts to authenticate the given username and password against the password map
54
 
     */
55
 
    public boolean authenticate(String name, char[] password, String server) throws Exception {
56
 
        char[] p = passwordMap.get(name);
57
 
        return Arrays.equals(password, p);
58
 
    }
59
 
}
 
1
/*
 
2
 * $Id: SimpleLoginService.java 3475 2009-08-28 08:30:47Z kleopatra $
 
3
 *
 
4
 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
 
5
 * Santa Clara, California 95054, U.S.A. All rights reserved.
 
6
 *
 
7
 * This library is free software; you can redistribute it and/or
 
8
 * modify it under the terms of the GNU Lesser General Public
 
9
 * License as published by the Free Software Foundation; either
 
10
 * version 2.1 of the License, or (at your option) any later version.
 
11
 * 
 
12
 * This library is distributed in the hope that it will be useful,
 
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
15
 * Lesser General Public License for more details.
 
16
 * 
 
17
 * You should have received a copy of the GNU Lesser General Public
 
18
 * License along with this library; if not, write to the Free Software
 
19
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
20
 */
 
21
 
 
22
package org.jdesktop.swingx.auth;
 
23
import java.util.Arrays;
 
24
import java.util.HashMap;
 
25
import java.util.Map;
 
26
 
 
27
/**
 
28
 * An implementation of LoginService that simply matches
 
29
 * the username/password against a list of known users and their passwords.
 
30
 * This is useful for demos or prototypes where a proper login server is not available.
 
31
 *
 
32
 * <em>This Implementation is NOT secure. DO NOT USE this in a real application</em>
 
33
 * To make this implementation more secure, the passwords should be passed in and
 
34
 * stored as the result of a one way hash algorithm. That way an attacker cannot 
 
35
 * simply read the password in memory to crack into the system.
 
36
 *
 
37
 * @author rbair
 
38
 */
 
39
public final class SimpleLoginService extends LoginService {
 
40
    private Map<String,char[]> passwordMap;
 
41
    
 
42
    /**
 
43
     * Creates a new SimpleLoginService based on the given password map.
 
44
     */
 
45
    public SimpleLoginService(Map<String,char[]> passwordMap) {
 
46
        if (passwordMap == null) {
 
47
            passwordMap = new HashMap<String,char[]>();
 
48
        }
 
49
        this.passwordMap = passwordMap;
 
50
    }
 
51
 
 
52
    /**
 
53
     * Attempts to authenticate the given username and password against the password map
 
54
     */
 
55
    @Override
 
56
    public boolean authenticate(String name, char[] password, String server) throws Exception {
 
57
        char[] p = passwordMap.get(name);
 
58
        return Arrays.equals(password, p);
 
59
    }
 
60
}