public boolean configure()

in integrations/shiro/shiro-authc/src/main/java/org/apache/aries/jax/rs/shiro/authc/impl/ShiroAuthenticationFeature.java [75:123]


    public boolean configure(FeatureContext fc) {
        
        Configuration configuration = fc.getConfiguration();
        
        if(_LOG.isInfoEnabled()) {
            @SuppressWarnings("unchecked")
            Map<String, Object> applicationProps = (Map<String, Object>) configuration.getProperty(JAX_RS_APPLICATION_SERVICE_PROPERTIES);
            _LOG.info("Registering the Shiro Authentication feature with application {}", 
                    applicationProps.getOrDefault(JAX_RS_NAME, "<No Name found in application configuration>"));
        }
        
        if(realms.isEmpty()) {
            _LOG.warn("There are no authentication realms available. Users may not be able to authenticate.");
        } else {
            _LOG.debug("Using the authentication realms {}.", realms);
        }

        _LOG.debug("Registering the Shiro SecurityManagerAssociatingFilter");
        fc.register(new SecurityManagerAssociatingFilter(manager), AUTHENTICATION);

        Map<Class<?>, Integer> contracts = configuration.getContracts(ExceptionMapper.class);
        if(contracts.isEmpty()) {
            _LOG.debug("Registering the Shiro ExceptionMapper");
            // Only register the ExceptionMapper if it isn't already registered
            fc.register(ExceptionMapper.class, AUTHENTICATION);
        } else if(AUTHENTICATION < contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER)) {
            _LOG.debug("Updating the priority of the Shiro ExceptionMapper from {} to {}",
                    contracts.getOrDefault(javax.ws.rs.ext.ExceptionMapper.class, USER),
                    AUTHORIZATION);
            // Update the priority if it's registered too low
            contracts.put(javax.ws.rs.ext.ExceptionMapper.class, AUTHENTICATION);
        }

        contracts = configuration.getContracts(SubjectPrincipalRequestFilter.class);
        if(contracts.isEmpty()) {
            _LOG.debug("Registering the Shiro SubjectPrincipalRequestFilter");
            // Only register the SubjectPrincipalRequestFilter if it isn't already registered
            // and make sure it always comes after the SecurityManagerAssociatingFilter
            fc.register(SubjectPrincipalRequestFilter.class, AUTHENTICATION + 1);
        } else if(AUTHENTICATION < contracts.getOrDefault(ContainerRequestFilter.class, USER)) {
            _LOG.debug("Updating the priority of the Shiro SubjectPrincipalRequestFilter from {} to {}",
                    contracts.getOrDefault(ContainerRequestFilter.class, USER),
                    AUTHENTICATION + 1);
            // Update the priority if it's registered too low
            contracts.put(ContainerRequestFilter.class, AUTHENTICATION + 1);
        }
        
        return true;
    }