How to add AccessDescisionVoters to AccessDescisionManager in Spring Security

Here’s a pretty neat approach to add AccessDescisionVoters to the default AccessDescisionManager in Spring Security: /** * This BeanPostProcessor adds all {@link AccessDecisionVoter}s that are set with * {@link #setAdditionalAccessDecisionVoters(List)} to beans that are instances of {@link AffirmativeBased}. This is the * default {@link AccessDecisionManager} implementation that the spring security namespace handler creates. * <p> […]

Convert Image to byte array in Java

final Image image = …; final ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { final BufferedImage bufferedImage = createBufferedImageFrom(image); ImageIO.write(bufferedImage, “png”, baos); } finally { IOUtils.closeQuietly(baos); } return baos.toByteArray(); private BufferedImage createBufferedImageFrom(final Image image) { if (image instanceof BufferedImage) { return (BufferedImage) image; } else { final BufferedImage bi = new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB); final Graphics2D […]

UnknownHostException with ‘%’ in IPv6 address

dnsjava to resolve whatever address request.getRemoteAddr() would return. This worked very well in most cases. However, in some cases I would see something like: [quote]java.net.UnknownHostException: Invalid address: fe80::1d9:b65a:ed86:7940%11[/quote] Not being much of a networking expert I was puzzled about the ‘%11’. Once again superuser.com came to rescue: http://superuser.com/questions/99746/why-is-there-a-in-the-ipv6-address

Maven hbm2ddl: fixing java.lang.ArrayStoreException: sun.reflect.annotation.EnumConstantNotPresentExceptionProxy

Creating a DDL in the Maven build with the hibernate3-maven-plugin fails if you explicitly configure an array of javax.persistence.CascadeType values in your JPA annotations. The stacktrace is similar to javax.persistence.PersistenceException: [PersistenceUnit: spontacts] Unable to configure EntityManagerFactory at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:265) at org.codehaus.mojo.hibernate3.configuration.JPAComponentConfiguration.createConfiguration(JPAComponentConfiguration.java:28) … Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.EnumConstantNotPresentExceptionProxy at sun.reflect.annotation.AnnotationParser.parseEnumArray(AnnotationParser.java:673) at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:462) Once I realized what the actual […]

Self signed certificates in Apache HttpClient

When you need to support self-signed SSL certificates in your Apache HttpClient based application you can use the contributed EasySSLProtocolSocketFactory as described in the HttpClient docs. Instead of using HttpClient’s HostConfiguration object directly you’d modify its protocol socket factory in your code like so: … if (config.isAllowSelfSignedCertificates()) { ProtocolSocketFactory factory = new EasySSLProtocolSocketFactory(); try { […]