1 20 21 package com.methodhead.auth; 22 23 import javax.servlet.http.HttpServletRequest ; 24 25 import org.apache.struts.action.ActionForward; 26 import org.apache.struts.action.ActionMapping; 27 28 32 public class AuthUtil { 33 34 36 38 40 42 47 public static String getRelativeUrl( 48 HttpServletRequest request ) { 49 50 String baseUrl = null; 51 52 if ( ( request.getServerPort() == 80 ) || 53 ( request.getServerPort() == 443 ) ) 54 baseUrl = 55 request.getScheme() + "://" + 56 request.getServerName() + 57 request.getContextPath(); 58 else 59 baseUrl = 60 request.getScheme() + "://" + 61 request.getServerName() + ":" + request.getServerPort() + 62 request.getContextPath(); 63 64 StringBuffer buf = request.getRequestURL(); 65 66 if ( request.getQueryString() != null ) { 67 buf.append( "?" ); 68 buf.append( request.getQueryString() ); 69 } 70 71 return buf.substring( baseUrl.length() ); 72 } 73 74 78 public static AuthUser getUser( 79 HttpServletRequest request ) { 80 81 return 82 ( AuthUser )request.getSession().getAttribute( AuthGlobals.USER_KEY ); 83 } 84 85 89 public static void setUser ( 90 HttpServletRequest request, 91 AuthUser user ) { 92 93 request.getSession().setAttribute( AuthGlobals.USER_KEY, user ); 94 } 95 96 100 public static ActionForward findForward( 101 ActionMapping mapping, 102 String name ) 103 throws 104 AuthException { 105 106 ActionForward forward = mapping.findForward( name ); 107 108 if ( forward == null ) 109 throw new AuthException( "Couldn't find \"" + name + "\" forward" ); 110 111 return forward; 112 } 113 114 116 } 118 | Popular Tags |