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

Add support for GraalVM native image #800

Open
ygyg70 opened this issue Apr 21, 2023 · 6 comments
Open

Add support for GraalVM native image #800

ygyg70 opened this issue Apr 21, 2023 · 6 comments

Comments

@ygyg70
Copy link

ygyg70 commented Apr 21, 2023

Is your feature request related to a problem? Please describe.
Notifications are not sent when run as a native image.
I was able to use the library after adding reflection configuration for these classes:
Message.class,
Notification.class,
AndroidConfig.class,
AndroidNotification.class,
AndroidFcmOptions.class,
WebpushConfig.class,
WebpushFcmOptions.class,
WebpushNotification.class,
ApnsConfig.class,
ApnsFcmOptions.class,
ApsAlert.class,
FcmOptions.class,
MessagingServiceResponse.class,
MessagingServiceErrorResponse.class

Describe the solution you'd like
Add reflect-config.json file to the project

Describe alternatives you've considered
Document how to achieve native image compatibility

@google-oss-bot
Copy link

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@CriPstian
Copy link

Is there any update on this? I am struggling with a native image build since adding the firebase-admin dependency.

@hmzgtl16
Copy link

Is there any update on this?

@VjekoslavKrainovic
Copy link

VjekoslavKrainovic commented Jan 7, 2024

Is there any update on this?

This is error i am getting:
[INFO] [creator] Jan 07, 2024 9:07:06 PM com.google.api.gax.nativeimage.NativeImageUtils registerClassForReflection [INFO] [creator] WARNING: Failed to find io.grpc.netty.shaded.io.netty.channel.ProtocolNegotiators on the classpath for reflection.

@waileong
Copy link

Hi everyone,

I've been working on GraalVM native image support for Spring Boot applications using Firebase Cloud Messaging (FCM) and wanted to share two projects that could help those facing similar challenges with native image compatibility:

Both projects demonstrate how to configure Spring Boot applications with FCM and make them GraalVM native image compatible, including handling reflection and other related issues. These might be helpful as examples or starting points for your own projects. Feel free to explore them and share feedback!

@oscarojeda
Copy link

Hello everyone. @waileong specially hi for you :)
I am having issues while validating a Firebase Auth idToken using the firebase admin sdk. When I compile as native, it works fine, the app boots up, but when it gets the first request it throws an error:

java.lang.NullPointerException: Failed to load: admin_sdk.properties
at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:924) ~[na:na]
at com.google.firebase.internal.SdkUtils.loadSdkVersion(SdkUtils.java:46) ~[na:na]
at com.google.firebase.internal.SdkUtils.(SdkUtils.java:31) ~[na:na]
at com.google.firebase.auth.internal.AuthHttpClient.(AuthHttpClient.java:38) ~[na:na]
at com.google.firebase.auth.multitenancy.FirebaseTenantClient.(FirebaseTenantClient.java:66) ~[na:na]
at com.google.firebase.auth.multitenancy.FirebaseTenantClient.(FirebaseTenantClient.java:53) ~[na:na]
at com.google.firebase.auth.multitenancy.TenantManager.(TenantManager.java:57) ~[location-receiver.exe:na]
at com.google.firebase.auth.FirebaseAuth$1.get(FirebaseAuth.java:77) ~[na:na]
at com.google.firebase.auth.FirebaseAuth$1.get(FirebaseAuth.java:74) ~[na:na]
at com.google.firebase.auth.AbstractFirebaseAuth$29.get(AbstractFirebaseAuth.java:1768) ~[na:na]
at com.google.common.base.Suppliers$NonSerializableMemoizingSupplier.get(Suppliers.java:186) ~[na:na]
at com.google.firebase.auth.FirebaseAuth.getTenantManager(FirebaseAuth.java:45) ~[location-receiver.exe:na]
at cl.seiza_ti.location_receiver.configuration.FirebaseAuthenticationFilter.doFilterInternal(FirebaseAuthenticationFilter.java:43) ~[location-receiver.exe:na]

I want to note that I am using the tenant manager as I am not using the default tenant in my GCP Project.

@component
public class FirebaseAuthenticationFilter extends OncePerRequestFilter {

@Autowired
FirebaseAuthConfiguration firebaseAuthConfiguration;

@Override
protected void doFilterInternal(
        HttpServletRequest request,
        HttpServletResponse response,
        FilterChain filterChain)
        throws ServletException, IOException {

    String idToken = request.getHeader("Authorization");

    if (idToken == null || idToken.isEmpty()) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Missing Authorization token");
        return;
    }

    try {
        FirebaseToken token =
                FirebaseAuth.getInstance().
                        getTenantManager().getAuthForTenant(firebaseAuthConfiguration.getTenantId())
                        .verifyIdToken(idToken.replace("Bearer ", ""));

        List<GrantedAuthority> authorities = getAuthoritiesFromToken(token);

        SecurityContextHolder.getContext()
                .setAuthentication(
                        new FirebaseAuthenticationToken(idToken, token, authorities));

        SecurityContextHolder.getContext().getAuthentication().setAuthenticated(true);

    } catch (Exception e) {
        response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid Firebase ID-Token");
        return;
    }

    filterChain.doFilter(request, response);
}

Does anyone have any idea of how to make it work?

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

7 participants