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

spring boot web cannot be recognized after obfuscation

takeAction opened this issue · comments

I am using spring boot 2.x with maven and yguard(4.1.0), and this project is packaged as war.
This project only has two classes:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CustomerApplication {

	public static void main(String[] args) {

		SpringApplication.run(CustomerApplication.class, args);
	}
}

and

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class ServletInitializer extends SpringBootServletInitializer {

	@Override
	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {

		return application.sources(CustomerApplication.class);
	}
}

the config for yguard looks like:

<plugin>
    <artifactId>maven-antrun-plugin</artifactId>
	<version>3.1.0</version>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>run</goal>
			</goals>
			<id>obfuscate</id>
			<configuration>
				<target>
					<property name="runtime_classpath" refid="maven.runtime.classpath"/>
					<taskdef name="yguard" classname="com.yworks.yguard.YGuardTask" classpath="${runtime_classpath}"/>
					<yguard>
						<inoutpair in="${project.build.directory}/test.war" out="${project.basedir}/wars/test.war" />
						<rename mainclass="com.my.CustomerApplication"
											logfile="${project.build.directory}/yguard.log.xml">
							<keep>
								<class name="com.my.ServletInitializer" classes="protected" methods="protected" fields="protected"/>
							</keep>
						</rename>
					</yguard>
				</target>
			</configuration>
		</execution>
	</executions>
</plugin>

After obfuscation, I deploy the war to tomcat and start it, but there is no spring boot logo printed on tomcat terminal and there is info like org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath, while it should is 2 Spring WebApplicationInitializers detected on classpath without obfuscation.

It seems that this spring boot war is not recognized as spring boot, what I missing for the configuration?

the yguard log as follows:

<yguard version="1.5">
<expose>
  <class name="com.my.CustomerApplication"/>
  <method class="com.my.CustomerApplication" name="void main(java.lang.String[])"/>
  <class name="com.my.ServletInitializer"/>
  <method class="com.my.ServletInitializer" name="org.springframework.boot.builder.SpringApplicationBuilder configure(org.springframework.boot.builder.SpringApplicationBuilder)"/>
</expose>
<map>
</map>
</yguard>

yGuard does not support WAR archives. You probably loose whatever meta data your archive contains. To be able to create a WAR archive with yGuard-obfuscated classes, you need to

  1. package your application classes as a regular JAR archive,
  2. pass the aforementioned JAR archive to yGuard,
  3. extract the obfuscated classes from the JAR archive that yGuard created, and
  4. package the obfuscated classes as a WAR archive.

The processing example demonstrates repackaging for a Spring Boot JAR (i.e. application classes in BOOT_INF).

Moreover, according to your yGuard log, yGuard did not rename anything. This supports the assumption that you are loosing meta data.

Finally, you should probably pass (Spring) compile-time dependencies to yGuard as externalclasses.

Hi @takeAction, you could have looked at our issue tracker, where this question had been asked 8 times previously. As Thomas outlined, you can follow the processing example.
Small note aside @thomasbehr, maybe this deserves its own section in the README to prevent these kinds of tickets in the future?
Closing as duplicate.

Thanks thomasbehr and Fohlen, Sorry, it's my fault, I searched it on google but seldom about yguard spring boot, thus I didn't search from the issue tracker before asking this time. @Fohlen , as you said, It's a good idea to mark this limitation in the README.