Example usage for org.springframework.context ApplicationContext toString

List of usage examples for org.springframework.context ApplicationContext toString

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext toString.

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.agilegroups.aws.AmazonEC2Application.java

public static void main(String[] args) throws Exception {
    //SpringApplication.run(AmazonEC2Application.class, args);
    ApplicationContext context = SpringApplication.run(ApplicationConfig.class, args);
    LOG.info("here is the spring context: " + context.toString());
}

From source file:org.acegisecurity.taglibs.authz.AclTag.java

public int doStartTag() throws JspException {
    if ((null == hasPermission) || "".equals(hasPermission)) {
        return Tag.SKIP_BODY;
    }//from  w ww  . ja  v  a2  s  . co m

    final String evaledPermissionsString = ExpressionEvaluationUtils.evaluateString("hasPermission",
            hasPermission, pageContext);

    Integer[] requiredIntegers = null;

    try {
        requiredIntegers = parseIntegersString(evaledPermissionsString);
    } catch (NumberFormatException nfe) {
        throw new JspException(nfe);
    }

    Object resolvedDomainObject = null;

    if (domainObject instanceof String) {
        resolvedDomainObject = ExpressionEvaluationUtils.evaluate("domainObject", (String) domainObject,
                Object.class, pageContext);
    } else {
        resolvedDomainObject = domainObject;
    }

    if (resolvedDomainObject == null) {
        if (logger.isDebugEnabled()) {
            logger.debug("domainObject resolved to null, so including tag body");
        }

        // Of course they have access to a null object!
        return Tag.EVAL_BODY_INCLUDE;
    }

    if (SecurityContextHolder.getContext().getAuthentication() == null) {
        if (logger.isDebugEnabled()) {
            logger.debug(
                    "SecurityContextHolder did not return a non-null Authentication object, so skipping tag body");
        }

        return Tag.SKIP_BODY;
    }

    Authentication auth = SecurityContextHolder.getContext().getAuthentication();

    ApplicationContext context = getContext(pageContext);
    String[] beans = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(context, AclManager.class, false,
            false);

    if (beans.length == 0) {
        throw new JspException("No AclManager would found the application context: " + context.toString());
    }

    AclManager aclManager = (AclManager) context.getBean(beans[0]);

    // Obtain aclEntrys applying to the current Authentication object
    AclEntry[] acls = aclManager.getAcls(resolvedDomainObject, auth);

    if (logger.isDebugEnabled()) {
        logger.debug("Authentication: '" + auth + "' has: " + ((acls == null) ? 0 : acls.length)
                + " AclEntrys for domain object: '" + resolvedDomainObject + "' from AclManager: '"
                + aclManager.toString() + "'");
    }

    if ((acls == null) || (acls.length == 0)) {
        return Tag.SKIP_BODY;
    }

    for (int i = 0; i < acls.length; i++) {
        // Locate processable AclEntrys
        if (acls[i] instanceof BasicAclEntry) {
            BasicAclEntry processableAcl = (BasicAclEntry) acls[i];

            // See if principal has any of the required permissions
            for (int y = 0; y < requiredIntegers.length; y++) {
                if (processableAcl.isPermitted(requiredIntegers[y].intValue())) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Including tag body as found permission: " + requiredIntegers[y]
                                + " due to AclEntry: '" + processableAcl + "'");
                    }

                    return Tag.EVAL_BODY_INCLUDE;
                }
            }
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("No permission, so skipping tag body");
    }

    return Tag.SKIP_BODY;
}