0

I have an authentication resource, where I want to authenticate users, as they log in via my front-end application.

I have a facade object, which i use to authenticate the user, and create a token as such

@GET
@Path("login")
@Produces(APPLICATION_JSON)
public Response authenticateUser(@FormParam("email") String email, @FormParam("password") String password) {

    try {
        //skal måske ændres til bruger
        User user = authenticationFacade.authenticateUser(email, password);

        String token = authenticationFacade.generateAuthenticationToken(user);

     return Response.ok(gson.toJson(user)).header(AUTHORIZATION, "Bearer " + token).build();

but i have a few doubts, about how to create my authentication facade, i have seen people use this convention:

   @Inject
   private AuthenticationFacade authenticationFacade;

and I have seen somebody, just instantiate the object:

    private AuthenticationFacade authenticationFacade = new AuthenticationFacade();

In this context, what difference would it make, and what would be the best practice?

Ating
  • 2,540
  • 1
  • 11
  • 39

0 Answers0