yWorks / yGuard

The open-source Java obfuscation tool working with Ant and Gradle by yWorks - the diagramming experts

Home Page:https://yworks.github.io/yGuard/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unique class name generation

patbaumgartner opened this issue · comments

I am facing an issue with a Spring Boot app and Component-Scanning and couldn't find the feature to create obfuscated unique class names. And if it exists, I could not find it in the documentation.

So basically, the issue is that there are two beans with the same name but in different packages. Spring, takes for unnamed Spring Beans, the class name as the Bean name. Bean names need to be unique.

Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'a' for bean class [org.springframework.samples.petclinic.C.A] conflicts with existing, non-compatible bean definition of same name and class [org.springframework.samples.petclinic.A.A]

For ProGuard I found a setting useuniqueclassmembernames which solves the issue.

I haven't used Spring before, but this sounds like a pretty annoying requirement. Are you sure that obfuscating the names would work, and it's just the clashing names? If it's just a handful of beans, you might workaround this by either excluding those bean class names from obfuscation or by specifying a mapping manually for some of those beans.

There is no naming strategy implemented that uses unique obfuscated class names across packages. This a very obscure requirement for an obfuscation, as typically either the name doesn't matter and will be considered fully qualified or the name is used for other reflective purposes and may not be changed at all. Both is supported, but not this special requirement. It wouldn't be too difficult to implement, as the renaming part is already pluggable. Since you are the first one to come across the problem, I am not sure whether this is a) a solution or b) worth the implementation effort. I would be happy to merge a pull request for the new feature, though.

Thanks, @yGuy, for your prompt feedback. I understand your concerns. The problem is just how Springs uses component-scanning. I can use @Component("BeanName") to make names explicit and don't need to rely on the fallback of the class names.

I will investigate further. Thanks!

commented

Hi @patbaumgartner, I am struggling with the same issue, did you figure out anything? I appreciate your sharing.

Hi @congcoi123 - Unfortunately, besides the idea to make my Spring Beans names not dependent on the class name, I did not make progress. Will try harder and update the thread.

commented

Thanks for your response @patbaumgartner . Actually I tried other approaches but they didn't work even by using proguard. I know it's not appropriated to mention other tools here, but as you mentioned you successfully made it work (spring boot, maven, proguard, I guess), could you please share your configuration in pom.xml file? Thanks.

Hi @congcoi123. Unfortunately, I was not successful with Proguard yet.

commented

Thanks again for your prompt reply @patbaumgartner. I am looking for alternative solutions and am willing to share if I find them.

Hi @congcoi123 why not keep the bean classes you are interested in with their original name and obfuscate only the rest of the application? This could be as simple as adding an appropriate keep section to your configuration.