]> git.basschouten.com Git - openhab-addons.git/blob
30da6eb6bc4b03051166a9b71ac24f764ba00d81
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License 2.0 which is available at
9  * http://www.eclipse.org/legal/epl-2.0
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.asuswrt.internal.structures;
14
15 import java.util.Base64;
16
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18
19 /**
20  * This class is used for storing Asuswrt credentials.
21  *
22  * @author Christian Wild - Initial contribution
23  */
24 @NonNullByDefault
25 public class AsuswrtCredentials {
26     private String username = "";
27     private String password = "";
28     private String encodedCredentials = "";
29
30     public AsuswrtCredentials() {
31     }
32
33     public AsuswrtCredentials(AsuswrtConfiguration routerConfig) {
34         setCredentials(routerConfig.username, routerConfig.password);
35     }
36
37     public AsuswrtCredentials(String username, String password) {
38         setCredentials(username, password);
39     }
40
41     /*
42      * Private methods
43      */
44
45     /**
46      * Stores the given credentials.
47      */
48     private void setCredentials(String username, String password) {
49         this.username = username;
50         this.password = password;
51         encodedCredentials = b64encode(username + ":" + password);
52     }
53
54     /**
55      * Encodes a String using Base64.
56      */
57     private String b64encode(String string) {
58         return Base64.getEncoder().encodeToString((string).getBytes());
59     }
60
61     /*
62      * Public methods
63      */
64
65     /**
66      * Returns Base64 encoded credentials.
67      *
68      * @return 'username:password' as Base64 encoded string
69      */
70     public String getEncodedCredentials() {
71         return encodedCredentials;
72     }
73
74     public String getPassword() {
75         return password;
76     }
77
78     public String getUsername() {
79         return username;
80     }
81 }