Search in sources :

Example 16 with PresentableUnloggedException

use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.

the class AutenticarPost method run.

@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
    String usuariosRestritos = Utils.getUsuariosRestritos();
    if (usuariosRestritos != null) {
        if (!ArrayUtils.contains(usuariosRestritos.split(","), req.username))
            throw new PresentableUnloggedException("Usuário não autorizado.");
    }
    // Read list from connected systems
    String[] systems = Utils.getSystems();
    if (systems == null)
        return;
    String authorization = "Basic " + SwaggerUtils.base64Encode((req.username + ":" + req.password).getBytes());
    Map<String, SwaggerCallParameters> mapp = new HashMap<>();
    for (String system : systems) {
        String urlsys = Utils.getApiUrl(system);
        IUsuarioUsernameGet.Request q = new IUsuarioUsernameGet.Request();
        q.username = req.username;
        mapp.put(system, new SwaggerCallParameters(system + "-autenticar-usuário", authorization, "GET", urlsys + "/usuario/" + req.username, q, IUsuarioUsernameGet.Response.class));
    }
    SwaggerMultipleCallResult mcr = SwaggerCall.callMultiple(mapp, BalcaojusServlet.TIMEOUT_MILLISECONDS);
    resp.status = Utils.getStatus(mcr);
    String origem = null;
    String usuarios = null;
    String cpf = null;
    String nome = null;
    String email = null;
    for (String system : mcr.responses.keySet()) {
        IUsuarioUsernameGet.Response u = (IUsuarioUsernameGet.Response) mcr.responses.get(system);
        if (u.codusu == null)
            continue;
        if (origem == null)
            origem = u.interno ? "int" : "ext";
        else if ((origem.equals("int") && !u.interno) || (origem.equals("ext") && u.interno))
            origem = "int/ext";
        if (u.cpf != null)
            cpf = u.cpf;
        if (u.nome != null)
            nome = u.nome;
        if (u.email != null)
            email = u.email;
        if (usuarios == null)
            usuarios = "";
        else
            usuarios += ";";
        usuarios += system + "," + u.codusu + "," + (u.interno ? "int" : "ext") + "," + serialize(u.codentidade != null && !u.codentidade.equals("0") ? u.codentidade : null) + "," + serialize(u.entidade) + "," + serialize(u.codunidade != null && !u.codunidade.equals("0") ? u.codunidade : null) + "," + serialize(u.unidade) + "," + (u.perfil != null && !u.perfil.equals("") ? u.perfil.toLowerCase() : "null");
    }
    if (usuarios == null)
        throw new SwaggerAuthorizationException("Credenciais rejeitadas. Base" + (systems.length == 1 ? "" : "s") + " acessada" + (systems.length == 1 ? "" : "s") + ": " + Utils.getSystemsNames() + ".", mcr.status);
    String jwt = jwt(origem, req.username, cpf, nome, email, usuarios);
    verify(jwt);
    resp.id_token = jwt;
    Cookie cookie = buildCookie(jwt);
    SwaggerServlet.getHttpServletResponse().addCookie(cookie);
    Usuario.setSenha(req.username, req.password);
}
Also used : Cookie(javax.servlet.http.Cookie) IUsuarioUsernameGet(br.jus.trf2.sistemaprocessual.ISistemaProcessual.IUsuarioUsernameGet) HashMap(java.util.HashMap) SwaggerCallParameters(com.crivano.swaggerservlet.SwaggerCallParameters) SwaggerAuthorizationException(com.crivano.swaggerservlet.SwaggerAuthorizationException) HttpServletResponse(javax.servlet.http.HttpServletResponse) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) SwaggerMultipleCallResult(com.crivano.swaggerservlet.SwaggerMultipleCallResult)

Example 17 with PresentableUnloggedException

use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.

the class AvisoConfirmadoXmlGet method run.

@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
    Usuario u = BalcaojusServlet.getPrincipal();
    if (u.isInterno())
        throw new PresentableUnloggedException("Exportação XML de avisos confirmados disponível apenas para usuários externos");
    resp.jwt = DownloadJwtFilenameGet.jwt(u.origem, u.usuario, null, null, null, null, "avisos-confirmados.xml", null, null, null, null, null);
}
Also used : Usuario(br.jus.trf2.balcaojus.AutenticarPost.Usuario) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException)

Example 18 with PresentableUnloggedException

use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.

the class AvisoPendenteXmlGet method run.

@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
    Usuario u = BalcaojusServlet.getPrincipal();
    if (u.isInterno())
        throw new PresentableUnloggedException("Exportação XML de avisos disponível apenas para usuários externos");
    resp.jwt = DownloadJwtFilenameGet.jwt(u.origem, u.usuario, null, null, null, null, "avisos-pendentes.xml", null, null, null, null, null);
}
Also used : Usuario(br.jus.trf2.balcaojus.AutenticarPost.Usuario) PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException)

