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


Java Encode类代码示例

本文整理汇总了Java中org.owasp.encoder.Encode的典型用法代码示例。如果您正苦于以下问题:Java Encode类的具体用法?Java Encode怎么用?Java Encode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testEncoder

import org.owasp.encoder.Encode; //导入依赖的package包/类
@Test
public void testEncoder() throws Exception {
    String s1 = "keep-alive";
    String s2 = "text/html";
    Assert.assertEquals(Encode.forJavaScriptSource(s1), s1);
    Assert.assertEquals(Encode.forJavaScriptSource(s2), s2);
    //Assert.assertEquals(Encode.forJavaScriptBlock(s1), s1);
    //Assert.assertEquals(Encode.forJavaScriptBlock(s2), s2);

    String s3 = "<script>alert('test')</script>";
    String e3 = Encode.forJavaScriptSource(s3);
    System.out.println("source = " + e3);
    String e4 = Encode.forJavaScriptAttribute(s3);
    System.out.println("attribute = " + e4);
    String e5 = Encode.forJavaScriptBlock(s3);
    System.out.println("block = " + e5);
    String e6 = Encode.forJavaScript(e3);
    System.out.println("script = " + e6);
    Assert.assertNotEquals(e3, s3);

    String s7 = "<script>location.href=\"respources.html\"</script>";
    String e7 = Encode.forJavaScriptSource(s7);
    System.out.println("e7 = " + e7);
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:25,代码来源:SanitizerHandlerTest.java

示例2: encodeNode

import org.owasp.encoder.Encode; //导入依赖的package包/类
public void encodeNode(Map<String, Object> map) {
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        String key = entry.getKey();
        Object value = entry.getValue();
        if (value instanceof String)
            map.put(key, Encode.forJavaScriptSource((String) value));
        else if (value instanceof Map)
            encodeNode((Map) value);
        else if (value instanceof List) {
            encodeList((List)value);
        }
    }
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:14,代码来源:SanitizerHandler.java

示例3: forHtml

import org.owasp.encoder.Encode; //导入依赖的package包/类
/**
 * Encodes for HTML text content and text attributes.
 *
 * @param input HTML input, may be null
 *
 * @return Encoded HTML text, empty string if anything goes wrong
 */
public String forHtml( String input )
{
    if( isEmpty( input ) )
    {
        return EMPTY;
    }
    try
    {
        return Encode.forHtml( input );
    }
    catch( Exception ex )
    {
        LOG.error( "Encoding for HTML error, will return empty string: {}", ex.getMessage(), ex );
        return EMPTY;
    }
}
 
开发者ID:werval,项目名称:werval,代码行数:24,代码来源:Sanitize.java

示例4: testStartExecutionTransServletEscapesHtmlWhenTransNotFound

import org.owasp.encoder.Encode; //导入依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testStartExecutionTransServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
  HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
  HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );

  StringWriter out = new StringWriter();
  PrintWriter printWriter = new PrintWriter( out );

  PowerMockito.spy( Encode.class );
  when( mockHttpServletRequest.getContextPath() ).thenReturn( StartExecutionTransServlet.CONTEXT_PATH );
  when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
  when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );

  startExecutionTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
  assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );

  PowerMockito.verifyStatic( atLeastOnce() );
  Encode.forHtml( anyString() );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:21,代码来源:StartExecutionTransServletTest.java

示例5: testPauseTransServletEscapesHtmlWhenTransNotFound

import org.owasp.encoder.Encode; //导入依赖的package包/类
@Test
@PrepareForTest( { Encode.class } )
public void testPauseTransServletEscapesHtmlWhenTransNotFound() throws ServletException, IOException {
  HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class );
  HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class );

  StringWriter out = new StringWriter();
  PrintWriter printWriter = new PrintWriter( out );

  PowerMockito.spy( Encode.class );
  when( mockHttpServletRequest.getContextPath() ).thenReturn( PrepareExecutionTransServlet.CONTEXT_PATH );
  when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST );
  when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter );

  prepareExecutionTransServlet.doGet( mockHttpServletRequest, mockHttpServletResponse );
  assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) );

  PowerMockito.verifyStatic( atLeastOnce() );
  Encode.forHtml( anyString() );
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:21,代码来源:PrepareExecutionTransServletTest.java

示例6: readCertificate

import org.owasp.encoder.Encode; //导入依赖的package包/类
/**
 * Read certificate from a file and convert it into X509Certificate object
 *
 * @param filename certificate file name
 * @return X509Certificate object
 * @throws Exception Exception while reading certificate
 */
