2
* $Id: SimpleLoginService.java,v 1.5 2006/05/23 19:07:51 rbair Exp $
4
* Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5
* Santa Clara, California 95054, U.S.A. All rights reserved.
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.
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.
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
22
package org.jdesktop.swingx.auth;
23
import java.util.Arrays;
24
import java.util.HashMap;
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.
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.
39
public final class SimpleLoginService extends LoginService {
40
private Map<String,char[]> passwordMap;
43
* Creates a new SimpleLoginService based on the given password map.
45
public SimpleLoginService(Map<String,char[]> passwordMap) {
46
if (passwordMap == null) {
47
passwordMap = new HashMap<String,char[]>();
49
this.passwordMap = passwordMap;
53
* Attempts to authenticate the given username and password against the password map
55
public boolean authenticate(String name, char[] password, String server) throws Exception {
56
char[] p = passwordMap.get(name);
57
return Arrays.equals(password, p);
2
* $Id: SimpleLoginService.java 3475 2009-08-28 08:30:47Z kleopatra $
4
* Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle,
5
* Santa Clara, California 95054, U.S.A. All rights reserved.
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.
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.
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
22
package org.jdesktop.swingx.auth;
23
import java.util.Arrays;
24
import java.util.HashMap;
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.
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.
39
public final class SimpleLoginService extends LoginService {
40
private Map<String,char[]> passwordMap;
43
* Creates a new SimpleLoginService based on the given password map.
45
public SimpleLoginService(Map<String,char[]> passwordMap) {
46
if (passwordMap == null) {
47
passwordMap = new HashMap<String,char[]>();
49
this.passwordMap = passwordMap;
53
* Attempts to authenticate the given username and password against the password map
56
public boolean authenticate(String name, char[] password, String server) throws Exception {
57
char[] p = passwordMap.get(name);
58
return Arrays.equals(password, p);