Example 19 with PresentableUnloggedException

use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.

the class CertidaoAutenticarNumeroCpfcnpjGet method run.

@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
    if (!CertidaoObterTokenGet.isValidToken(req.token, req.numero, null, req.cpfcnpj))
        throw new PresentableException("Token inválido");
    FetchResponse r = CertidaoEmitirRequisitanteCpfcnpjPost.fetch(Utils.getCertApiUrl(req.sistema) + "/bv_consul_cert_neg.asp", Utils.getCertApiPassword(req.sistema), "POST", "Botao=Consultar&NumProt=" + req.numero + "&NumDocPess=" + req.cpfcnpj);
    if (r.headerFields.containsKey(Utils.ERROR_MESSAGE))
        throw new PresentableUnloggedException(r.headerFields.get(Utils.ERROR_MESSAGE).get(0));
    resp.html = r.html;
    if (r.headerFields.containsKey(Utils.RESULT_KIND)) {
        resp.tipo = r.headerFields.get(Utils.RESULT_KIND).get(0);
        resp.html = Utils.obterHtml(resp.html, resp.tipo);
    }
    if (r.headerFields.containsKey(Utils.CERT_NUMBER))
        resp.numero = r.headerFields.get(Utils.CERT_NUMBER).get(0);
}
Also used : PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) PresentableException(com.crivano.swaggerservlet.PresentableException) FetchResponse(br.jus.trf2.balcaojus.CertidaoEmitirRequisitanteCpfcnpjPost.FetchResponse)

Example 20 with PresentableUnloggedException

use of com.crivano.swaggerservlet.PresentableUnloggedException in project balcaovirtual by trf2-jus-br.

the class CertidaoRequererRequisitanteCpfcnpjPost method run.

@Override
public void run(Request req, Response resp, BalcaojusContext ctx) throws Exception {
    if (!CertidaoObterTokenGet.isValidToken(req.token, null, req.requisitante, req.cpfcnpj))
        throw new PresentableException("Token inválido");
    FetchResponse r = CertidaoEmitirRequisitanteCpfcnpjPost.fetch(Utils.getCertApiUrl(req.sistema) + "/bv_conf_req_cert.asp", Utils.getCertApiPassword(req.sistema), "POST", "Botao=Requerer&NumDocPessReq=" + req.requisitante + "&NumDoc=" + req.cpfcnpj + "&Nome=" + URLEncoder.encode(req.nome, "ISO-8859-1"));
    if (r.headerFields.containsKey(Utils.ERROR_MESSAGE))
        throw new PresentableUnloggedException(r.headerFields.get(Utils.ERROR_MESSAGE).get(0));
    resp.html = r.html;
    if (r.headerFields.containsKey(Utils.RESULT_KIND)) {
        resp.tipo = r.headerFields.get(Utils.RESULT_KIND).get(0);
        resp.html = Utils.obterHtml(resp.html, resp.tipo);
    }
    if (r.headerFields.containsKey(Utils.CERT_NUMBER))
        resp.numero = r.headerFields.get(Utils.CERT_NUMBER).get(0);
}
Also used : PresentableUnloggedException(com.crivano.swaggerservlet.PresentableUnloggedException) PresentableException(com.crivano.swaggerservlet.PresentableException) FetchResponse(br.jus.trf2.balcaojus.CertidaoEmitirRequisitanteCpfcnpjPost.FetchResponse)

Aggregations

PresentableUnloggedException (com.crivano.swaggerservlet.PresentableUnloggedException)28 Usuario (br.jus.trf2.balcaojus.AutenticarPost.Usuario)19 UsuarioDetalhe (br.jus.trf2.balcaojus.AutenticarPost.UsuarioDetalhe)8 PresentableException (com.crivano.swaggerservlet.PresentableException)8 SwaggerAsyncResponse (com.crivano.swaggerservlet.SwaggerAsyncResponse)8 Processo (br.jus.trf2.balcaojus.model.Processo)6 Nota (br.jus.trf2.balcaojus.model.Nota)4 FetchResponse (br.jus.trf2.balcaojus.CertidaoEmitirRequisitanteCpfcnpjPost.FetchResponse)3 TipoProcessoJudicial (br.jus.cnj.intercomunicacao_2_2.TipoProcessoJudicial)2 ServicoIntercomunicacao222 (br.jus.cnj.servico_intercomunicacao_2_2.ServicoIntercomunicacao222)2 IUsuarioUsernameMesaIdDocumentoId2SalvarPost (br.jus.trf2.sistemaprocessual.ISistemaProcessual.IUsuarioUsernameMesaIdDocumentoId2SalvarPost)2 JWTVerifyException (com.auth0.jwt.JWTVerifyException)2 IOException (java.io.IOException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 ArrayList (java.util.ArrayList)2 SOAPException (javax.xml.soap.SOAPException)2 TransformerException (javax.xml.transform.TransformerException)2 Holder (javax.xml.ws.Holder)2