1 16 17 package org.springframework.web.portlet.handler; 18 19 import java.io.IOException ; 20 21 import javax.portlet.PortletException; 22 import javax.portlet.PortletRequest; 23 import javax.portlet.PortletResponse; 24 import javax.portlet.PortletSecurityException; 25 26 35 public class UserRoleAuthorizationInterceptor extends HandlerInterceptorAdapter { 36 37 private String [] authorizedRoles; 38 39 40 44 public final void setAuthorizedRoles(String [] authorizedRoles) { 45 this.authorizedRoles = authorizedRoles; 46 } 47 48 49 public final boolean preHandle(PortletRequest request, PortletResponse response, Object handler) 50 throws PortletException, IOException { 51 52 if (this.authorizedRoles != null) { 53 for (int i = 0; i < this.authorizedRoles.length; i++) { 54 if (request.isUserInRole(this.authorizedRoles[i])) { 55 return true; 56 } 57 } 58 } 59 handleNotAuthorized(request, response, handler); 60 return false; 61 } 62 63 74 protected void handleNotAuthorized(PortletRequest request, PortletResponse response, Object handler) 75 throws PortletException, IOException { 76 77 throw new PortletSecurityException("Request not authorized"); 78 } 79 80 } 81 | Popular Tags |