static public X509Certificate readCertificate(String filename)
        throws Exception {
    InputStream inStream = null;
    X509Certificate cert = null;
    try {
        inStream = Config.getInstance().getInputStreamFromFile(filename);
        if (inStream != null) {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            cert = (X509Certificate) cf.generateCertificate(inStream);
        } else {
            logger.info("Certificate " + Encode.forJava(filename) + " not found.");
        }
    } catch (Exception e) {
        logger.error("Exception: ", e);
    } finally {
        if (inStream != null) {
            try {
                inStream.close();
            } catch (IOException ioe) {
                logger.error("Exception: ", ioe);
            }
        }
    }
    return cert;
}
 
开发者ID:networknt,项目名称:light-4j,代码行数:33,代码来源:JwtHelper.java

示例7: createForum

import org.owasp.encoder.Encode; //导入依赖的package包/类
@Override
public GWTForum createForum(GWTForum forum) throws OKMException {
	log.debug("createForum()");
	updateSessionManager();

	try {
		// Fix XSS issues
		forum.setDescription(Encode.forHtml(forum.getDescription()));
		forum.setName(Encode.forHtml(forum.getName()));

		forum.setDate(new Date());
		forum.setLastPostDate(new Date());
		forum.setLastPostUser(getThreadLocalRequest().getRemoteUser());
		forum.setNumPosts(0);
		forum.setNumTopics(0);
		Forum f = GWTUtil.copy(forum);
		ForumDAO.create(f);
		return GWTUtil.copy(f);
	} catch (DatabaseException e) {
		log.error(e.getMessage(), e);
		throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMForumService, ErrorCode.CAUSE_Database),
				e.getMessage());
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:25,代码来源:ForumServlet.java

示例8: updateForum

import org.owasp.encoder.Encode; //导入依赖的package包/类
@Override
public void updateForum(GWTForum forum) throws OKMException {
	log.debug("updateForum()");
	updateSessionManager();

	try {
		// Fix XSS issues
		forum.setDescription(Encode.forHtml(forum.getDescription()));
		forum.setName(Encode.forHtml(forum.getName()));

		Forum f = ForumDAO.findByPk(forum.getId());
		f.setName(forum.getName());
		f.setDescription(forum.getDescription());
		ForumDAO.update(f);
	} catch (DatabaseException e) {
		log.error(e.getMessage(), e);
		throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMForumService, ErrorCode.CAUSE_Database),
				e.getMessage());
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:21,代码来源:ForumServlet.java

示例9: updateTopic

import org.owasp.encoder.Encode; //导入依赖的package包/类
@Override
public void updateTopic(long id, GWTForumPost post) throws OKMException {
	log.debug("updateTopic({}, {})", id, post.getId());
	updateSessionManager();

	try {
		// Fix XSS issues
		post.setSubject(Encode.forHtml(post.getSubject()));
		post.setMessage(Encode.forHtml(post.getMessage()));

		// Update post
		ForumPost fp = ForumDAO.findPostByPk(post.getId());
		fp.setSubject(post.getSubject());
		fp.setMessage(post.getMessage());
		ForumDAO.update(fp);

		// Update topic
		ForumTopic ft = ForumDAO.findTopicByPk(id);
		ft.setTitle(post.getSubject()); // Updating the title
		ForumDAO.update(ft);
	} catch (DatabaseException e) {
		log.error(e.getMessage(), e);
		throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMForumService, ErrorCode.CAUSE_Database),
				e.getMessage());
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:27,代码来源:ForumServlet.java

示例10: updateWikiPage

