package br.com.petrobras.rj.portal.transpetromaritimos.conteudo.contentserviceinterface;
import java.io.IOException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import lumis.doui.service.DouiServiceInterface;
import lumis.portal.PortalException;
import lumis.portal.authentication.SessionConfig;
import lumis.portal.manager.ManagerException;
import lumis.portal.manager.ManagerFactory;
import lumis.portal.serviceinterface.IServiceInterfaceRenderRequest;
import lumis.portal.serviceinterface.IServiceInterfaceRenderResponse;
import lumis.portal.serviceinterface.ServiceInterfaceException;
import lumis.portal.transaction.ITransaction;
import lumis.portal.transaction.PortalTransactionFactory;
import lumis.util.CookieUtil;
public class UrlInternaInterface extends DouiServiceInterface {
public static final String PROPERTY_ID = "configURL";
@Override
public void render(IServiceInterfaceRenderRequest request, IServiceInterfaceRenderResponse response) throws ServiceInterfaceException, PortalException {
super.render(request, response);
final ITransaction currentTransaction = PortalTransactionFactory.getCurrentTransaction();
String pegaUrlCustomProperty = fetchEnabledProperty(request.getServiceInstanceConfig().getId(), request.getSessionConfig(), currentTransaction);
StringBuffer pegaRequestUrl = ((HttpServletRequest) request).getRequestURL();
int verificaUrlInterna = pegaRequestUrl.indexOf(pegaUrlCustomProperty);
if (verificaUrlInterna > 0) {
SessionConfig sc = ManagerFactory.getAuthenticationManager().login("UsuarioMaritimosTranspetro", "promef", currentTransaction);
if (sc != null) {
CookieUtil.addLumisUserCookies(request, response);
ManagerFactory.getAuthenticationManager().impersonate(sc.getUserId());
HttpServletResponse servletresponse = (HttpServletResponse) response;
try {
servletresponse.sendRedirect("main.jsp?lumPageId=8A92F2B030F682A40130F6843E8801B2");
} catch (IOException e) {
e.printStackTrace();
}
}
} else {
throw new PortalException("Endereço invalidos.");
}
}
private String fetchEnabledProperty(final String serviceInstanceId, SessionConfig session, ITransaction transaction) throws ManagerException, PortalException {
return ManagerFactory.getServiceInstanceManager().getCustomProperty(session, serviceInstanceId, PROPERTY_ID, transaction);
}
}