001 package com.khubla.pragmatach.plugin.adminapp;
002
003 import com.khubla.pragmatach.framework.api.PragmatachException;
004 import com.khubla.pragmatach.framework.api.Response;
005
006 /**
007 * @author tome
008 */
009 public class SecuredAdminController extends BaseAdminController {
010 /**
011 * check security
012 */
013 public Response render() throws PragmatachException {
014 /*
015 * get the user controller
016 */
017 final AdminUserController adminUserController = this.getSessionScopedController(AdminUserController.class);
018 /*
019 * user logged in?
020 */
021 if (null != adminUserController.getUsername()) {
022 /*
023 * user is logged in
024 */
025 return super.render();
026 } else {
027 /*
028 * check for the cookie
029 */
030 final String userId = getRequest().getCookies().getEncryptedCookie(USERID);
031 final String password = getRequest().getCookies().getEncryptedCookie(PASSWORD);
032 if ((null != userId) && (null != password)) {
033 /*
034 * check
035 */
036 if ((userId.compareTo(getConfigurationParameter("pragmatach.adminapp.username")) == 0) && (password.compareTo(getConfigurationParameter("pragmatach.adminapp.password")) == 0)) {
037 /*
038 * set the session state from the cookie
039 */
040 adminUserController.setUsername(userId);
041 /*
042 * redirect back and try again
043 */
044 return super.render();
045 } else {
046 /*
047 * log in
048 */
049 return super.forward("/pragmatach/admin/login");
050 }
051 } else {
052 /*
053 * log in
054 */
055 return super.forward("/pragmatach/admin/login");
056 }
057 }
058 }
059 }