1 23 24 package org.infoglue.cms.security; 25 26 import java.security.Principal ; 27 import java.util.Map ; 28 import java.util.Properties ; 29 30 import javax.servlet.FilterChain ; 31 import javax.servlet.http.HttpServletRequest ; 32 import javax.servlet.http.HttpServletResponse ; 33 34 import org.apache.log4j.Logger; 35 import org.infoglue.cms.exception.SystemException; 36 37 42 43 public class CombinedJNDIBasicAuthenticationModule extends JNDIBasicAuthenticationModule 44 { 45 private final static Logger logger = Logger.getLogger(CombinedJNDIBasicAuthenticationModule.class.getName()); 46 47 48 public static AuthenticationModule getFallbackAuthenticationModule(Object transactionObject, String successLoginUrl) throws SystemException 49 { 50 AuthenticationModule authenticationModule = null; 51 52 try 53 { 54 String authorizerClass = InfoGlueAuthenticationFilter.authorizerClass; 55 String invalidLoginUrl = InfoGlueAuthenticationFilter.invalidLoginUrl; 56 String loginUrl = InfoGlueAuthenticationFilter.loginUrl; 57 String logoutUrl = InfoGlueAuthenticationFilter.logoutUrl; 58 String serverName = InfoGlueAuthenticationFilter.serverName; 59 Properties extraProperties = InfoGlueAuthenticationFilter.extraProperties; 60 String casRenew = InfoGlueAuthenticationFilter.casRenew; 61 String casServiceUrl = InfoGlueAuthenticationFilter.casServiceUrl; 62 String casValidateUrl = InfoGlueAuthenticationFilter.casValidateUrl; 63 String casLogoutUrl = InfoGlueAuthenticationFilter.casLogoutUrl; 64 65 authenticationModule = new InfoGlueBasicAuthenticationModule(); 66 authenticationModule.setAuthenticatorClass(InfoGlueBasicAuthenticationModule.class.getName()); 67 authenticationModule.setAuthorizerClass(authorizerClass); 68 authenticationModule.setInvalidLoginUrl(invalidLoginUrl); 69 authenticationModule.setLoginUrl(loginUrl); 70 authenticationModule.setLogoutUrl(logoutUrl); 71 authenticationModule.setServerName(serverName); 72 authenticationModule.setExtraProperties(extraProperties); 73 authenticationModule.setCasRenew(casRenew); 74 75 if(successLoginUrl != null && successLoginUrl.length() > 0) 76 { 77 int index = successLoginUrl.indexOf("&ticket="); 78 if(index > -1) 79 { 80 successLoginUrl = successLoginUrl.substring(0, index); 81 } 82 logger.info("successLoginUrl:" + successLoginUrl); 83 authenticationModule.setCasServiceUrl(successLoginUrl); 84 authenticationModule.setSuccessLoginUrl(successLoginUrl); 85 } 86 else 87 authenticationModule.setCasServiceUrl(casServiceUrl); 88 89 authenticationModule.setCasValidateUrl(casValidateUrl); 90 authenticationModule.setCasLogoutUrl(casLogoutUrl); 91 authenticationModule.setTransactionObject(transactionObject); 92 } 93 catch(Exception e) 94 { 95 logger.error("An error occurred when we tried to get an authenticationModule:" + e, e); 96 throw new SystemException("An error occurred when we tried to get an authenticationModule: " + e.getMessage(), e); 97 } 98 99 return authenticationModule; 100 } 101 102 105 106 public String authenticateUser(HttpServletRequest request, HttpServletResponse response, FilterChain fc) throws Exception 107 { 108 String authenticatedUserName = null; 109 110 try 111 { 112 logger.info("authenticateUser 1"); 113 request.setAttribute("disableRedirect", "true"); 114 authenticatedUserName = super.authenticateUser(request, response, fc); 115 logger.info("authenticatedUserName from JNDI:" + authenticatedUserName); 116 if(authenticatedUserName == null) 117 { 118 authenticatedUserName = getFallbackAuthenticationModule(null, null).authenticateUser(request, response, fc); 119 logger.info("authenticatedUserName from BASIC:" + authenticatedUserName); 120 } 121 } 122 catch(Exception e) 123 { 124 logger.info("NO authenticatedUserName from JNDI"); 125 authenticatedUserName = getFallbackAuthenticationModule(null, null).authenticateUser(request, response, fc); 126 logger.info("authenticatedUserName from BASIC:" + authenticatedUserName); 127 } 128 129 return authenticatedUserName; 130 } 131 132 133 136 137 public String authenticateUser(Map request) throws Exception 138 { 139 String authenticatedUserName = null; 140 try 141 { 142 logger.info("authenticateUser 2"); 143 request.put("disableRedirect", "true"); 144 authenticatedUserName = super.authenticateUser(request); 145 logger.info("authenticatedUserName from JNDI:" + authenticatedUserName); 146 if(authenticatedUserName == null) 147 { 148 authenticatedUserName = getFallbackAuthenticationModule(null, null).authenticateUser(request); 149 logger.info("authenticatedUserName from BASIC:" + authenticatedUserName); 150 } 151 } 152 catch(Exception e) 153 { 154 logger.info("NO authenticatedUserName from JNDI"); 155 authenticatedUserName = getFallbackAuthenticationModule(null, null).authenticateUser(request); 156 logger.info("authenticatedUserName from BASIC:" + authenticatedUserName); 157 } 158 159 return authenticatedUserName; 160 } 161 162 163 166 167 public String getLoginDialogUrl(HttpServletRequest request, HttpServletResponse response) throws Exception 168 { 169 return super.getLoginDialogUrl(request, response); 170 } 171 172 public Principal loginUser(HttpServletRequest request, HttpServletResponse response, Map status) throws Exception 173 { 174 return null; 175 } 176 177 public boolean logoutUser(HttpServletRequest request, HttpServletResponse response) throws Exception 178 { 179 return false; 180 } 181 182 183 } | Popular Tags |