1 package fr.ifremer.quadrige3.ui.swing.content.login;
2
3 /*-
4 * #%L
5 * Quadrige3 Core :: Quadrige3 UI Common
6 * $Id:$
7 * $HeadURL:$
8 * %%
9 * Copyright (C) 2017 Ifremer
10 * %%
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Affero General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU Affero General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * #L%
24 */
25
26
27 import fr.ifremer.quadrige3.core.security.AuthenticationInfo;
28 import fr.ifremer.quadrige3.ui.swing.model.AbstractEmptyUIModel;
29 import org.apache.commons.lang3.StringUtils;
30
31 /**
32 * Created by Ludovic on 21/04/2016.
33 */
34 public class LoginUIModel extends AbstractEmptyUIModel<LoginUIModel> {
35
36 /** Constant <code>PROPERTY_LOGIN="login"</code> */
37 public static final String PROPERTY_LOGIN = "login";
38 /** Constant <code>PROPERTY_PASSWORD="password"</code> */
39 public static final String PROPERTY_PASSWORD = "password";
40 /** Constant <code>PROPERTY_URL="url"</code> */
41 public static final String PROPERTY_URL = "url";
42 private String login;
43 private String password;
44 private String url;
45
46 /**
47 * <p>Getter for the field <code>login</code>.</p>
48 *
49 * @return a {@link String} object.
50 */
51 public String getLogin() {
52 return login;
53 }
54
55 /**
56 * <p>Setter for the field <code>login</code>.</p>
57 *
58 * @param login a {@link String} object.
59 */
60 public void setLogin(String login) {
61 this.login = login;
62 firePropertyChange(PROPERTY_LOGIN, null, login);
63 }
64
65 /**
66 * <p>Getter for the field <code>password</code>.</p>
67 *
68 * @return a {@link String} object.
69 */
70 public String getPassword() {
71 return password;
72 }
73
74 /**
75 * <p>Setter for the field <code>password</code>.</p>
76 *
77 * @param password a {@link String} object.
78 */
79 public void setPassword(String password) {
80 this.password = password;
81 firePropertyChange(PROPERTY_PASSWORD, null, password);
82 }
83
84 /**
85 * <p>Getter for the field <code>url</code>.</p>
86 *
87 * @return a {@link String} object.
88 */
89 public String getUrl() {
90 return url;
91 }
92
93 /**
94 * <p>Setter for the field <code>url</code>.</p>
95 *
96 * @param url a {@link String} object.
97 */
98 public void setUrl(String url) {
99 this.url = url;
100 firePropertyChange(PROPERTY_URL, null, url);
101 }
102
103 /**
104 * <p>getAuthenticationInfo.</p>
105 *
106 * @return a {@link fr.ifremer.quadrige3.core.security.AuthenticationInfo} object.
107 */
108 public AuthenticationInfo getAuthenticationInfo() {
109 if (StringUtils.isBlank(getLogin()) && StringUtils.isBlank(getPassword())) {
110 return null;
111 }
112 return new AuthenticationInfo(getLogin(), getPassword());
113 }
114
115 /**
116 * <p>setAuthenticationInfo.</p>
117 *
118 * @param authenticationInfo a {@link fr.ifremer.quadrige3.core.security.AuthenticationInfo} object.
119 */
120 public void setAuthenticationInfo(AuthenticationInfo authenticationInfo) {
121 if (authenticationInfo != null) {
122 setLogin(authenticationInfo.getLogin());
123 setPassword(authenticationInfo.getPassword());
124 }
125 }
126
127 }