source: DASISH/t5.6/backend/annotator-backend/trunk/annotator-backend/src/test/java/eu/dasish/annotation/backend/rest/BCryptTestUserPasswordEncoder.java @ 4209

Last change on this file since 4209 was 4209, checked in by olhsha, 10 years ago

following Eric's instruction in security management in Dasish: removing a separate security DB, making authentication tables the part of the main DB, keeping hashed passwords. Used spring-security configuration for hashes with BCryptPasswordEncoder as recommended.

File size: 2.4 KB
Line 
1/*
2 * Copyright (C) 2013 DASISH
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17 */
18package eu.dasish.annotation.backend.rest;
19
20import java.util.HashMap;
21import java.util.Map;
22import org.junit.Test;
23import org.junit.runner.RunWith;
24import org.springframework.test.context.ContextConfiguration;
25import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
27/**
28 *
29 * @author olhsha
30 */
31@RunWith(value = SpringJUnit4ClassRunner.class)
32@ContextConfiguration({"/spring-test-config/dataSource.xml"})
33public class BCryptTestUserPasswordEncoder {
34   
35    final   Map<String, String> userPassword= new HashMap<String, String>();
36    private Map<String, String> passwordHash= new HashMap<String, String>();
37    private BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
38   
39   
40    public BCryptTestUserPasswordEncoder(){
41        userPassword.put("olha", "olha"+"password");
42        userPassword.put("stephanie", "stephanie"+"password");
43        userPassword.put("olof", "olof"+"password");
44        userPassword.put("twan", "twan"+"password");
45        userPassword.put("peter", "peter"+"password");
46        userPassword.put("przemek", "przemek"+"password");
47        userPassword.put("daan", "daan"+"password");
48        userPassword.put("menzo", "menzo"+"password");
49        userPassword.put("eric", "eric"+"password");
50    }
51   
52   
53    @Test
54    public void generateHashes(){
55        System.out.println("Passwords -- hashes:");
56        for (String user:userPassword.keySet()){
57            String hash = passwordEncoder.encode(userPassword.get(user));
58            System.out.println(userPassword.get(user)+" -- "+hash);
59            passwordHash.put(userPassword.get(user), hash);
60        }
61    }
62}
Note: See TracBrowser for help on using the repository browser.