import org.owasp.encoder.Encode; //导入依赖的package包/类
@Override
public GWTWikiPage updateWikiPage(GWTWikiPage wikiPage) throws OKMException {
	log.debug("updateWikiPage({})", wikiPage);

	try {
		// Fix XSS issues
		wikiPage.setTitle(Encode.forHtml(wikiPage.getTitle()));
		wikiPage.setContent(Encode.forHtml(wikiPage.getContent()));

		WikiPage updatedWikiPage = WikiPageDAO.updateWikiPage(GWTUtil.copy(wikiPage));

		if (updatedWikiPage == null) {
			throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMWikiService, ErrorCode.CAUSE_Database), "Not possible doing update");
		} else {
			return GWTUtil.copy(updatedWikiPage);
		}
	} catch (DatabaseException e) {
		log.error(e.getMessage(), e);
		throw new OKMException(ErrorCode.get(ErrorCode.ORIGIN_OKMWikiService, ErrorCode.CAUSE_Database), e.getMessage());
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:22,代码来源:WikiServlet.java

示例11: processRequest

import org.owasp.encoder.Encode; //导入依赖的package包/类
private void processRequest(Request request, Response response, CompositeValve compositeValve,
                            AuthenticationInfo authenticationInfo) {
    switch (authenticationInfo.getStatus()) {
    case SUCCESS:
    case CONTINUE:
        this.getNext().invoke(request, response, compositeValve);
        break;
    case FAILURE:
        String msg = "Failed to authorize incoming request";
        if (authenticationInfo.getMessage() != null && !authenticationInfo.getMessage().isEmpty()) {
            msg = authenticationInfo.getMessage();
            response.setHeader("WWW-Authenticate", "Basic");
        }

        if (log.isDebugEnabled()) {
            log.debug(msg + " , API : " + Encode.forUriComponent(request.getRequestURI()));
        }
        AuthenticationFrameworkUtil.handleResponse(request, response, HttpServletResponse.SC_UNAUTHORIZED, msg);
        break;
    }
}
 
开发者ID:wso2,项目名称:carbon-device-mgt,代码行数:22,代码来源:WebappAuthenticationValve.java

示例12: getAdditionalRequestParams

import org.owasp.encoder.Encode; //导入依赖的package包/类
private Map<String, String> getAdditionalRequestParams(HttpServletRequest request,
                                                       AuthenticationContext context) {
    Map<String, String> reqParamMap = new HashMap<String, String>();
    Map<String, String> authenticatorProperties = context.getAuthenticatorProperties();

    if (authenticatorProperties != null) {
        String queryString = authenticatorProperties.get(FrameworkConstants.QUERY_PARAMS);
        if (queryString != null) {
            reqParamMap = SSOUtils.getQueryMap(queryString);
        }
    }

    String fidp = request.getParameter("domain");
    if (fidp != null) {
        reqParamMap.put("fidp", Encode.forHtmlAttribute(fidp));
    }

    return reqParamMap;
}
 
开发者ID:wso2-attic,项目名称:carbon-identity,代码行数:20,代码来源:SAMLSSOAuthenticator.java

示例13: escapeUrlPart

import org.owasp.encoder.Encode; //导入依赖的package包/类
/**
	 * Escapes a url part so bad characters (/<.space) don't get included.
	 * <a href="StaticVoidGames.com/example/ESCAPE THIS">blah</a>
	 */
	public static String escapeUrlPart(String part){
		if(part == null){
			return null;
		}
		
		return Encode.forUriComponent(part);
		
//		try {
//			return UriUtils.encodePathSegment(part, "UTF-8");
//		} 
//		catch (UnsupportedEncodingException e) {
//			e.printStackTrace();
//		}
		
		//return null;
	}
 
开发者ID:KevinWorkman,项目名称:StaticVoidGames,代码行数:21,代码来源:HtmlEscaper.java

示例14: process

import org.owasp.encoder.Encode; //导入依赖的package包/类
public static String process(
        HttpServletRequest request, HttpServletResponse response, ServletConfig config)
        throws Exception {

    String resourcePath = request.getParameter("resourcePath");
    String description = request.getParameter("description");
    description = Encode.forHtmlContent(description);

    description = description.replaceAll("<br>", "\n");
    String cookie = (String) request.
            getSession().getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE);

    ResourceServiceClient client =
            new ResourceServiceClient(cookie, config, request.getSession());
    client.setDescription(resourcePath, description);

    return description;
}
 
开发者ID:wso2,项目名称:carbon-registry,代码行数:19,代码来源:SetDescriptionProcessor.java

示例15: forCssString

import org.owasp.encoder.Encode; //导入依赖的package包/类
/**
 * Encodes for CSS strings.
 *
 * @param input CSS input, may be null
 *
 * @return Encoded CSS, empty string if anything goes wrong
 */
public String forCssString( String input )
{
    if( isEmpty( input ) )
    {
        return EMPTY;
    }
    try
    {
        return Encode.forCssString( input );
    }
    catch( Exception ex )
    {
        LOG.error( "Encoding for CSS string error, will return empty string: {}", ex.getMessage(), ex );
        return EMPTY;
    }
}
 
开发者ID:werval,项目名称:werval,代码行数:24,代码来源:Sanitize.java


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