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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations