Skip to content

Instantly share code, notes, and snippets.

View dwelch2344's full-sized avatar

David Welch dwelch2344

View GitHub Profile
@dwelch2344
dwelch2344 / HardCodedUserDetailsAuthenticationProvider.java
Created June 4, 2012 18:41
A simple UserDetailsAuthenticationProvider for SpringSecurity
package com.example;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.authentication.dao.AbstractUserDetailsAuthenticationProvider;
import org.springframework.security.core.AuthenticationException;
@dwelch2344
dwelch2344 / 0.1_secure-url.xml
Created June 10, 2012 21:17
Spring Security & Expression Language Tutorial Gist
<security:intercept-url pattern="/secure/**" access="hasRole('ROLE_ADMIN')"/>
@dwelch2344
dwelch2344 / gist:2925101
Created June 13, 2012 16:29
Get Spring Application Context anywhere
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.servlet.support.RequestContextUtils;
public class Blah {
@dwelch2344
dwelch2344 / SftpServer.java
Created June 15, 2012 14:14
SFTP experiments with Mina
package com.example.sftp;
import java.util.ArrayList;
import java.util.List;
import org.apache.sshd.SshServer;
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.CommandFactory;
import org.apache.sshd.server.PasswordAuthenticator;
@dwelch2344
dwelch2344 / DanTest.java
Created June 22, 2012 16:20
Autowiring all defined beans
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
public class DanTest implements ApplicationContextAware{
@Override
public void setApplicationContext(ApplicationContext ctx)
public class Model {
private final List<String> entries = new ArrayList<String>();
public List<String> getEntries(){
return new ArrayList<String>();
}
}
@dwelch2344
dwelch2344 / 1_web.xml
Created July 1, 2012 22:09
Spring MVC w/ no XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>SpringDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ANSIBlackColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OViRjbGFzc1xOU0NvbG9yU3BhY2VVTlNSR0KAAhAB
TxAoMC4wMjc0NTA5ODAzOSAwLjIxMTc2NDcwNTkgMC4yNTg4MjM1Mjk0ANIQERITWiRj
bGFzc25hbWVYJGNsYXNzZXNXTlNDb2xvcqISFFhOU09iamVjdF8QD05TS2V5ZWRBcmNo
@dwelch2344
dwelch2344 / 1_pom.xml
Created August 9, 2012 19:13
Spring RestTemplate w/ Basic Auth
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- Http Client -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
@dwelch2344
dwelch2344 / Main.java
Created September 13, 2012 20:17
A simple Java properties-to-xml converter
package co.ntier.util.prop2xml;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.Locale;
import java.util.Properties;