org.picketlink.extension.PicketLinkExtension Maven / Gradle / Ivy
/*
* JBoss, Home of Professional Open Source.
* Copyright 2012, Red Hat, Inc., and individual contributors
* as indicated by the @author tags. See the copyright.txt file in the
* distribution for a full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.picketlink.extension;
import org.picketlink.Identity;
import org.picketlink.config.SecurityConfiguration;
import org.picketlink.config.SecurityConfigurationBuilder;
import org.picketlink.event.SecurityConfigurationEvent;
import org.picketlink.internal.IdentityBeanDefinition;
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.AfterDeploymentValidation;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.Extension;
import javax.enterprise.inject.spi.ProcessAnnotatedType;
import static org.picketlink.log.BaseLog.ROOT_LOGGER;
/**
* {@link javax.enterprise.inject.spi.Extension} responsible for:
*
*
* - Fire a {@link org.picketlink.event.SecurityConfigurationEvent} to allow the application provide its own configuration.
* - Register a {@link org.picketlink.internal.IdentityBeanDefinition} to properly manage the {@link org.picketlink.Identity} bean
* behavior.
*
*
* @author Pedro Igor
*/
public class PicketLinkExtension implements Extension {
private IdentityBeanDefinition identityBeanDefinition;
private SecurityConfigurationBuilder securityConfigurationBuilder;
private SecurityConfiguration securityConfiguration;
/**
* Veto all {@link org.picketlink.Identity} implementations.
*
* This is necessary in order to proper install the {@link org.picketlink.internal.IdentityBeanDefinition},
* which is responsible for defining those beans.
*
* @param pat
* @param
*/
void vetoIdentityImplementations(@Observes ProcessAnnotatedType pat) {
final AnnotatedType annotatedType = pat.getAnnotatedType();
Class javaClass = annotatedType.getJavaClass();
if (!Identity.class.equals(javaClass) && Identity.class.isAssignableFrom(javaClass)) {
pat.veto();
}
}
/**
* Initializes the PicketLink configuration.
*
* @param abd
* @param beanManager
*/
void installIdentityBean(@Observes AfterBeanDiscovery abd, BeanManager beanManager) {
this.identityBeanDefinition = new IdentityBeanDefinition(beanManager);
abd.addBean(identityBeanDefinition);
}
/**
* Initializes the PicketLink configuration.
*
* @param adv
* @param beanManager
*/
void initializeConfiguration(@Observes AfterDeploymentValidation adv, BeanManager beanManager) {
ROOT_LOGGER.picketlinkBootstrap();
SecurityConfigurationEvent securityConfigurationEvent = new SecurityConfigurationEvent();
beanManager.fireEvent(securityConfigurationEvent);
// TODO: best is fire an event. We're not doing that because of issues in EAP and WildFly when using PL jars from modules.
this.securityConfigurationBuilder = securityConfigurationEvent.getBuilder();
this.securityConfiguration = this.securityConfigurationBuilder.build();
this.identityBeanDefinition.setSecurityConfiguration(this.securityConfiguration);
}
public SecurityConfigurationBuilder getSecurityConfigurationBuilder() {
return this.securityConfigurationBuilder;
}
public SecurityConfiguration getSecurityConfiguration() {
return this.securityConfiguration;
}
}