(GLPI 23730) Desenvolver via ADM para limpeza de Cache
bug#19140 dev: trevezani qua: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Web/trunk/ventaboletos@101542 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
be38c326bb
commit
0c4fad6b87
|
@ -0,0 +1,153 @@
|
||||||
|
package com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import javax.xml.bind.DatatypeConverter;
|
||||||
|
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.auth.AuthenticationException;
|
||||||
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
|
import org.apache.http.client.ClientProtocolException;
|
||||||
|
import org.apache.http.client.HttpClient;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.impl.auth.BasicScheme;
|
||||||
|
import org.apache.http.impl.client.DefaultHttpClient;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.zkoss.zk.ui.util.Clients;
|
||||||
|
import org.zkoss.zul.Messagebox;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.nimbusds.jose.JOSEException;
|
||||||
|
import com.nimbusds.jose.JWSAlgorithm;
|
||||||
|
import com.nimbusds.jose.JWSHeader;
|
||||||
|
import com.nimbusds.jose.JWSObject;
|
||||||
|
import com.nimbusds.jose.Payload;
|
||||||
|
import com.nimbusds.jose.crypto.MACSigner;
|
||||||
|
import com.nimbusds.jwt.JWTClaimsSet;
|
||||||
|
import com.rjconsultores.ventaboletos.service.ConstanteService;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.menu.DefaultItemMenuSistema;
|
||||||
|
import com.rjconsultores.ventaboletos.web.utilerias.spring.AppContext;
|
||||||
|
|
||||||
|
public class ItemMenuLimparCacheLocalidadesAPI extends DefaultItemMenuSistema {
|
||||||
|
private static Logger log = Logger.getLogger(ItemMenuLimparCacheLocalidadesAPI.class);
|
||||||
|
|
||||||
|
private static final String secret = "#KO&Fm4_k.sU9M8`6Mx'F\\\"H:*Qxu]6F4r,)JmZ2Jwafd)I.2[RET'1:)VQ6mG9,";
|
||||||
|
private static final int minutesExpireToken = 10;
|
||||||
|
|
||||||
|
public ItemMenuLimparCacheLocalidadesAPI() {
|
||||||
|
super("indexController.mniLimparCacheLocalidadesAPI.label");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getClaveMenu() {
|
||||||
|
return "COM.RJCONSULTORES.ADMINISTRACION.GUI.SEGURIDAD.MENU.RECARREGARCACHELOCALIDADESAPI";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void ejecutar() {
|
||||||
|
String url = getURLAPI();
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(url)) {
|
||||||
|
Clients.alert(org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.message.naoconfigurado"),
|
||||||
|
org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.title"), Messagebox.INFORMATION);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!url.endsWith("/")) {
|
||||||
|
url += "/";
|
||||||
|
}
|
||||||
|
|
||||||
|
url = url.concat("adm/limparCache");
|
||||||
|
|
||||||
|
|
||||||
|
HttpClient client = new DefaultHttpClient();
|
||||||
|
HttpGet request = new HttpGet(url);
|
||||||
|
|
||||||
|
String message = "Erro não identificado.";
|
||||||
|
|
||||||
|
try {
|
||||||
|
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("internal", getToken());
|
||||||
|
request.addHeader(new BasicScheme().authenticate(creds, request));
|
||||||
|
|
||||||
|
HttpResponse response = client.execute(request);
|
||||||
|
|
||||||
|
if (response.getStatusLine().getStatusCode() == 401) {
|
||||||
|
message = "Acesso negado";
|
||||||
|
|
||||||
|
} else if (response.getStatusLine().getStatusCode() == 200) {
|
||||||
|
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
|
||||||
|
|
||||||
|
String line = "";
|
||||||
|
|
||||||
|
StringBuilder result = new StringBuilder("");
|
||||||
|
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
message = result.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (ClientProtocolException e) {
|
||||||
|
message = e.getMessage();
|
||||||
|
} catch (IOException e) {
|
||||||
|
message = e.getMessage();
|
||||||
|
} catch (AuthenticationException e) {
|
||||||
|
message = "Erro de autenticação";
|
||||||
|
} catch (JOSEException e) {
|
||||||
|
message = "Erro de autenticação";
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("LimparCacheLocalidadesAPI :: " + message);
|
||||||
|
|
||||||
|
try {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
HashMap<String, String> map = new Gson().fromJson(message, HashMap.class);
|
||||||
|
|
||||||
|
if (map.containsKey("message")) {
|
||||||
|
message = map.get("message");
|
||||||
|
} else if (map.containsKey("mensagem")) {
|
||||||
|
message = map.get("mensagem");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error(e.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
Clients.alert(message, org.zkoss.util.resource.Labels.getLabel("limparCacheLocalidadesAPI.title"), Messagebox.INFORMATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getURLAPI() {
|
||||||
|
ApplicationContext appContext = AppContext.getApplicationContext();
|
||||||
|
ConstanteService constanteService = (ConstanteService) appContext.getBean("constanteService");
|
||||||
|
|
||||||
|
return constanteService.buscarURLAPI();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getToken() throws JOSEException {
|
||||||
|
long ttlMillis = minutesExpireToken * 60000;
|
||||||
|
long nowMillis = System.currentTimeMillis();
|
||||||
|
long expMillis = nowMillis + ttlMillis;
|
||||||
|
|
||||||
|
JWTClaimsSet claims = new JWTClaimsSet.Builder()
|
||||||
|
.claim("sub", new SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new Date()))
|
||||||
|
.claim("userId", "adm")
|
||||||
|
.claim("role", "ROLE_TOKEN")
|
||||||
|
.claim("exp", expMillis)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
JWSObject jwsObject = new JWSObject(new JWSHeader(JWSAlgorithm.HS256),
|
||||||
|
new Payload(claims.toJSONObject()));
|
||||||
|
|
||||||
|
jwsObject.sign(new MACSigner(DatatypeConverter.parseBase64Binary(secret)));
|
||||||
|
|
||||||
|
return jwsObject.serialize();
|
||||||
|
}
|
||||||
|
}
|
|
@ -277,6 +277,7 @@ seguridad.painelBpe=com.rjconsultores.ventaboletos.web.utilerias.menu.item.segur
|
||||||
seguridad.contingencia=com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad.ItemMenuContingencia
|
seguridad.contingencia=com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad.ItemMenuContingencia
|
||||||
seguridad.reenvioBpe=com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad.ItemMenuReenvioBPe
|
seguridad.reenvioBpe=com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad.ItemMenuReenvioBPe
|
||||||
seguridad.reenvioBpe=com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad.ItemMenuExtrairBPeXml
|
seguridad.reenvioBpe=com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad.ItemMenuExtrairBPeXml
|
||||||
|
seguridad.limparCacheLocalidadesAPI=com.rjconsultores.ventaboletos.web.utilerias.menu.item.seguridad.ItemMenuLimparCacheLocalidadesAPI
|
||||||
pasajerofrecuente=com.rjconsultores.ventaboletos.web.utilerias.menu.item.pasajerofrecuente.MenuPasajeroFrecuente
|
pasajerofrecuente=com.rjconsultores.ventaboletos.web.utilerias.menu.item.pasajerofrecuente.MenuPasajeroFrecuente
|
||||||
pasajerofrecuente.cliente=com.rjconsultores.ventaboletos.web.utilerias.menu.item.pasajerofrecuente.ItemMenuCliente
|
pasajerofrecuente.cliente=com.rjconsultores.ventaboletos.web.utilerias.menu.item.pasajerofrecuente.ItemMenuCliente
|
||||||
pasajerofrecuente.importarClientes=com.rjconsultores.ventaboletos.web.utilerias.menu.item.pasajerofrecuente.ItemMenuImportarClientes
|
pasajerofrecuente.importarClientes=com.rjconsultores.ventaboletos.web.utilerias.menu.item.pasajerofrecuente.ItemMenuImportarClientes
|
||||||
|
|
|
@ -8615,4 +8615,8 @@ filtroTaxaEmbarqueW2i.tblEstoque.label = Qtd. Estoque
|
||||||
filtroTaxaEmbarqueW2i.MSG.informarDatas= Favor informar a Localidade de origem.
|
filtroTaxaEmbarqueW2i.MSG.informarDatas= Favor informar a Localidade de origem.
|
||||||
filtroTaxaEmbarqueW2i.MSG.NaoExisteConfiguracao = Não existe configuração de estoque para esta pesquisa.
|
filtroTaxaEmbarqueW2i.MSG.NaoExisteConfiguracao = Não existe configuração de estoque para esta pesquisa.
|
||||||
filtroTaxaEmbarqueW2i.MSG.erroPesquisa= Erro ao realizar pesquisa de estoque.
|
filtroTaxaEmbarqueW2i.MSG.erroPesquisa= Erro ao realizar pesquisa de estoque.
|
||||||
filtroTaxaEmbarqueW2i.labelAviso.value= Atenção. Certifique-se que todos os dados da corrida estejam de acordo com a pesquisa. Somente a categoria da corrida pode variar se houver 'TODAS' no resultado.
|
filtroTaxaEmbarqueW2i.labelAviso.value= Atenção. Certifique-se que todos os dados da corrida estejam de acordo com a pesquisa. Somente a categoria da corrida pode variar se houver 'TODAS' no resultado.
|
||||||
|
|
||||||
|
indexController.mniLimparCacheLocalidadesAPI.label = Recarregar Cache Localidades API
|
||||||
|
limparCacheLocalidadesAPI.title = Localidades (API)
|
||||||
|
limparCacheLocalidadesAPI.message.naoconfigurado=A constante de configuração da URL da API não foi encontrada.
|
||||||
|
|
|
@ -9158,4 +9158,8 @@ filtroTaxaEmbarqueW2i.tblEstoque.label = Qtd. Estoque
|
||||||
filtroTaxaEmbarqueW2i.MSG.informarDatas= Favor informar a Localidade de origem.
|
filtroTaxaEmbarqueW2i.MSG.informarDatas= Favor informar a Localidade de origem.
|
||||||
filtroTaxaEmbarqueW2i.MSG.NaoExisteConfiguracao = Não existe configuração de estoque para esta pesquisa.
|
filtroTaxaEmbarqueW2i.MSG.NaoExisteConfiguracao = Não existe configuração de estoque para esta pesquisa.
|
||||||
filtroTaxaEmbarqueW2i.MSG.erroPesquisa= Erro ao realizar pesquisa de estoque.
|
filtroTaxaEmbarqueW2i.MSG.erroPesquisa= Erro ao realizar pesquisa de estoque.
|
||||||
filtroTaxaEmbarqueW2i.labelAviso.value= Atenção. Certifique-se que todos os dados da corrida estejam de acordo com a pesquisa. Somente a categoria da corrida pode variar se houver 'TODAS' no resultado.
|
filtroTaxaEmbarqueW2i.labelAviso.value= Atenção. Certifique-se que todos os dados da corrida estejam de acordo com a pesquisa. Somente a categoria da corrida pode variar se houver 'TODAS' no resultado.
|
||||||
|
|
||||||
|
indexController.mniLimparCacheLocalidadesAPI.label = Recarregar Cache de Localidades (API)
|
||||||
|
limparCacheLocalidadesAPI.title = Localidades (API)
|
||||||
|
limparCacheLocalidadesAPI.message.naoconfigurado=A constante de configuração da URL da API não foi encontrada.
|
||||||
|
|
Loading…
Reference in New Issue