| 1 | |
package jp.co.y_net.amm.page; |
| 2 | |
|
| 3 | |
import java.text.DateFormat; |
| 4 | |
import java.text.ParseException; |
| 5 | |
import java.text.SimpleDateFormat; |
| 6 | |
import java.util.List; |
| 7 | |
|
| 8 | |
import javax.servlet.http.Cookie; |
| 9 | |
|
| 10 | |
import jp.co.y_net.amm.AppSession; |
| 11 | |
import jp.co.y_net.amm.common.AppLogger; |
| 12 | |
import jp.co.y_net.amm.common.ResourceReader; |
| 13 | |
import jp.co.y_net.amm.dao.GrpDao; |
| 14 | |
import jp.co.y_net.amm.dao.GrpusrDao; |
| 15 | |
import jp.co.y_net.amm.dao.InfDao; |
| 16 | |
import jp.co.y_net.amm.dao.OrgDao; |
| 17 | |
import jp.co.y_net.amm.dao.PwtcktDao; |
| 18 | |
import jp.co.y_net.amm.dao.Usr; |
| 19 | |
import jp.co.y_net.amm.dao.UsrDao; |
| 20 | |
import jp.co.y_net.amm.service.Challengestring; |
| 21 | |
import jp.co.y_net.amm.service.Logincheck; |
| 22 | |
import jp.co.y_net.amm.service.Logout; |
| 23 | |
import jp.co.y_net.amm.service.MailAddressCheck; |
| 24 | |
import jp.co.y_net.amm.service.PasswordTicketManager; |
| 25 | |
|
| 26 | |
import org.apache.commons.lang.StringUtils; |
| 27 | |
import org.apache.wicket.markup.html.WebPage; |
| 28 | |
import org.apache.wicket.request.http.WebRequest; |
| 29 | |
import org.apache.wicket.request.http.WebResponse; |
| 30 | |
import org.apache.wicket.request.mapper.parameter.PageParameters; |
| 31 | |
import org.apache.wicket.spring.injection.annot.SpringBean; |
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public abstract class AppPage extends WebPage{ |
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | |
@SpringBean(name="usrDao") |
| 50 | |
protected UsrDao usrDao; |
| 51 | |
|
| 52 | |
@SpringBean(name="orgDao") |
| 53 | |
protected OrgDao orgDao; |
| 54 | |
|
| 55 | |
@SpringBean(name="pwtcktDao") |
| 56 | |
protected PwtcktDao pwtcktDao; |
| 57 | |
|
| 58 | |
@SpringBean(name="infDao") |
| 59 | |
protected InfDao infDao; |
| 60 | |
|
| 61 | |
@SpringBean(name="grpDao") |
| 62 | |
protected GrpDao grpDao; |
| 63 | |
|
| 64 | |
@SpringBean(name="grpusrDao") |
| 65 | |
protected GrpusrDao grpusrDao; |
| 66 | |
|
| 67 | |
@SpringBean(name="challengestring") |
| 68 | |
protected Challengestring challengestring; |
| 69 | |
|
| 70 | |
@SpringBean(name="logincheck") |
| 71 | |
protected Logincheck logincheck; |
| 72 | |
|
| 73 | |
@SpringBean(name="logout") |
| 74 | |
protected Logout logout; |
| 75 | |
|
| 76 | |
@SpringBean(name="passwordTicketManager") |
| 77 | |
protected PasswordTicketManager passwordTicketManager; |
| 78 | |
|
| 79 | |
@SpringBean(name="mailAddressCheck") |
| 80 | |
protected MailAddressCheck mailAddressCheck; |
| 81 | |
|
| 82 | 0 | public AppPage() { |
| 83 | |
|
| 84 | |
|
| 85 | 0 | AppSession.get().bind(); |
| 86 | 0 | } |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
@Override |
| 94 | |
protected void onConfigure() { |
| 95 | |
|
| 96 | 0 | if (validateLogin() == false) { |
| 97 | |
|
| 98 | 0 | AppSession.get().returnPageClass = getPageClass(); |
| 99 | 0 | AppSession.get().returnPageParameters = getPageParameters(); |
| 100 | |
|
| 101 | 0 | setResponsePage(LoginPage.class, getPageParameters()); |
| 102 | 0 | return; |
| 103 | |
} |
| 104 | 0 | } |
| 105 | |
|
| 106 | |
|
| 107 | |
|
| 108 | |
|
| 109 | |
|
| 110 | |
|
| 111 | |
protected boolean validateLogin() { |
| 112 | 0 | return true; |
| 113 | |
} |
| 114 | |
|
| 115 | |
|
| 116 | |
|
| 117 | |
|
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 127 | |
|
| 128 | |
|
| 129 | |
|
| 130 | |
|
| 131 | |
protected void validItem(String value, String itemname, int min, int max) { |
| 132 | 0 | if(StringUtils.isEmpty(value)) { |
| 133 | 0 | if(min > 0) { |
| 134 | 0 | error(itemname + "を入力してください。"); |
| 135 | |
} else { |
| 136 | |
|
| 137 | |
} |
| 138 | 0 | } else { |
| 139 | 0 | if ((value.length() >= min && value.length() <= max) == false ) { |
| 140 | 0 | if(min == max) { |
| 141 | 0 | error(itemname + "は" + min + "文字で入力してください。"); |
| 142 | 0 | } else { |
| 143 | 0 | if(min == 1 || min == 0) { |
| 144 | 0 | error(itemname + "は" + max + "文字以下で入力してください。"); |
| 145 | 0 | } else { |
| 146 | 0 | error(itemname + "は" + min + "~" + max + "文字で入力してください。"); |
| 147 | |
} |
| 148 | |
} |
| 149 | |
} |
| 150 | |
} |
| 151 | 0 | } |
| 152 | |
|
| 153 | |
|
| 154 | |
|
| 155 | |
|
| 156 | |
|
| 157 | |
|
| 158 | |
|
| 159 | |
|
| 160 | |
protected void validItemNum(String value, String itemname, int min, int max) { |
| 161 | 0 | validItem(value, itemname, min, max); |
| 162 | 0 | if(hasInputError()) return; |
| 163 | 0 | if(StringUtils.isEmpty(value) == false) { |
| 164 | 0 | if(isNumeric(value) == false) { |
| 165 | 0 | error(itemname + "は数字で入力してください。"); |
| 166 | |
} |
| 167 | |
} |
| 168 | 0 | } |
| 169 | |
|
| 170 | |
|
| 171 | |
|
| 172 | |
|
| 173 | |
|
| 174 | |
|
| 175 | |
|
| 176 | |
|
| 177 | |
protected void validItemTel(String value, String itemname, int min, int max) { |
| 178 | 0 | validItem(value, itemname, min, max); |
| 179 | 0 | if(hasInputError()) return; |
| 180 | 0 | if(StringUtils.isEmpty(value) == false) { |
| 181 | 0 | value = value.replaceAll("-", ""); |
| 182 | 0 | if(isNumeric(value) == false) { |
| 183 | 0 | error(itemname + "は数字とハイフンのみ使用できます。"); |
| 184 | |
} |
| 185 | |
} |
| 186 | 0 | } |
| 187 | |
|
| 188 | |
|
| 189 | |
|
| 190 | |
|
| 191 | |
|
| 192 | |
|
| 193 | |
|
| 194 | |
|
| 195 | |
protected void validItemAscii(String value, String itemname, int min, int max) { |
| 196 | 0 | validItem(value, itemname, min, max); |
| 197 | 0 | if(hasInputError()) return; |
| 198 | 0 | if(StringUtils.isEmpty(value) == false) { |
| 199 | 0 | if(StringUtils.isAsciiPrintable(value) == false) { |
| 200 | 0 | error(itemname + "に使用できない文字が含まれています。"); |
| 201 | |
} |
| 202 | |
} |
| 203 | 0 | } |
| 204 | |
|
| 205 | |
|
| 206 | |
|
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
protected void validItemMail(String value, String itemname) { |
| 212 | 0 | validItemMail(value, itemname, false); |
| 213 | 0 | } |
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | |
protected void validItemMail(String value, String itemname, boolean freemailCheck) { |
| 222 | |
|
| 223 | 0 | if(StringUtils.isEmpty(value)) { |
| 224 | 0 | error(itemname + "を入力してください。"); |
| 225 | 0 | return; |
| 226 | |
} |
| 227 | 0 | if (value.length() > 256 ) { |
| 228 | 0 | error(itemname + "は256文字以内で入力してください。"); |
| 229 | 0 | return; |
| 230 | |
} |
| 231 | 0 | if(StringUtils.isAsciiPrintable(value) == false) { |
| 232 | 0 | error(itemname + "に使用できない文字が含まれています。"); |
| 233 | 0 | return; |
| 234 | |
} |
| 235 | 0 | if(value.indexOf('@') == -1) { |
| 236 | |
|
| 237 | 0 | error(itemname + "は形式が正しくありません。"); |
| 238 | 0 | return; |
| 239 | |
} |
| 240 | 0 | if(freemailCheck) { |
| 241 | |
|
| 242 | 0 | for (String ng: ResourceReader.getLines("omitmaildomains")) { |
| 243 | 0 | if(ng == null) ng = ""; |
| 244 | 0 | ng = ng.trim(); |
| 245 | 0 | if(StringUtils.isEmpty(ng) == false) { |
| 246 | 0 | if(value.endsWith(ng)) { |
| 247 | 0 | error(itemname + "は利用できないドメインです。"); |
| 248 | |
|
| 249 | |
|
| 250 | 0 | AppLogger.info("次のメールアドレスで申請されましたが、拒否リストに含まるため受け付けませんでした。:" + value); |
| 251 | |
|
| 252 | 0 | return; |
| 253 | |
} |
| 254 | |
} |
| 255 | |
} |
| 256 | |
} |
| 257 | 0 | } |
| 258 | |
|
| 259 | |
|
| 260 | |
|
| 261 | |
|
| 262 | |
protected boolean hasInputError() { |
| 263 | 0 | return AppSession.get().getFeedbackMessages().isEmpty() == false; |
| 264 | |
} |
| 265 | |
|
| 266 | |
|
| 267 | |
|
| 268 | |
|
| 269 | |
|
| 270 | |
|
| 271 | |
|
| 272 | |
|
| 273 | |
public static boolean isNumeric(String value) { |
| 274 | |
|
| 275 | |
|
| 276 | |
|
| 277 | |
|
| 278 | |
|
| 279 | |
|
| 280 | 0 | if("-1".equals(value)) { |
| 281 | 0 | return true; |
| 282 | |
} |
| 283 | 0 | if(StringUtils.isNumeric(value) == false) { |
| 284 | 0 | return false; |
| 285 | |
} |
| 286 | |
|
| 287 | 0 | if(StringUtils.isEmpty(value) != false) { |
| 288 | |
|
| 289 | 0 | if(value.indexOf('0') != -1) return false; |
| 290 | 0 | if(value.indexOf('1') != -1) return false; |
| 291 | 0 | if(value.indexOf('2') != -1) return false; |
| 292 | 0 | if(value.indexOf('3') != -1) return false; |
| 293 | 0 | if(value.indexOf('4') != -1) return false; |
| 294 | 0 | if(value.indexOf('5') != -1) return false; |
| 295 | 0 | if(value.indexOf('6') != -1) return false; |
| 296 | 0 | if(value.indexOf('7') != -1) return false; |
| 297 | 0 | if(value.indexOf('8') != -1) return false; |
| 298 | 0 | if(value.indexOf('9') != -1) return false; |
| 299 | |
} |
| 300 | 0 | return true; |
| 301 | |
} |
| 302 | |
|
| 303 | |
|
| 304 | |
|
| 305 | |
|
| 306 | |
|
| 307 | |
|
| 308 | |
|
| 309 | |
|
| 310 | |
|
| 311 | |
protected boolean isMember() { |
| 312 | 0 | return AppSession.get().isLogin() |
| 313 | 0 | && AppSession.get().getLoginUser().getKind() != null |
| 314 | 0 | && AppSession.get().getLoginUser().getKind().equals(Usr.KIND_機関会員); |
| 315 | |
} |
| 316 | |
|
| 317 | |
protected boolean isOrgAdmin() { |
| 318 | 0 | return AppSession.get().isLogin() |
| 319 | 0 | && AppSession.get().getLoginUser().getKind() != null |
| 320 | 0 | && AppSession.get().getLoginUser().getKind().equals(Usr.KIND_機関管理者); |
| 321 | |
} |
| 322 | |
|
| 323 | |
protected boolean isSystemAdmin() { |
| 324 | 0 | return AppSession.get().isLogin() |
| 325 | 0 | && AppSession.get().getLoginUser().getKind() != null |
| 326 | 0 | && AppSession.get().getLoginUser().getKind().equals(Usr.KIND_運営管理者); |
| 327 | |
} |
| 328 | |
protected boolean isSystemAdmin代表者() { |
| 329 | 0 | return AppSession.get().isLogin() |
| 330 | 0 | && AppSession.get().getLoginUser().getKind() != null |
| 331 | 0 | && AppSession.get().getLoginUser().getKind().equals(Usr.KIND_運営管理者) |
| 332 | 0 | && AppSession.get().getLoginUser().getOrgrole() != null |
| 333 | 0 | && AppSession.get().getLoginUser().getOrgrole().equals(Usr.ROLE_管理者); |
| 334 | |
} |
| 335 | |
|
| 336 | |
|
| 337 | |
|
| 338 | |
|
| 339 | |
protected boolean isLoginUser(Usr usr) { |
| 340 | 0 | return AppSession.get().isLogin() |
| 341 | 0 | && AppSession.get().getLoginUser().getUsrid().equals(usr.getUsrid()); |
| 342 | |
} |
| 343 | |
|
| 344 | |
|
| 345 | |
|
| 346 | |
|
| 347 | |
|
| 348 | |
|
| 349 | |
|
| 350 | |
|
| 351 | |
|
| 352 | |
|
| 353 | |
|
| 354 | |
|
| 355 | |
|
| 356 | |
|
| 357 | |
|
| 358 | |
|
| 359 | |
|
| 360 | |
|
| 361 | |
protected String getScreenId() { |
| 362 | 0 | return getPage().getClass().getSimpleName(); |
| 363 | |
} |
| 364 | |
protected PageParameters getParams() { |
| 365 | 0 | return super.getPageParameters(); |
| 366 | |
} |
| 367 | |
protected void addCookie(String name, String value, int time) { |
| 368 | 0 | Cookie cookie = new Cookie(name, value); |
| 369 | 0 | cookie.setPath("/"); |
| 370 | 0 | cookie.setMaxAge(time); |
| 371 | 0 | ((WebResponse) getRequestCycle().getResponse()).addCookie(cookie); |
| 372 | 0 | } |
| 373 | |
protected String getCookie(String name) { |
| 374 | 0 | List<Cookie> cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies(); |
| 375 | 0 | if (cookies != null) { |
| 376 | 0 | for (Cookie cookie : cookies) { |
| 377 | 0 | if (name.equals(cookie.getName())) { |
| 378 | 0 | return cookie.getValue(); |
| 379 | |
} |
| 380 | |
} |
| 381 | |
} |
| 382 | 0 | return ""; |
| 383 | |
} |
| 384 | |
|
| 385 | |
protected static boolean validFromToDate(String value) { |
| 386 | 0 | if("00000000".equals(value)){ |
| 387 | 0 | return true; |
| 388 | |
} |
| 389 | 0 | final DateFormat DF = new SimpleDateFormat("yyyyMMdd"); |
| 390 | 0 | DF.setLenient(false); |
| 391 | |
try { |
| 392 | 0 | DF.parse(value); |
| 393 | 0 | return true; |
| 394 | 0 | } catch (ParseException e) { |
| 395 | 0 | return false; |
| 396 | |
} |
| 397 | |
} |
| 398 | |
|
| 399 | |
|
| 400 | |
|
| 401 | |
|
| 402 | |
|
| 403 | |
|
| 404 | |
} |