Get a return from a method in another Java class

0

I have a method in my Spring boot API that receives the data of the user that is logging, checks if it exists and if the password confers. Then return returns a JWT token. I need to get this token return in another Java class. I can not do it.

My method that receives the user and generates the token.

@RequestMapping(value = "/autenticar", consumes = MediaType.APPLICATION_JSON_UTF8_VALUE, method = RequestMethod.POST)
public LoginResponse autenticar(@RequestBody Usuarios usuarios)
        throws ServletException {

    // verifica se foram digitados o login e senha no front end
    if (usuarios.getLogin() == null
            || usuarios.getSenha() == null) {
        throw new  ServletException("Nome ou senha obrigatório");

    }

    // busca no banco de dados
    Usuarios usuariosAutenticado = uService.buscarPorLogin(usuarios.getLogin());

    if (usuariosAutenticado == null) {
        return new LoginResponse("naoEncontrado");
    }       

    // compara a senha vinda do banco de dados com a senha vinda da tela
    if (!usuariosAutenticado.getSenha()
            .equals(usuarios.getSenha())) {
        return new LoginResponse("senhaInvalida");
    }

    String token = Jwts.builder().setSubject(usuariosAutenticado.getLogin())
            .signWith(SignatureAlgorithm.HS512, "xxx")
            .setExpiration(new Date(System.currentTimeMillis() + 60 * 60 * 1000)).compact();            

    return new LoginResponse(token);
}

I need to get the token return within this method

public void newRevision(Object revisionEntity) {
    AuditEntity revEntity = (AuditEntity) revisionEntity;

    //aqui e preciso do token
}

How can I do this ???

    
asked by anonymous 20.12.2017 / 11:16

0 answers