当前位置: 首页>>代码示例>>Java>>正文


Java Encoder.encodeForHTMLAttribute方法代码示例

本文整理汇总了Java中org.owasp.esapi.Encoder.encodeForHTMLAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java Encoder.encodeForHTMLAttribute方法的具体用法?Java Encoder.encodeForHTMLAttribute怎么用?Java Encoder.encodeForHTMLAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.owasp.esapi.Encoder的用法示例。


在下文中一共展示了Encoder.encodeForHTMLAttribute方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encode

import org.owasp.esapi.Encoder; //导入方法依赖的package包/类
public static String encode(String item, short encFor) throws PageException  {
	
	PrintStream out = System.out;
	try {
		 System.setOut(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
		 Encoder encoder = ESAPI.encoder();
		 switch(encFor){
		 //case ENC_CSS:return encoder.encodeForBase64(item);
		 case ENC_CSS:return encoder.encodeForCSS(item);
		 case ENC_DN:return encoder.encodeForDN(item);
		 case ENC_HTML:return encoder.encodeForHTML(item);
		 case ENC_HTML_ATTR:return encoder.encodeForHTMLAttribute(item);
		 case ENC_JAVA_SCRIPT:return encoder.encodeForJavaScript(item);
		 case ENC_LDAP:return encoder.encodeForLDAP(item);
		 //case ENC_CSS:return encoder.encodeForOS(arg0, arg1)(item);
		 //case ENC_CSS:return encoder.encodeForSQL(arg0, arg1)CSS(item);
		 case ENC_URL:return encoder.encodeForURL(item);
		 case ENC_VB_SCRIPT:return encoder.encodeForVBScript(item);
		 case ENC_XML:return encoder.encodeForXML(item);
		 case ENC_XML_ATTR:return encoder.encodeForXMLAttribute(item);
		 case ENC_XPATH:return encoder.encodeForXPath(item);
		 }
		 throw new ApplicationException("invalid target encoding defintion");
	}
	catch(EncodingException ee){
		throw Caster.toPageException(ee);
	}
	finally {
		 System.setOut(out);
	}
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:32,代码来源:ESAPIEncode.java

示例2: populateVelocityContext

import org.owasp.esapi.Encoder; //导入方法依赖的package包/类
/**
 * Populate the Velocity context instance which will be used to render the POST body.
 * 
 * @param velocityContext the Velocity context instance to populate with data
 * @param messageContext the SAML message context source of data
 * @param endpointURL endpoint URL to which to encode message
 * @throws MessageEncodingException thrown if there is a problem encoding the message
 */
protected void populateVelocityContext(VelocityContext velocityContext, SAMLMessageContext messageContext,
        String endpointURL) throws MessageEncodingException {
    
    Encoder esapiEncoder = ESAPI.encoder();

    String encodedEndpointURL = esapiEncoder.encodeForHTMLAttribute(endpointURL);
    log.debug("Encoding action url of '{}' with encoded value '{}'", endpointURL, encodedEndpointURL);
    velocityContext.put("action", encodedEndpointURL);
    velocityContext.put("binding", getBindingURI());

    log.debug("Marshalling and Base64 encoding SAML message");
    if (messageContext.getOutboundSAMLMessage().getDOM() == null) {
        marshallMessage(messageContext.getOutboundSAMLMessage());
    }
    try {
        String messageXML = XMLHelper.nodeToString(messageContext.getOutboundSAMLMessage().getDOM());
        String encodedMessage = Base64.encodeBytes(messageXML.getBytes("UTF-8"), Base64.DONT_BREAK_LINES);
        if (messageContext.getOutboundSAMLMessage() instanceof RequestAbstractType) {
            velocityContext.put("SAMLRequest", encodedMessage);
        } else if (messageContext.getOutboundSAMLMessage() instanceof StatusResponseType) {
            velocityContext.put("SAMLResponse", encodedMessage);
        } else {
            throw new MessageEncodingException(
                    "SAML message is neither a SAML RequestAbstractType or StatusResponseType");
        }
    } catch (UnsupportedEncodingException e) {
        log.error("UTF-8 encoding is not supported, this VM is not Java compliant.");
        throw new MessageEncodingException("Unable to encode message, UTF-8 encoding is not supported");
    }

    String relayState = messageContext.getRelayState();
    if (checkRelayState(relayState)) {
        String encodedRelayState = esapiEncoder.encodeForHTMLAttribute(relayState);
        log.debug("Setting RelayState parameter to: '{}', encoded as '{}'", relayState, encodedRelayState);
        velocityContext.put("RelayState", encodedRelayState);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:HTTPPostEncoder.java

示例3: postEncode

import org.owasp.esapi.Encoder; //导入方法依赖的package包/类
/**
 * Performs HTTP POST based encoding.
 * 
 * @param artifactContext current request context
 * @param outTransport outbound HTTP transport
 * 
 * @throws MessageEncodingException thrown if there is a problem POST encoding the artifact
 */
protected void postEncode(SAMLMessageContext artifactContext, HTTPOutTransport outTransport)
        throws MessageEncodingException {
    log.debug("Performing HTTP POST SAML 2 artifact encoding");

    log.debug("Creating velocity context");
    VelocityContext context = new VelocityContext();
    Encoder esapiEncoder = ESAPI.encoder();
    String endpointURL = getEndpointURL(artifactContext).toString();
    String encodedEndpointURL = esapiEncoder.encodeForHTMLAttribute(endpointURL);
    log.debug("Setting action parameter to: '{}', encoded as '{}'", endpointURL, encodedEndpointURL);
    context.put("action", encodedEndpointURL);
    context.put("SAMLArt", buildArtifact(artifactContext).base64Encode());
    context.put("binding", getBindingURI());

    if (checkRelayState(artifactContext.getRelayState())) {
        String encodedRelayState = esapiEncoder.encodeForHTMLAttribute(artifactContext.getRelayState());
        log.debug("Setting RelayState parameter to: '{}', encoded as '{}'", artifactContext.getRelayState(), encodedRelayState);
        context.put("RelayState", encodedRelayState);
    }

    try {
        log.debug("Invoking velocity template");
        OutputStreamWriter outWriter = new OutputStreamWriter(outTransport.getOutgoingStream());
        velocityEngine.mergeTemplate(velocityTemplateId, "UTF-8", context, outWriter);
    } catch (Exception e) {
        log.error("Error invoking velocity template to create POST form", e);
        throw new MessageEncodingException("Error creating output document", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:38,代码来源:HTTPArtifactEncoder.java

示例4: encode

import org.owasp.esapi.Encoder; //导入方法依赖的package包/类
public static String encode(String item, short encFor, boolean canonicalize) throws PageException  {
	if(StringUtil.isEmpty(item)) return item;
	
	PrintStream out = System.out;
	try {
		 
		
		System.setOut(new PrintStream(DevNullOutputStream.DEV_NULL_OUTPUT_STREAM));
		 Encoder encoder = ESAPI.encoder();
		 if(canonicalize)item=encoder.canonicalize(item, false);
		 
		 switch(encFor){
		 case ENC_CSS:return encoder.encodeForCSS(item);
		 case ENC_DN:return encoder.encodeForDN(item);
		 case ENC_HTML:return encoder.encodeForHTML(item);
		 case ENC_HTML_ATTR:return encoder.encodeForHTMLAttribute(item);
		 case ENC_JAVA_SCRIPT:return encoder.encodeForJavaScript(item);
		 case ENC_LDAP:return encoder.encodeForLDAP(item);
		 case ENC_URL:return encoder.encodeForURL(item);
		 case ENC_VB_SCRIPT:return encoder.encodeForVBScript(item);
		 case ENC_XML:return encoder.encodeForXML(item);
		 case ENC_XML_ATTR:return encoder.encodeForXMLAttribute(item);
		 case ENC_XPATH:return encoder.encodeForXPath(item);
		 }
		 throw new ApplicationException("invalid target encoding defintion");
	}
	catch(EncodingException ee){
		throw Caster.toPageException(ee);
	}
	finally {
		 System.setOut(out);
	}
}
 
开发者ID:lucee,项目名称:Lucee,代码行数:34,代码来源:ESAPIEncode.java

示例5: encode

import org.owasp.esapi.Encoder; //导入方法依赖的package包/类
/**
 * Encode tag's content for usage as a HTML attribute.
 * @param content The tag's content as a String
 * @param enc Encoder used to call
 * 	{@link Encoder#encodeForHTMLAttribute(String)}
 * @return content encoded for usage as a HTML attribute
 */
protected String encode(String content, Encoder enc)
{
	return enc.encodeForHTMLAttribute(content);
}
 
开发者ID:abimael93,项目名称:owasp-esapi-java,代码行数:12,代码来源:EncodeForHTMLAttributeTag.java


注:本文中的org.owasp.esapi.Encoder.encodeForHTMLAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。