1 package org.apache.turbine.util.template; 2 3 18 19 import org.apache.turbine.Turbine; 20 import org.apache.turbine.TurbineConstants; 21 import org.apache.turbine.om.security.Permission; 22 import org.apache.turbine.om.security.Role; 23 import org.apache.turbine.services.security.TurbineSecurity; 24 import org.apache.turbine.services.template.TurbineTemplate; 25 import org.apache.turbine.util.RunData; 26 27 44 public class TemplateSecurityCheck 45 { 46 private String message = 47 "Sorry, you do not have permission to access this area."; 48 private String failScreen = TurbineTemplate.getDefaultScreen(); 49 private String failTemplate; 50 private RunData data = null; 51 52 59 public TemplateSecurityCheck(RunData data, String message) 60 { 61 this.data = data; 62 this.message = message; 63 } 64 65 70 public TemplateSecurityCheck(RunData data) 71 { 72 this.data = data; 73 } 74 75 82 public boolean hasRole(Role role) 83 throws Exception 84 { 85 if (!checkLogin()) 86 { 87 return false; 88 } 89 90 if (data.getACL() == null || !data.getACL().hasRole(role)) 91 { 92 data.setScreen(getFailScreen()); 93 data.getTemplateInfo().setScreenTemplate(getFailTemplate()); 94 data.setMessage(getMessage()); 95 return false; 96 } 97 98 return true; 99 } 100 101 108 public boolean hasPermission(Permission permission) 109 throws Exception 110 { 111 boolean value = true; 112 if (data.getACL() == null || !data.getACL().hasPermission(permission)) 113 { 114 data.setScreen(getFailScreen()); 115 data.getTemplateInfo().setScreenTemplate(getFailTemplate()); 116 data.setMessage(getMessage()); 117 value = false; 118 } 119 120 return value; 121 } 122 123 129 public boolean checkLogin() 130 throws Exception 131 { 132 boolean value = true; 133 134 if (!TurbineSecurity.isAnonymousUser(data.getUser()) 136 && !data.getUser().hasLoggedIn()) 137 { 138 data.setMessage(Turbine.getConfiguration() 139 .getString(TurbineConstants.LOGIN_MESSAGE)); 140 141 data.getTemplateInfo().setScreenTemplate(getFailTemplate()); 142 value = false; 143 } 144 145 return value; 146 } 147 148 154 public void setMessage(String v) 155 { 156 this.message = v; 157 } 158 159 165 public String getMessage() 166 { 167 return message; 168 } 169 170 175 public String getFailScreen() 176 { 177 return failScreen; 178 } 179 180 185 public void setFailScreen(String v) 186 { 187 this.failScreen = v; 188 } 189 190 195 public String getFailTemplate() 196 { 197 return failTemplate; 198 } 199 200 205 public void setFailTemplate(String v) 206 { 207 this.failTemplate = v; 208 } 209 } 210 | Popular Tags |