1 package net.simya.ldap.taglib; 2 3 import javax.servlet.jsp.tagext.*; 4 import javax.servlet.jsp.*; 5 import javax.naming.Context ; 6 import javax.naming.directory.DirContext ; 7 import javax.naming.NamingException ; 8 import java.util.Enumeration ; 9 import net.simya.ldap.beans.*; 10 11 public class Connect 12 extends BodyTagSupport 13 { 14 private LdapConnectBean connectBean = null; 15 16 private String url = null; 17 private String dn = null; 18 private String password = null; 19 private String ssl = null; 20 private String referral = null; 21 private String authtype = null; 22 23 public int doStartTag() 24 throws JspException 25 { 26 connectBean = new LdapConnectBean(); 27 28 for ( Enumeration e = pageContext.getAttributeNamesInScope( pageContext.PAGE_SCOPE ); e.hasMoreElements(); ) 29 { 30 String property = (String ) e.nextElement(); 31 connectBean.setProperty( property, pageContext.getAttribute( property ) ); 32 } 33 34 if ( url != null ) 35 connectBean.setProperty( Context.PROVIDER_URL, url ); 36 if ( dn != null ) 37 connectBean.setProperty( Context.SECURITY_PRINCIPAL, dn ); 38 if ( password != null ) 39 connectBean.setProperty( Context.SECURITY_CREDENTIALS, password ); 40 if ( (ssl != null) && (ssl.equalsIgnoreCase("on")) ) 41 connectBean.setProperty(Context.SECURITY_PROTOCOL, "ssl"); 42 if ( referral != null ) 43 connectBean.setProperty(Context.REFERRAL, referral); 44 if ( authtype != null ) 45 connectBean.setProperty(Context.REFERRAL, referral); 46 47 try 48 { 49 connectBean.connect(); 50 } catch ( NamingException ex ) 51 { 52 throw new LdapTaglibException( ex ); 53 } 54 55 return EVAL_BODY_TAG; 56 } 57 58 public int doAfterBody() 59 throws JspException 60 { 61 try 62 { 63 connectBean.disconnect(); 64 } catch ( NamingException ex ) 65 { 66 throw new LdapTaglibException( ex ); 67 } 68 BodyContent body = getBodyContent(); 69 try 70 { 71 body.writeOut( getPreviousOut() ); 73 } 74 catch ( java.io.IOException ex ) 75 { 76 throw new JspTagException( "IO Error" ); 77 } 78 return SKIP_BODY; 80 } 81 82 public void release() 83 { 84 connectBean = null; 85 url = null; 86 password = null; 87 dn = null; 88 ssl = null; 89 referral=null; 90 authtype=null; 91 } 92 93 public DirContext getContext() 94 { 95 return connectBean.getContext(); 96 } 97 98 public java.util.Hashtable getEnv() 99 { 100 return connectBean.getEnv(); 101 } 102 103 public Object getProperty( String name ) 104 { 105 return connectBean.getProperty( name ); 106 } 107 108 public String getDn() { return this.dn; } 109 public void setDn(String dn) { this.dn = dn; } 110 111 public String getPassword() { return this.password; } 112 public void setPassword(String password) { this.password = password; } 113 114 public String getUrl() { return this.url; } 115 public void setUrl(String url) { this.url = url; } 116 117 public String getSsl() { return this.url; } 118 public void setSsl(String ssl) { this.ssl = ssl; } 119 120 public String getReferral() { return this.referral; } 121 122 public void setReferral(String referral) { this.referral = referral; } 123 124 125 public String getAuthtype() 126 { 127 return this.authtype; 128 } 129 130 public void setAuthtype(String authtype) 131 { 132 this.authtype = authtype; 133 } 134 } 135 | Popular Tags |