1 package org.apache.turbine.util; 2 3 18 19 import org.apache.turbine.om.security.Permission; 20 import org.apache.turbine.om.security.Role; 21 import org.apache.turbine.services.security.TurbineSecurity; 22 23 38 public class SecurityCheck 39 { 40 private String message; 41 private String failScreen; 42 private RunData data = null; 43 44 51 public SecurityCheck(RunData data, 52 String message, 53 String failedScreen) 54 { 55 this.data = data; 56 this.message = message; 57 this.failScreen = failedScreen; 58 } 59 60 67 public boolean hasRole(Role role) 68 throws Exception 69 { 70 boolean value = false; 71 if (data.getACL() == null || 72 !data.getACL().hasRole(role)) 73 { 74 data.setScreen(failScreen); 75 data.setMessage(message); 76 } 77 else 78 { 79 value = true; 80 } 81 return value; 82 } 83 84 91 public boolean hasRole(String role) 92 throws Exception 93 { 94 return hasRole(TurbineSecurity.getRoleByName(role)); 95 } 96 97 104 public boolean hasPermission(Permission permission) 105 throws Exception 106 { 107 boolean value = false; 108 if (data.getACL() == null || 109 !data.getACL().hasPermission(permission)) 110 { 111 data.setScreen(failScreen); 112 data.setMessage(message); 113 } 114 else 115 { 116 value = true; 117 } 118 return value; 119 } 120 121 128 public boolean hasPermission(String permission) 129 throws Exception 130 { 131 return hasPermission(TurbineSecurity.getPermissionByName(permission)); 132 } 133 134 140 public String getMessage() 141 { 142 return message; 143 } 144 145 151 public String getFailScreen() 152 { 153 return failScreen; 154 } 155 } 156 | Popular Tags |