Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux io problem #221

Open
rayacode opened this issue Dec 25, 2023 · 4 comments
Open

Linux io problem #221

rayacode opened this issue Dec 25, 2023 · 4 comments

Comments

@rayacode
Copy link

the application as systemctl service in debian 12
give error at two files
LoginNotificationConfig.java
SecSecurityConfig.java
error as:
root@debian:/opt# journalctl -u NoBios.service -e Dec 25 12:16:28 debian java[12609]: Caused by: o.s.b.f.BeanCreationException: Error creating bean with name 'GeoIPCity' defined in class path resource [ir/artlake/NoBios/spring/LoginNotificationConfig.class]: > Dec 25 12:16:28 debian java[12609]: at o.s.b.f.s.ConstructorResolver.instantiate(ConstructorResolver.java:654) Dec 25 12:16:28 debian java[12609]: at o.s.b.f.s.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:488) Dec 25 12:16:28 debian java[12609]: at o.s.b.f.s.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1332) Dec 25 12:16:28 debian java[12609]: at o.s.b.f.s.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1162) Dec 25 12:16:28 debian java[12609]: at o.s.b.f.s.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) Dec 25 12:16:28 debian java[12609]: ... 10 frames truncated Dec 25 12:16:28 debian java[12609]: ... 98 common frames omitted Dec 25 12:16:28 debian java[12609]: Caused by: o.s.b.BeanInstantiationException: Failed to instantiate [com.maxmind.geoip2.DatabaseReader]: Factory method 'databaseReader' threw exception with message: class p> Dec 25 12:16:28 debian java[12609]: at o.s.b.f.s.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171) Dec 25 12:16:28 debian java[12609]: at o.s.b.f.s.ConstructorResolver.instantiate(ConstructorResolver.java:650) Dec 25 12:16:28 debian java[12609]: ... 112 common frames omitted Dec 25 12:16:28 debian java[12609]: Caused by: j.i.FileNotFoundException: class path resource [maxmind/GeoLite2-City.mmdb] cannot be resolved to absolute file path because it does not reside in the file system> Dec 25 12:16:28 debian java[12609]: at o.s.u.ResourceUtils.getFile(ResourceUtils.java:217) Dec 25 12:16:28 debian java[12609]: at o.s.u.ResourceUtils.getFile(ResourceUtils.java:180) Dec 25 12:16:28 debian java[12609]: at i.a.N.s.LoginNotificationConfig.databaseReader(LoginNotificationConfig.java:23) Dec 25 12:16:28 debian java[12609]: at i.a.N.s.LoginNotificationConfig$$SpringCGLIB$$0.CGLIB$databaseReader$0(<generated>) Dec 25 12:16:28 debian java[12609]: at i.a.N.s.LoginNotificationConfig$$SpringCGLIB$$FastClass$$1.invoke(<generated>) Dec 25 12:16:28 debian java[12609]: ... 8 frames truncated Dec 25 12:16:28 debian java[12609]: ... 113 common frames omitted Dec 25 12:16:28 debian systemd[1]: NoBios.service: Main process exited, code=exited, status=1/FAILURE Dec 25 12:16:28 debian systemd[1]: NoBios.service: Failed with result 'exit-code'. Dec 25 12:16:28 debian systemd[1]: NoBios.service: Consumed 18.129s CPU time.

Error resolved by changing the code of GeoCity and GeoCountry to:
` @bean(name="GeoIPCity")
public DatabaseReader databaseReader() throws IOException{
Resource resource = new ClassPathResource("maxmind/GeoLite2-City.mmdb");
InputStream databaseStream = resource.getInputStream();
return new DatabaseReader.Builder(databaseStream).build();

}`

@Bean(name = "GeoIPCountry") public DatabaseReader databaseReader() throws IOException, GeoIp2Exception { Resource resource = new ClassPathResource("maxmind/GeoLite2-City.mmdb"); InputStream databaseStream = resource.getInputStream(); return new DatabaseReader.Builder(databaseStream).build(); }

@ulisseslima
Copy link
Contributor

Hey, @rayacode.

Please include a link to the article you're referring to so we can look into this.

@rayacode
Copy link
Author

rayacode commented Dec 31, 2023

there is no article, i tested on actual debian 12 local vps, by using apache2 as proxy server, and spring boot app(tomcat) of this project behind the apache2 server. there are some changes of mine to the project to fit to what i want, but not related to the issue.
seems like there an issue with the Spring ResourceUtils.getFile() methd, It is trying to access maxmind/GeoLite2-Country.mmdb but it is unable to find it, in modified method, "new ClassPathResource("maxmind/GeoLite2-City.mmdb")" creats resource that represents the maxmind/GeoLite2-City.mmdb file in the classpath, resource.getInputStream() then gets an InputStream that reads from the file the DatabaseReader.Builder constructor is changed to accept an InputStream instead of a File, allowig it to read from the maxmind/GeoLite2-City.mmdb file even when it is inside jar file

@ulisseslima
Copy link
Contributor

We're considering this article: https://www.baeldung.com/spring-security-restrict-authentication-by-geography

This issue will remain open until we look into this.

@rayacode
Copy link
Author

rayacode commented Jan 4, 2024

oh i see what you mean by article, i actually didn't read those completely, this repo is nice code template for the security of the web apps, i found it this way not by learning with articles... .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants