1 28 package net.sf.jguard.jee.taglib; 29 30 import java.io.IOException ; 31 import java.util.Iterator ; 32 import java.util.Set ; 33 34 import javax.security.auth.Subject ; 35 import javax.servlet.jsp.JspException ; 36 import javax.servlet.jsp.tagext.TagSupport ; 37 38 import net.sf.jguard.jee.authentication.http.HttpConstants; 39 import net.sf.jguard.core.authentication.credentials.JGuardCredential; 40 41 import org.apache.commons.logging.Log; 42 import org.apache.commons.logging.LogFactory; 43 import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager; 44 45 51 public class PubCredential extends TagSupport implements HttpConstants { 52 53 private static final Log logger = LogFactory.getLog(PubCredential.class); 54 57 private static final long serialVersionUID = 3257570611415888950L; 58 private String id; 59 private String def = ""; 60 61 64 public String getId() { 65 return id; 66 } 67 68 71 public void setId(String id) { 72 this.id = id; 73 } 74 75 public int doEndTag() throws JspException { 76 String value = null; 77 String defaut = (String ) ExpressionEvaluatorManager.evaluate("default", def, String .class, this, pageContext); 78 String name = (String ) ExpressionEvaluatorManager.evaluate("id", id, String .class, this, pageContext); 79 80 Subject subject = TagUtils.getSubject(pageContext); 81 82 if (subject != null) { 83 Set publicCredentials = subject.getPublicCredentials(); 84 Iterator it = publicCredentials.iterator(); 85 JGuardCredential cred = null; 86 87 while (it.hasNext()) { 88 cred = (JGuardCredential) it.next(); 89 if (cred.getId().equals(name)) { 92 value = (String ) cred.getValue(); 93 break; 94 } 95 } 96 } 97 98 if (value == null && defaut != null) { 99 value = defaut; 100 } else if (name == null) { 101 value = ""; 102 } 103 104 if (logger.isDebugEnabled()) { 105 logger.debug("<jguard:PubCredential> id=" + this.id); 106 logger.debug("<jguard:PubCredential> default=" + defaut); 107 logger.debug("<jguard:PubCredential> value=" + value); 108 } 109 try { 110 pageContext.getOut().print(value); 112 } catch (IOException e) { 113 logger.error("doEndTag()", e); 114 } 115 116 return EVAL_PAGE; 117 } 118 119 122 public String getDefault() { 123 return def; 124 } 125 126 130 public void setDefault(String def) { 131 this.def = def; 132 } 133 } 134 | Popular Tags |