| | |
| | | /* |
| | | * To change this license header, choose License Headers in Project Properties. |
| | | * To change this template file, choose Tools | Templates |
| | | * and open the template in the editor. |
| | | http-auth - Authentication Extensions to jdk.httpserver |
| | | 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.io.File; |
| | | import java.io.FileReader; |
| | | import java.io.IOException; |
| | | import java.security.InvalidKeyException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.security.spec.InvalidKeySpecException; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.logging.Level; |
| | | import java.util.logging.Logger; |
| | | import javax.crypto.BadPaddingException; |
| | | import javax.crypto.IllegalBlockSizeException; |
| | | import javax.crypto.NoSuchPaddingException; |
| | | |
| | | /** |
| | | * |
| | | * Eine einfache Implementierung der Schnittstelle Realm, die |
| | | * Benutzerinformationen aus einer Datei liest. Die Datei ist dabei |
| | | * wie folgt aufgebaut. |
| | | * |
| | | * test=test,testRolle |
| | | * ulrich=ulrich,testRolle,andereRolle |
| | | * |
| | | * Der erste Eintrag nach dem Gleichheitszeichen ist das Passwort, die restlichen |
| | | * Eintrage sind Rollen. |
| | | * |
| | | * @author Ulrich Hilger |
| | | * @version 1, 03.06.2021 |
| | |
| | | |
| | | private static final Logger logger = Logger.getLogger(SimpleRealm.class.getName()); |
| | | |
| | | |
| | | public static final String LIST_INDICATOR = "="; |
| | | public static final String ROLE_SEPARATOR = ","; |
| | | public static final String COMMENT_INDICATOR = "#"; |
| | | |
| | | private String name; |
| | | private Map<String, User> users; |
| | | private Map<String, List> userRoles; |
| | | private final Map<String, User> users; |
| | | private final Map<String, List> userRoles; |
| | | |
| | | public SimpleRealm() { |
| | | users = new HashMap<>(); |