All Downloads are FREE. Search and download functionalities are using the official Maven repository.

colesico.framework.rpc.clientapi.handler.BasicRequestHandler Maven / Gradle / Ivy

The newest version!
package colesico.framework.rpc.clientapi.handler;

import colesico.framework.profile.Profile;
import colesico.framework.profile.teleapi.ProfileSerializer;
import colesico.framework.rpc.teleapi.BasicEnvelope;
import colesico.framework.rpc.clientapi.RpcRequestHandler;
import colesico.framework.security.Principal;
import colesico.framework.security.teleapi.PrincipalSerializer;

import javax.inject.Provider;
import javax.inject.Singleton;

@Singleton
public class BasicRequestHandler implements RpcRequestHandler {

    private final PrincipalSerializer principalSerializer;
    private final ProfileSerializer profileSerializer;

    private final Provider principalProv;
    private final Provider profileProv;

    public BasicRequestHandler(PrincipalSerializer principalSerializer, ProfileSerializer profileSerializer, Provider principalProv, Provider profileProv) {
        this.principalSerializer = principalSerializer;
        this.profileSerializer = profileSerializer;
        this.principalProv = principalProv;
        this.profileProv = profileProv;
    }

    @Override
    public void onRequest(BasicEnvelope request) {
        Principal principal = principalProv.get();
        if (principal != null) {
            request.setPrincipal(principalSerializer.serialize(principal));
        } else {
            request.setPrincipal(null);
        }

        Profile profile = profileProv.get();
        if (profile != null) {
            request.setProfile(profileSerializer.serialize(profile));
        } else {
            request.setProfile(null);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy