Search in sources :

Example 91 with Binding

use of groovy.lang.Binding in project hudson-2.x by hudson.

the class Combination method evalGroovyExpression.

/**
 * Evaluates the given Groovy expression with values bound from this combination.
 *
 * <p>
 * For example, if this combination is a=X,b=Y, then expressions like <tt>a=="X"</tt> would evaluate to
 * true.
 */
public boolean evalGroovyExpression(AxisList axes, String expression) {
    if (Util.fixEmptyAndTrim(expression) == null)
        return true;
    Binding binding = new Binding();
    for (Map.Entry<String, String> e : entrySet()) binding.setVariable(e.getKey(), e.getValue());
    binding.setVariable("index", toModuloIndex(axes));
    binding.setVariable("uniqueId", toIndex(axes));
    GroovyShell shell = new GroovyShell(binding);
    Object result = shell.evaluate("use(" + BooleanCategory.class.getName().replace('$', '.') + ") {" + expression + "}");
    return TRUE.equals(result);
}
Also used : Binding(groovy.lang.Binding) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) GroovyShell(groovy.lang.GroovyShell)

Example 92 with Binding

use of groovy.lang.Binding 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 93 with Binding

use of groovy.lang.Binding 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 94 with Binding

use of groovy.lang.Binding 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)

Example 95 with Binding

use of groovy.lang.Binding 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)

Aggregations

Binding (groovy.lang.Binding)213 GroovyShell (groovy.lang.GroovyShell)76 Script (groovy.lang.Script)55 Test (org.junit.Test)41 IOException (java.io.IOException)29 File (java.io.File)24 HashMap (java.util.HashMap)23 Closure (groovy.lang.Closure)22 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)22 Map (java.util.Map)20 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)13 ImportCustomizer (org.codehaus.groovy.control.customizers.ImportCustomizer)12 GroovyService (eu.esdihumboldt.util.groovy.sandbox.GroovyService)11 MissingPropertyException (groovy.lang.MissingPropertyException)11 GroovyClassLoader (groovy.lang.GroovyClassLoader)10 StringWriter (java.io.StringWriter)10 InstanceBuilder (eu.esdihumboldt.hale.common.instance.groovy.InstanceBuilder)9 InputStreamReader (java.io.InputStreamReader)9 Writer (java.io.Writer)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9