1 16 package org.apache.jetspeed.portal.portlets; 17 18 import org.apache.jetspeed.portal.PortletException; 19 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 20 import org.apache.jetspeed.services.logging.JetspeedLogger; 21 22 import org.apache.turbine.util.RunData; 23 import org.apache.ecs.ConcreteElement; 24 25 26 34 public class BASICAuthIFramePortlet extends IFramePortlet 35 { 36 37 40 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(BASICAuthIFramePortlet.class.getName()); 41 42 private String origSource = null; 43 44 private static final String USERNAME = "username"; 45 private static final String PASSWORD = "password"; 46 47 52 public ConcreteElement getContent(RunData runData) 53 { 54 if (org.apache.jetspeed.util.PortletSessionState.getPortletConfigChanged(this, runData)) 55 { 56 try { 57 this.init(); 58 } 59 catch (PortletException pe) 60 { 61 logger.error("Exception", pe); 62 } 63 } 64 65 setSource(getSource(runData)); 66 67 return super.getContent(runData); 68 } 69 70 75 public String getSource(RunData runData) 76 { 77 String source = origSource; 78 if (source == null || source.trim().length() == 0) 79 { 80 return null; 81 } 82 83 int schemeCount = 8; 84 int index = source.indexOf("https://"); 85 if (index == -1) 86 { 87 schemeCount = 7; 88 index = source.indexOf("http://"); 89 } 90 91 if (index != -1) 92 { 93 String user = this.getPortletConfig().getInitParameter(USERNAME); 94 if (user == null || user.trim().length() == 0) 95 { 96 user = runData.getUser().getUserName(); 97 } 98 String pass = this.getPortletConfig().getInitParameter(PASSWORD); 99 if (pass == null || pass.trim().length() == 0) 100 { 101 pass = runData.getUser().getPassword(); 102 } 103 String beginStr = source.substring(0, schemeCount); 104 String endStr = source.substring(schemeCount); 105 int size = user.length() + pass.length() + source.length() + 2; 106 StringBuffer buff = new StringBuffer (size); 107 source = buff.append(beginStr).append(user).append(":").append(pass).append("@").append(endStr).toString(); 108 } 109 return source; 110 } 111 112 116 public void init() throws PortletException 117 { 118 super.init(); 119 origSource = getSource(); 120 } 121 122 } 123 | Popular Tags |