Skip to content

Instantly share code, notes, and snippets.

View jamestrandung's full-sized avatar

James Tran jamestrandung

View GitHub Profile
@jamestrandung
jamestrandung / Create certificate
Last active December 15, 2015 10:09
Command line
<JAVA_HOME>\bin\keytool -genkey -alias s1as -keyalg RSA -keypass newpass -storepass newpass -keystore keystore.jks
<JAVA_HOME>\bin\keytool -export -alias s1as -storepass newpass -file server.cer -keystore keystore.jks
<JAVA_HOME>\bin\keytool -import -v -trustcacerts -alias s1as -file server.cer -keystore cacerts.jks -keypass newpass -storepass newpass
@jamestrandung
jamestrandung / Non-secure cookie setting.xml
Last active December 15, 2015 10:19
glassfish-web.xml file
<p:media ... >
<f:param name="wmode" value="opaque" />
</p:media>
-Djavax.net.ssl.keyStorePassword=newpass
-Djavax.net.ssl.trustStorePassword=newpass
@jamestrandung
jamestrandung / Managed bean.java
Last active October 8, 2017 16:40
Social authentication
@Named(value = "userSession")
@SessionScoped
public class UserSessionBean implements Serializable {
private SocialAuthManager manager;
private String originalURL;
private String providerID;
private Profile profile;
public UserSessionBean() { ... }
@jamestrandung
jamestrandung / Filter redirecting.java
Last active December 15, 2015 15:39
Redirect after login
String requestURI = request.getRequestURI();
String queryString = request.getQueryString();
String encodedURL = URLEncoder.encode(requestURI + "?" + queryString, "UTF-8");
response.sendRedirect(request.getContextPath() + "/login.xhtml?originalURL=" + encodedURL);
@jamestrandung
jamestrandung / MrBean.java
Last active December 15, 2015 17:59
The order of Action and Listener in JSF
package my.beanBag;
@ManagedBean(name = "mrBean")
@RequestScoped
public class MrBean implements ActionListener {
private String type;
public void triggerActionListener() {
System.out.println("MrBean is called by buttons' actionListener.");
}
@jamestrandung
jamestrandung / Application.java
Last active April 8, 2019 07:36
Starting SpringBoot app in stand-alone servlet container
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
@jamestrandung
jamestrandung / DatabaseConfiguration.java
Last active April 3, 2020 03:32
Set up LocalContainerEntityManagerFactoryBean
@Primary
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory(DataSource dataSource) {
LocalContainerEntityManagerFactoryBean emfBean = new LocalContainerEntityManagerFactoryBean();
emfBean.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
emfBean.setDataSource(dataSource);
// Other configurations
}
@jamestrandung
jamestrandung / Application.java
Last active April 9, 2019 02:57
Update javax.xml.bind.JAXBContextFactory to make use of packaged JAXB library
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
// Updating javax.xml.bind.JAXBContextFactory to make use of com.sun.xml.bind.v2.ContextFactory from our packaged WAR
System.setProperty("javax.xml.bind.JAXBContextFactory", "com.sun.xml.bind.v2.ContextFactory");