Search in sources :

Example 1 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project hudson-2.x by hudson.

the class BeanBuilder method methodMissing.

/**
	 * This method is invoked by Groovy when a method that's not defined in Java is invoked.
     * We use that as a syntax for bean definition. 
	 */
public Object methodMissing(String name, Object arg) {
    Object[] args = (Object[]) arg;
    if (args.length == 0)
        throw new MissingMethodException(name, getClass(), args);
    if (args[0] instanceof Closure) {
        // abstract bean definition
        return invokeBeanDefiningMethod(name, args);
    } else if (args[0] instanceof Class || args[0] instanceof RuntimeBeanReference || args[0] instanceof Map) {
        return invokeBeanDefiningMethod(name, args);
    } else if (args.length > 1 && args[args.length - 1] instanceof Closure) {
        return invokeBeanDefiningMethod(name, args);
    }
    WebApplicationContext ctx = springConfig.getUnrefreshedApplicationContext();
    MetaClass mc = DefaultGroovyMethods.getMetaClass(ctx);
    if (!mc.respondsTo(ctx, name, args).isEmpty()) {
        return mc.invokeMethod(ctx, name, args);
    }
    return this;
}
Also used : MissingMethodException(groovy.lang.MissingMethodException) Closure(groovy.lang.Closure) MetaClass(groovy.lang.MetaClass) GroovyObject(groovy.lang.GroovyObject) MetaClass(groovy.lang.MetaClass) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 2 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project hudson-2.x by hudson.

the class LegacySecurityRealm method createFilter.

/**
     * Filter to run for the LegacySecurityRealm is the
     * ChainServletFilter legacy from /WEB-INF/security/SecurityFilters.groovy.
     */
@Override
public Filter createFilter(FilterConfig filterConfig) {
    Binding binding = new Binding();
    SecurityComponents sc = this.createSecurityComponents();
    binding.setVariable("securityComponents", sc);
    binding.setVariable("securityRealm", this);
    BeanBuilder builder = new BeanBuilder();
    builder.parse(filterConfig.getServletContext().getResourceAsStream("/WEB-INF/security/SecurityFilters.groovy"), binding);
    WebApplicationContext context = builder.createApplicationContext();
    return (Filter) context.getBean("legacy");
}
Also used : Binding(groovy.lang.Binding) BeanBuilder(hudson.util.spring.BeanBuilder) Filter(javax.servlet.Filter) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 3 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project hudson-2.x by hudson.

the class PAMSecurityRealm method createSecurityComponents.

public SecurityComponents createSecurityComponents() {
    Binding binding = new Binding();
    binding.setVariable("instance", this);
    BeanBuilder builder = new BeanBuilder();
    builder.parse(Hudson.getInstance().servletContext.getResourceAsStream("/WEB-INF/security/PAMSecurityRealm.groovy"), binding);
    WebApplicationContext context = builder.createApplicationContext();
    return new SecurityComponents(findBean(AuthenticationManager.class, context), new UserDetailsService() {

        public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
            if (!UnixUser.exists(username))
                throw new UsernameNotFoundException("No such Unix user: " + username);
            // return some dummy instance
            return new User(username, "", true, true, true, true, new GrantedAuthority[] { AUTHENTICATED_AUTHORITY });
        }
    });
}
Also used : Binding(groovy.lang.Binding) BeanBuilder(hudson.util.spring.BeanBuilder) AuthenticationManager(org.acegisecurity.AuthenticationManager) UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) UserDetails(org.acegisecurity.userdetails.UserDetails) UnixUser(org.jvnet.libpam.UnixUser) User(org.acegisecurity.userdetails.User) GrantedAuthority(org.acegisecurity.GrantedAuthority) UserDetailsService(org.acegisecurity.userdetails.UserDetailsService) DataAccessException(org.springframework.dao.DataAccessException) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 4 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project hudson-2.x by hudson.

the class SecurityRealm method createFilter.

/**
     * Creates {@link Filter} that all the incoming HTTP requests will go through
     * for authentication.
     * <p/>
     * <p/>
     * The default implementation uses {@link #getSecurityComponents()} and builds
     * a standard filter chain from /WEB-INF/security/SecurityFilters.groovy.
     * But subclasses can override this to completely change the filter sequence.
     * <p/>
     * <p/>
     * For other plugins that want to contribute {@link Filter}, see
     * {@link PluginServletFilter}.
     *
     * @since 1.271
     */
public Filter createFilter(FilterConfig filterConfig) {
    LOGGER.entering(SecurityRealm.class.getName(), "createFilter");
    Binding binding = new Binding();
    SecurityComponents sc = getSecurityComponents();
    binding.setVariable("securityComponents", sc);
    binding.setVariable("securityRealm", this);
    BeanBuilder builder = new BeanBuilder();
    builder.parse(filterConfig.getServletContext().getResourceAsStream("/WEB-INF/security/SecurityFilters.groovy"), binding);
    WebApplicationContext context = builder.createApplicationContext();
    return (Filter) context.getBean("filter");
}
Also used : Binding(groovy.lang.Binding) BeanBuilder(hudson.util.spring.BeanBuilder) Filter(javax.servlet.Filter) PluginServletFilter(hudson.util.PluginServletFilter) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Example 5 with WebApplicationContext

use of org.springframework.web.context.WebApplicationContext in project hudson-2.x by hudson.

the class AbstractPasswordBasedSecurityRealm method createSecurityComponents.

@Override
public SecurityComponents createSecurityComponents() {
    Binding binding = new Binding();
    binding.setVariable("authenticator", new Authenticator());
    BeanBuilder builder = new BeanBuilder();
    builder.parse(Hudson.getInstance().servletContext.getResourceAsStream("/WEB-INF/security/AbstractPasswordBasedSecurityRealm.groovy"), binding);
    WebApplicationContext context = builder.createApplicationContext();
    return new SecurityComponents(findBean(AuthenticationManager.class, context), this);
}
Also used : Binding(groovy.lang.Binding) BeanBuilder(hudson.util.spring.BeanBuilder) AuthenticationManager(org.acegisecurity.AuthenticationManager) WebApplicationContext(org.springframework.web.context.WebApplicationContext)

Aggregations

WebApplicationContext (org.springframework.web.context.WebApplicationContext)100 Test (org.junit.Test)32 ServletContext (javax.servlet.ServletContext)17 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)15 MockHttpServletResponse (org.springframework.mock.web.test.MockHttpServletResponse)13 ApplicationContext (org.springframework.context.ApplicationContext)11 GenericWebApplicationContext (org.springframework.web.context.support.GenericWebApplicationContext)11 HashMap (java.util.HashMap)9 StaticWebApplicationContext (org.springframework.web.context.support.StaticWebApplicationContext)9 MockServletContext (org.springframework.mock.web.test.MockServletContext)8 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)7 Filter (javax.servlet.Filter)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)6 Binding (groovy.lang.Binding)5 BeanBuilder (hudson.util.spring.BeanBuilder)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 DispatcherServlet (org.springframework.web.servlet.DispatcherServlet)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)4 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)4