springboot+allatori代码混淆技术(踩过的坑)

最最基础的demo只有一个Controller返回字符串,注意!没有数据库!所以基本上网上能够搜索到的教程几乎都是一样的,所以不在此赘述,具体详见参考url:https://github.com/Lovnx/confusion。里面有非常详细的操作步骤。

大多数需要加密或者做混淆的代码肯定都会有数据库操作,而allatori.xml官方参考模板里面是这样:


    
        
    

    
        
            
            
        
    

    

具体xml配置说明请见参考文档,只说说我在将allatori运用到我的项目里面的时候遇到的坑,一开始LZ也像初学allatori一样,下载官方demo,跑一遍,诶!可以了。然后完全按照配置一步一步的加入到自己的项目里面,打包运行,结果连启动都有问题,当时一脸懵圈,赶快百度了一下,有大牛博客上面说springboot的一些启动类就不要混淆了,混淆代码肯定是想要混淆自写的那部分代码,而maven中所依赖的jar包是不需要混淆的,所以查看了文档配置说明,在此用上了xml文档中ignore-classes标签,见名知意,注明哪些类不需要混淆,试了一下,在allatori.xml中添加了如下配置:


	
	
	
	
	

满心欢喜的以为成功了,结果屡次在JpaRepository报错,代码如下:

springboot+allatori代码混淆技术(踩过的坑)_第1张图片

打包过程没有异常,运行过程中报错如下:

Caused by: java.lang.IllegalArgumentException: Failed to create query method public abstract com.panshi.server.model.FaceDataEntity com.panshi.server.dao.FaceDataRepository.findByUId(java.lang.String)! Unable to locate Attribute  with the the given name [uId] on this ManagedType [com.panshi.server.model.FaceDataEntity]
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:76)
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:101)
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfNotFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:207)
	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:77)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.(RepositoryFactorySupport.java:451)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:223)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277)
	at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263)
	at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:101)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1692)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1630)
	... 63 common frames omitted
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute  with the the given name [uId] on this ManagedType [com.panshi.server.model.FaceDataEntity]
	at org.hibernate.jpa.internal.metamodel.AbstractManagedType.checkNotNull(AbstractManagedType.java:128)
	at org.hibernate.jpa.internal.metamodel.AbstractManagedType.getAttribute(AbstractManagedType.java:113)
	at org.springframework.data.jpa.repository.query.QueryUtils.toExpressionRecursively(QueryUtils.java:570)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.getTypedPath(JpaQueryCreator.java:359)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator$PredicateBuilder.build(JpaQueryCreator.java:302)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator.toPredicate(JpaQueryCreator.java:207)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:115)
	at org.springframework.data.jpa.repository.query.JpaQueryCreator.create(JpaQueryCreator.java:52)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createCriteria(AbstractQueryCreator.java:109)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:88)
	at org.springframework.data.repository.query.parser.AbstractQueryCreator.createQuery(AbstractQueryCreator.java:73)
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.(PartTreeJpaQuery.java:133)
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$CountQueryPreparer.(PartTreeJpaQuery.java:259)
	at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:71)
	... 73 common frames omitted

就因为这个问题,困惑了一个上午,因为对于allatori网上的资料非常之少,基本上就是和demo一模一样,后来仔仔细细一琢磨才发现,个人理解是这样,JPA操作是按照方法名称去创建sql语句查询的,虽然反编译发现方法名称并没有改变,但是也不知道为什么,就是在jpaRepository的方法处报错,而且报错永远是告诉你方法参数不对。最后试了一下,将Dao层和Entity类都不要混淆,添加了如下代码:


	
	
	
	
	
	
	
	

最后运行成功了。

你可能感兴趣的:(代码安全,springboot)