Search in sources :

Example 1 with HudsonFilter

use of hudson.security.HudsonFilter in project hudson-2.x by hudson.

the class Hudson method setSecurityRealm.

public void setSecurityRealm(SecurityRealm securityRealm) {
    if (securityRealm == null) {
        securityRealm = SecurityRealm.NO_AUTHENTICATION;
    }
    this.securityRealm = securityRealm;
    // reset the filters and proxies for the new SecurityRealm
    try {
        HudsonFilter filter = HudsonFilter.get(servletContext);
        if (filter == null) {
            // Fix for #3069: This filter is not necessarily initialized before the servlets.
            // when HudsonFilter does come back, it'll initialize itself.
            LOGGER.fine("HudsonFilter has not yet been initialized: Can't perform security setup for now");
        } else {
            LOGGER.fine("HudsonFilter has been previously initialized: Setting security up");
            filter.reset(securityRealm);
            LOGGER.fine("Security is now fully set up");
        }
    } catch (ServletException e) {
        // for binary compatibility, this method cannot throw a checked exception
        throw new AcegiSecurityException("Failed to configure filter", e) {
        };
    }
}
Also used : ServletException(javax.servlet.ServletException) HudsonFilter(hudson.security.HudsonFilter) AcegiSecurityException(org.acegisecurity.AcegiSecurityException)

Example 2 with HudsonFilter

use of hudson.security.HudsonFilter in project hudson-2.x by hudson.

the class ReadyDetector method getDelegate.

private Filter getDelegate(final HudsonFilter filter) {
    assert filter != null;
    try {
        Field field = filter.getClass().getDeclaredField("filter");
        field.setAccessible(true);
        return (Filter) field.get(filter);
    } catch (Exception e) {
        throw new Error("Failed to access HudsonFilter.filter delegate", e);
    }
}
Also used : Field(java.lang.reflect.Field) HudsonFilter(hudson.security.HudsonFilter) Filter(javax.servlet.Filter)

Example 3 with HudsonFilter

use of hudson.security.HudsonFilter in project hudson-2.x by hudson.

the class ReadyDetector method isReady.

private boolean isReady() {
    // but if its not yet COMPLETED, don't bother trying to figure out more
    if (hudson.getInitLevel() != InitMilestone.COMPLETED) {
        return false;
    }
    HudsonFilter filter = HudsonFilter.get(hudson.servletContext);
    if (filter == null) {
        return false;
    }
    // Need to get access to the filter's filter field to see if its actually initialized or not
    // it does not expose it directly, so we have to use reflection to force access
    Filter delegate = getDelegate(filter);
    if (delegate == null) {
        return false;
    }
    // At this point we _should_ be ready, see if the app root object is installed... fingers crossed!
    try {
        // FIXME: This may actually be the only check needed?
        Object app = controller.current();
        return app instanceof hudson.model.Hudson;
    } catch (IllegalStateException e) {
        // context not yet available
        return false;
    }
}
Also used : HudsonFilter(hudson.security.HudsonFilter) HudsonFilter(hudson.security.HudsonFilter) Filter(javax.servlet.Filter) Hudson(hudson.model.Hudson)

Aggregations

HudsonFilter (hudson.security.HudsonFilter)3 Filter (javax.servlet.Filter)2 Hudson (hudson.model.Hudson)1 Field (java.lang.reflect.Field)1 ServletException (javax.servlet.ServletException)1 AcegiSecurityException (org.acegisecurity.AcegiSecurityException)1