1 55 56 package org.jboss.axis.handlers; 57 58 import org.jboss.axis.AxisFault; 59 import org.jboss.axis.Handler; 60 import org.jboss.axis.MessageContext; 61 import org.jboss.axis.security.AuthenticatedUser; 62 import org.jboss.axis.security.SecurityProvider; 63 import org.jboss.axis.utils.JavaUtils; 64 import org.jboss.axis.utils.Messages; 65 import org.jboss.logging.Logger; 66 67 import java.util.StringTokenizer ; 68 69 70 87 public class SimpleAuthorizationHandler extends BasicHandler 88 { 89 private static Logger log = Logger.getLogger(SimpleAuthorizationHandler.class.getName()); 90 91 94 public void invoke(MessageContext msgContext) throws AxisFault 95 { 96 if (log.isDebugEnabled()) 97 { 98 log.debug("Enter: SimpleAuthorizationHandler::invoke"); 99 } 100 101 boolean allowByDefault = 102 JavaUtils.isTrueExplicitly(getOption("allowByDefault")); 103 104 AuthenticatedUser user = (AuthenticatedUser)msgContext. 105 getProperty(MessageContext.AUTHUSER); 106 107 if (user == null) 108 throw new AxisFault("Server.NoUser", 109 Messages.getMessage("needUser00"), null, null); 110 111 String userID = user.getName(); 112 Handler serviceHandler = msgContext.getService(); 113 114 if (serviceHandler == null) 115 throw new AxisFault(Messages.getMessage("needService00")); 116 117 String serviceName = serviceHandler.getName(); 118 119 String allowedRoles = (String )serviceHandler.getOption("allowedRoles"); 120 if (allowedRoles == null) 121 { 122 if (allowByDefault) 123 { 124 if (log.isDebugEnabled()) 125 { 126 log.debug(Messages.getMessage("noRoles00")); 127 } 128 } 129 else 130 { 131 if (log.isDebugEnabled()) 132 { 133 log.debug(Messages.getMessage("noRoles01")); 134 } 135 136 throw new AxisFault("Server.Unauthorized", 137 Messages.getMessage("notAuth00", userID, serviceName), 138 null, null); 139 } 140 141 if (log.isDebugEnabled()) 142 { 143 log.debug("Exit: SimpleAuthorizationHandler::invoke"); 144 } 145 return; 146 } 147 148 SecurityProvider provider = (SecurityProvider)msgContext.getProperty(MessageContext.SECURITY_PROVIDER); 149 if (provider == null) 150 throw new AxisFault(Messages.getMessage("noSecurity00")); 151 152 StringTokenizer st = new StringTokenizer (allowedRoles, ","); 153 while (st.hasMoreTokens()) 154 { 155 String thisRole = st.nextToken(); 156 if (provider.userMatches(user, thisRole)) 157 { 158 159 if (log.isDebugEnabled()) 160 { 161 log.debug(Messages.getMessage("auth01", 162 userID, serviceName)); 163 } 164 165 if (log.isDebugEnabled()) 166 { 167 log.debug("Exit: SimpleAuthorizationHandler::invoke"); 168 } 169 return; 170 } 171 } 172 173 throw new AxisFault("Server.Unauthorized", 174 Messages.getMessage("cantAuth02", userID, serviceName), 175 null, null); 176 } 177 178 181 public void onFault(MessageContext msgContext) 182 { 183 if (log.isDebugEnabled()) 184 { 185 log.debug("Enter: SimpleAuthorizationHandler::onFault"); 186 log.debug("Exit: SimpleAuthorizationHandler::onFault"); 187 } 188 } 189 } 190 191 ; 192 | Popular Tags |