Skip to content

Instantly share code, notes, and snippets.

View gscordeiro's full-sized avatar

Gilliard Cordeiro gscordeiro

View GitHub Profile
@gscordeiro
gscordeiro / persistence.xml
Created December 16, 2012 19:10
Arquivo com configuração básica da JPA
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="default">
<properties>
<property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
<property name="javax.persistence.jdbc.url" value="jdbc:h2:~/faces-motors" />
@gscordeiro
gscordeiro / gist:4170587
Created November 29, 2012 17:27
Servlet para carregar imagem
@WebServlet(urlPatterns="/carrega-imagem")
public class ImagemServlet extends HttpServlet{
private static final long serialVersionUID = -4433688269834762430L;
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String id = req.getParameter("auto_id");
Automovel automovel = JpaUtil.getEntityManager().find(Automovel.class, Long.valueOf(id));
@gscordeiro
gscordeiro / gist:1290208
Created October 15, 2011 21:56
Passando direto pela validação do certificado
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
@gscordeiro
gscordeiro / gist:1290164
Created October 15, 2011 21:17
Adiciona truststore no client WS
String clientTruststorePath = Main.class.getResource("/META-INF/client.truststore").getPath();
System.setProperty("javax.net.ssl.trustStore", clientTruststorePath);
System.setProperty("javax.net.ssl.trustStorePassword", "a1234b");
@gscordeiro
gscordeiro / gist:1290086
Created October 15, 2011 20:20
Comandos para geração de certificados
#geração da chave e armazenamento no keystore
keytool -genkey -alias certificado_servidor -keyalg RSA -validity 1000 -keystore server.keystore
#extração da chave que estava no keystore para um arquivo separado
keytool -export -alias certificado_servidor -keystore server.keystore -file server.cer
#criação de um truststore do cliente contendo a chave do servidor
keytool -import -alias certificado_servidor -keystore client.truststore -file server.cer
@gscordeiro
gscordeiro / gist:1290002
Created October 15, 2011 19:11
Rest authentication client
Credentials credentials = new UsernamePasswordCredentials("xico", "xico123");
HttpClient httpClient = new HttpClient();
httpClient.getState().setCredentials(AuthScope.ANY, credentials);
httpClient.getParams().setAuthenticationPreemptive(true);
ClientExecutor clientExecutor = new ApacheHttpClientExecutor(httpClient);
@gscordeiro
gscordeiro / gist:1289940
Created October 15, 2011 18:32
JBoss BASIC Authentication
<!-- no web.xml -->
<security-constraint>
<display-name>require valid user</display-name>
<web-resource-collection>
<web-resource-name>internal application</web-resource-name>
<!-- secure only admin pages-->
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
@gscordeiro
gscordeiro / gist:1229521
Created September 20, 2011 16:05
Inscrição simples do Jmeetings
class InscricaoController {
//...
def inscricaoSimples = {
def inscricaoInstance = new Inscricao(params)
/*if(inscricaoInstance.validate() & inscricaoInstance.participante.validate(['nome', 'email'])){
inscricao.save(validate: false)
}*/
if(inscricaoInstance.inscricaoSimples()){