Skip to content

Instantly share code, notes, and snippets.

@igm
igm / MyController.java
Created July 7, 2011 11:46
Secured methods
@Controller
public class MyController {
@Secured(admin = true)
@RequestMapping(value="/show_users.html", method = RequestMethod.GET)
public String showAllUsers(Model model) {
...
}
...
}
@igm
igm / Secured.java
Created July 7, 2011 11:48
Secured annotation
@Target({ ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface Secured {
Boolean admin() default false;
}
@Aspect
@Component
public class SecuredAspect {
@Pointcut("@annotation(annotation)")
@SuppressWarnings("unused")
private void secured(Secured annotation) {
}
@Around("secured(annotation)")
public Object aroundCachedMethods(ProceedingJoinPoint thisJoinPoint, Secured annotation)
<beans>
...
<bean class="security.SecurityAspect" />
<aop:aspectj-autoproxy />
</beans>
<beans>
...
<bean id="jangodConf"
class="org.springframework.web.servlet.view.jangod.JangodConfigurer">
<property name="configurationFile" value="jangod.config.properties" />
</bean>
<bean class="org.springframework.web.servlet.view.jangod.JangodViewResolver">
<property name="jangodConfig" ref="jangodConf" />
<property name="prefix" value="/WEB-INF/views" />
<property name="suffix" value=".html" />
{% extends "base.html" %}
{% block content %}
<div id="part-content">
{% if posts %}
{% for post in posts %}
<div id="post-{{post.id}}" class="post-home">
<div class="post-title">
<h1><a href="{{post.link}}" rel="bookmark">{{post.title}}</a></h1>
</div>
<div class="post-content">{{post.preview}}</div>
<web-app>
...
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>spring.profiles.active</param-name>
<param-value>production</param-value>
</init-param>
</servlet>
package foo.bar;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
public class MyContextInitializer implements
ApplicationContextInitializer<ConfigurableApplicationContext> {
private static final String PROP = "com.google.appengine.runtime.environment";
<web-app>
..
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextInitializerClasses</param-name>
<param-value>foo.bar.MyContextInitializer</param-value>
</init-param>
</servlet>
@igm
igm / MyContextInitializer.java
Created August 17, 2011 09:26
KB_spring_profile
package foo.bar;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
public class MyContextInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
public void initialize(ConfigurableApplicationContext applicationContext) {
ConfigurableEnvironment springEnvironment = applicationContext.getEnvironment();