1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17 package org.apache.tomcat.util.descriptor.web;
18
19 import java.io.Serializable;
20
21 import org.apache.tomcat.util.buf.UDecoder;
22
23 /**
24 * Representation of a login configuration element for a web application,
25 * as represented in a <code><login-config></code> element in the
26 * deployment descriptor.
27 *
28 * @author Craig R. McClanahan
29 */
30 public class LoginConfig implements Serializable {
31
32
33 private static final long serialVersionUID = 1L;
34
35
36 // ----------------------------------------------------------- Constructors
37
38
39 /**
40 * Construct a new LoginConfig with default properties.
41 */
42 public LoginConfig() {
43
44 super();
45
46 }
47
48
49 /**
50 * Construct a new LoginConfig with the specified properties.
51 *
52 * @param authMethod The authentication method
53 * @param realmName The realm name
54 * @param loginPage The login page URI
55 * @param errorPage The error page URI
56 */
57 public LoginConfig(String authMethod, String realmName,
58 String loginPage, String errorPage) {
59
60 super();
61 setAuthMethod(authMethod);
62 setRealmName(realmName);
63 setLoginPage(loginPage);
64 setErrorPage(errorPage);
65
66 }
67
68
69 // ------------------------------------------------------------- Properties
70
71
72 /**
73 * The authentication method to use for application login. Must be
74 * BASIC, DIGEST, FORM, or CLIENT-CERT.
75 */
76 private String authMethod = null;
77
78 public String getAuthMethod() {
79 return this.authMethod;
80 }
81
82 public void setAuthMethod(String authMethod) {
83 this.authMethod = authMethod;
84 }
85
86
87 /**
88 * The context-relative URI of the error page for form login.
89 */
90 private String errorPage = null;
91
92 public String getErrorPage() {
93 return this.errorPage;
94 }
95
96 public void setErrorPage(String errorPage) {
97 // if ((errorPage == null) || !errorPage.startsWith("/"))
98 // throw new IllegalArgumentException
99 // ("Error Page resource path must start with a '/'");
100 this.errorPage = UDecoder.URLDecode(errorPage);
101 }
102
103
104 /**
105 * The context-relative URI of the login page for form login.
106 */
107 private String loginPage = null;
108
109 public String getLoginPage() {
110 return this.loginPage;
111 }
112
113 public void setLoginPage(String loginPage) {
114 // if ((loginPage == null) || !loginPage.startsWith("/"))
115 // throw new IllegalArgumentException
116 // ("Login Page resource path must start with a '/'");
117 this.loginPage = UDecoder.URLDecode(loginPage);
118 }
119
120
121 /**
122 * The realm name used when challenging the user for authentication
123 * credentials.
124 */
125 private String realmName = null;
126
127 public String getRealmName() {
128 return this.realmName;
129 }
130
131 public void setRealmName(String realmName) {
132 this.realmName = realmName;
133 }
134
135
136 // --------------------------------------------------------- Public Methods
137
138
139 /**
140 * Return a String representation of this object.
141 */
142 @Override
143 public String toString() {
144 StringBuilder sb = new StringBuilder("LoginConfig[");
145 sb.append("authMethod=");
146 sb.append(authMethod);
147 if (realmName != null) {
148 sb.append(", realmName=");
149 sb.append(realmName);
150 }
151 if (loginPage != null) {
152 sb.append(", loginPage=");
153 sb.append(loginPage);
154 }
155 if (errorPage != null) {
156 sb.append(", errorPage=");
157 sb.append(errorPage);
158 }
159 sb.append("]");
160 return sb.toString();
161 }
162
163
164 /* (non-Javadoc)
165 * @see java.lang.Object#hashCode()
166 */
167 @Override
168 public int hashCode() {
169 final int prime = 31;
170 int result = 1;
171 result = prime * result
172 + ((authMethod == null) ? 0 : authMethod.hashCode());
173 result = prime * result
174 + ((errorPage == null) ? 0 : errorPage.hashCode());
175 result = prime * result
176 + ((loginPage == null) ? 0 : loginPage.hashCode());
177 result = prime * result
178 + ((realmName == null) ? 0 : realmName.hashCode());
179 return result;
180 }
181
182
183 /* (non-Javadoc)
184 * @see java.lang.Object#equals(java.lang.Object)
185 */
186 @Override
187 public boolean equals(Object obj) {
188 if (this == obj)
189 return true;
190 if (!(obj instanceof LoginConfig))
191 return false;
192 LoginConfig other = (LoginConfig) obj;
193 if (authMethod == null) {
194 if (other.authMethod != null)
195 return false;
196 } else if (!authMethod.equals(other.authMethod))
197 return false;
198 if (errorPage == null) {
199 if (other.errorPage != null)
200 return false;
201 } else if (!errorPage.equals(other.errorPage))
202 return false;
203 if (loginPage == null) {
204 if (other.loginPage != null)
205 return false;
206 } else if (!loginPage.equals(other.loginPage))
207 return false;
208 if (realmName == null) {
209 if (other.realmName != null)
210 return false;
211 } else if (!realmName.equals(other.realmName))
212 return false;
213 return true;
214 }
215
216
217 }
218