/*
|
jwtTest - JSON Web Token Testimplementierung
|
Copyright (C) 2021 Ulrich Hilger
|
|
This program is free software: you can redistribute it and/or modify
|
it under the terms of the GNU Affero General Public License as
|
published by the Free Software Foundation, either version 3 of the
|
License, or (at your option) any later version.
|
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU Affero General Public License for more details.
|
|
You should have received a copy of the GNU Affero General Public License
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
*/
|
package de.uhilger.httpserver.auth.realm;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
*
|
* @author Ulrich Hilger
|
* @version 1, 22.05.2021
|
*/
|
public class TestRealm implements Realm {
|
|
private String name = "Testverzeichnis";
|
|
private Map nutzerMap;
|
|
private Map rollenMap;
|
|
public TestRealm() {
|
nutzerMap = new HashMap();
|
User nutzer = new User();
|
nutzer.setName("test");
|
nutzer.setPassword("test");
|
nutzerMap.put(nutzer.getName(), nutzer);
|
|
rollenMap = new HashMap();
|
List nutzerRollen = new ArrayList();
|
nutzerRollen.add("testRolle");
|
rollenMap.put(nutzer.getName(), nutzerRollen);
|
}
|
|
/**
|
* Uberpruefen, ob die Benutzerkennung und das Kennwort gueltig sind.
|
*
|
* @param nutzerId
|
* @param kennwort
|
* @return
|
*/
|
public boolean isValid(String nutzerId, String kennwort) {
|
Object o = nutzerMap.get(nutzerId);
|
if(o instanceof User) {
|
User nutzer = (User) o;
|
if(nutzer.getPassword().equals(kennwort)) {
|
return true;
|
} else {
|
return false;
|
}
|
} else {
|
return false;
|
}
|
}
|
|
public String getName() {
|
return name;
|
}
|
|
public void setName(String name) {
|
this.name = name;
|
}
|
|
@Override
|
public boolean hasRole(String nutzerId, String rollenId) {
|
Object o = rollenMap.get(nutzerId);
|
if(o instanceof List) {
|
List nutzerRollen = (List) o;
|
return nutzerRollen.contains(rollenId);
|
} else {
|
return false;
|
}
|
}
|
}
|