@SuppressWarnings("unchecked") private void configure() throws Exception { Collection<SecurityConfigurer<O, B>> configurers = getConfigurers(); for (SecurityConfigurer<O, B> configurer : configurers) { configurer.configure((B) this); } }
@SuppressWarnings("unchecked") private void init() throws Exception { Collection<SecurityConfigurer<O, B>> configurers = getConfigurers(); for (SecurityConfigurer<O, B> configurer : configurers) { configurer.init((B) this); } for (SecurityConfigurer<O, B> configurer : configurersAddedInInitializing) { configurer.init((B) this); } }
/** * Return the {@link SecurityBuilder} when done using the {@link SecurityConfigurer}. * This is useful for method chaining. * * @return the {@link SecurityBuilder} for further customizations */ public B and() { return getBuilder(); }
/** * Executes the build using the {@link SecurityConfigurer}'s that have been applied * using the following steps: * * <ul> * <li>Invokes {@link #beforeInit()} for any subclass to hook into</li> * <li>Invokes {@link SecurityConfigurer#init(SecurityBuilder)} for any * {@link SecurityConfigurer} that was applied to this builder.</li> * <li>Invokes {@link #beforeConfigure()} for any subclass to hook into</li> * <li>Invokes {@link #performBuild()} which actually builds the Object</li> * </ul> */ @Override protected final O doBuild() throws Exception { synchronized (configurers) { buildState = BuildState.INITIALIZING; beforeInit(); init(); buildState = BuildState.CONFIGURING; beforeConfigure(); configure(); buildState = BuildState.BUILDING; O result = performBuild(); buildState = BuildState.BUILT; return result; } }
/** * Applies a {@link SecurityConfigurerAdapter} to this {@link SecurityBuilder} and * invokes {@link SecurityConfigurerAdapter#setBuilder(SecurityBuilder)}. * * @param configurer * @return the {@link SecurityConfigurerAdapter} for further customizations * @throws Exception */ @SuppressWarnings("unchecked") public <C extends SecurityConfigurerAdapter<O, B>> C apply(C configurer) throws Exception { configurer.addObjectPostProcessor(objectPostProcessor); configurer.setBuilder((B) this); add(configurer); return configurer; }
/** * Performs post processing of an object. The default is to delegate to the * {@link ObjectPostProcessor}. * * @param object the Object to post process * @return the possibly modified Object to use */ protected <P> P postProcess(P object) { return this.objectPostProcessor.postProcess(object); }
/** * Similar to {@link #build()} and {@link #getObject()} but checks the state to * determine if {@link #build()} needs to be called first. * * @return the result of {@link #build()} or {@link #getObject()}. If an error occurs * while building, returns null. */ public O getOrBuild() { if (isUnbuilt()) { try { return build(); } catch (Exception e) { logger.debug("Failed to perform build. Returning null", e); return null; } } else { return getObject(); } }
/** * Captures the {@link UserDetailsService} from any {@link UserDetailsAwareConfigurer} * . * * @param configurer the {@link UserDetailsAwareConfigurer} to capture the * {@link UserDetailsService} from. * @return the {@link UserDetailsAwareConfigurer} for further customizations * @throws Exception if an error occurs */ private <C extends UserDetailsAwareConfigurer<AuthenticationManagerBuilder, ? extends UserDetailsService>> C apply( C configurer) throws Exception { this.defaultUserDetailsService = configurer.getUserDetailsService(); return (C) super.apply(configurer); } }
public final O build() throws Exception { if (this.building.compareAndSet(false, true)) { this.object = doBuild(); return this.object; } throw new AlreadyBuiltException("This object has already been built"); }
/** * Performs post processing of an object. The default is to delegate to the * {@link ObjectPostProcessor}. * * @param object the Object to post process * @return the possibly modified Object to use */ @SuppressWarnings("unchecked") protected <T> T postProcess(T object) { return (T) this.objectPostProcessor.postProcess(object); }
/** * Applies a {@link SecurityConfigurer} to this {@link SecurityBuilder} overriding any * {@link SecurityConfigurer} of the exact same class. Note that object hierarchies * are not considered. * * @param configurer * @return the {@link SecurityConfigurerAdapter} for further customizations * @throws Exception */ public <C extends SecurityConfigurer<O, B>> C apply(C configurer) throws Exception { add(configurer); return configurer; }
public <C> void setSharedObject(Class<C> sharedType, C object) { super.setSharedObject(sharedType, object); }
@Test public void postProcessObjectPostProcessorsAreSorted() { adapter.addObjectPostProcessor(new OrderedObjectPostProcessor(Ordered.LOWEST_PRECEDENCE)); adapter.addObjectPostProcessor(new OrderedObjectPostProcessor(Ordered.HIGHEST_PRECEDENCE)); assertThat(adapter.postProcess("hi")) .isEqualTo("hi " + Ordered.HIGHEST_PRECEDENCE + " " + Ordered.LOWEST_PRECEDENCE); }
public static List<?> perform(ArrayList<?> l) { return new ListToLinkedListObjectPostProcessor().postProcess(l); } }
@Override public void configure(SecurityBuilder<Object> builder) throws Exception { list = postProcess(list); }
@Before public void setup() { adapter = new ConcereteSecurityConfigurerAdapter(); }
@Autowired(required = false) public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) { this.objectPostProcessor = objectPostProcessor; this.defaultMethodExpressionHandler = objectPostProcessor .postProcess(defaultMethodExpressionHandler); }
@Autowired(required = false) public void setObjectPostProcessor(ObjectPostProcessor<Object> objectPostProcessor) { defaultExpressionHandler = objectPostProcessor.postProcess(defaultExpressionHandler); }
@Autowired public void configure(ObjectPostProcessor<Object> p) { p.postProcess(this.toTest); } }
@Autowired public void configure(ObjectPostProcessor<Object> p) { p.postProcess(new Object()); } }