2 * Copyright (c) 2015, 2017 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.aaa.shiro.idm.persistence;
11 import java.util.ArrayList;
12 import java.util.LinkedList;
13 import java.util.List;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.mockito.Mockito;
17 import org.opendaylight.aaa.shiro.AAAShiroProvider;
18 import org.opendaylight.aaa.api.IDMStoreException;
19 import org.opendaylight.aaa.api.IIDMStore;
20 import org.opendaylight.aaa.api.PasswordCredentials;
21 import org.opendaylight.aaa.api.SHA256Calculator;
22 import org.opendaylight.aaa.api.model.Domain;
23 import org.opendaylight.aaa.api.model.Grant;
24 import org.opendaylight.aaa.api.model.Grants;
25 import org.opendaylight.aaa.api.model.Role;
26 import org.opendaylight.aaa.api.model.User;
27 import org.opendaylight.aaa.api.model.Users;
28 import org.opendaylight.aaa.shiro.idm.IdmLightProxy;
31 * @Author - Sharon Aicler (saichler@cisco.com)
33 public class PasswordHashTest {
36 public void before() throws IDMStoreException {
37 IIDMStore store = Mockito.mock(IIDMStore.class);
38 AAAShiroProvider.setIdmStore(store);
39 Domain domain = new Domain();
40 domain.setName("sdn");
41 domain.setDomainid("sdn");
43 Mockito.when(store.readDomain("sdn")).thenReturn(domain);
44 Creds creds = new Creds();
46 User user = new User();
47 user.setName("admin");
48 user.setUserid(creds.username());
49 user.setDomainid("sdn");
51 user.setPassword(SHA256Calculator.getSHA256(creds.password(), user.getSalt()));
52 List<User> lu = new LinkedList<>();
54 Users users = new Users();
57 Grant grant = new Grant();
58 List<Grant> listOfGrants = new ArrayList<>();
59 listOfGrants.add(grant);
60 grant.setDomainid("sdn");
61 grant.setRoleid("admin");
62 grant.setUserid("admin");
63 Grants grants = new Grants();
64 grants.setGrants(listOfGrants);
65 Role role = new Role();
66 role.setRoleid("admin");
67 role.setName("admin");
68 Mockito.when(store.readRole("admin")).thenReturn(role);
69 Mockito.when(store.getUsers(creds.username(), creds.domain())).thenReturn(users);
70 Mockito.when(store.getGrants(creds.domain(), creds.username())).thenReturn(grants);
74 public void testPasswordHash() {
75 IdmLightProxy proxy = new IdmLightProxy();
76 proxy.authenticate(new Creds());
79 private static class Creds implements PasswordCredentials {
81 public String username() {
86 public String password() {
91 public String domain() {