Example usage for org.apache.commons.logging Log debug

List of usage examples for org.apache.commons.logging Log debug

Introduction

In this page you can find the example usage for org.apache.commons.logging Log debug.

Prototype

void debug(Object message);

Source Link

Document

Logs a message with debug log level.

Usage

From source file:org.rhq.core.clientapi.descriptor.AgentPluginDescriptorUtil.java

/**
 * Loads a plugin descriptor from the given plugin jar and returns it.
 *
 * This is a static method to provide a convenience method for others to be able to use.
 *
 * @param pluginJarFileUrl URL to a plugin jar file
 * @return the plugin descriptor found in the given plugin jar file
 * @throws PluginContainerException if failed to find or parse a descriptor file in the plugin jar
 *//* w  w  w  .  j a v  a 2  s  . c o  m*/
public static PluginDescriptor loadPluginDescriptorFromUrl(URL pluginJarFileUrl)
        throws PluginContainerException {

    final Log logger = LogFactory.getLog(AgentPluginDescriptorUtil.class);

    if (pluginJarFileUrl == null) {
        throw new PluginContainerException("A valid plugin JAR URL must be supplied.");
    }
    logger.debug("Loading plugin descriptor from plugin jar at [" + pluginJarFileUrl + "]...");

    testPluginJarIsReadable(pluginJarFileUrl);

    JarInputStream jis = null;
    JarEntry descriptorEntry = null;
    ValidationEventCollector validationEventCollector = new ValidationEventCollector();
    try {
        jis = new JarInputStream(pluginJarFileUrl.openStream());
        JarEntry nextEntry = jis.getNextJarEntry();
        while (nextEntry != null && descriptorEntry == null) {
            if (PLUGIN_DESCRIPTOR_PATH.equals(nextEntry.getName())) {
                descriptorEntry = nextEntry;
            } else {
                jis.closeEntry();
                nextEntry = jis.getNextJarEntry();
            }
        }

        if (descriptorEntry == null) {
            throw new Exception("The plugin descriptor does not exist");
        }

        return parsePluginDescriptor(jis, validationEventCollector);
    } catch (Exception e) {
        throw new PluginContainerException(
                "Could not successfully parse the plugin descriptor [" + PLUGIN_DESCRIPTOR_PATH
                        + "] found in plugin jar at [" + pluginJarFileUrl + "].",
                new WrappedRemotingException(e));
    } finally {
        if (jis != null) {
            try {
                jis.close();
            } catch (Exception e) {
                logger.warn("Cannot close jar stream [" + pluginJarFileUrl + "]. Cause: " + e);
            }
        }

        logValidationEvents(pluginJarFileUrl, validationEventCollector, logger);
    }
}

From source file:org.rhq.enterprise.gui.admin.role.AddLdapGroupsAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(AddLdapGroupsAction.class.getName());
    HttpSession session = request.getSession();

    AddLdapGroupsForm addForm = (AddLdapGroupsForm) form;
    Integer roleId = addForm.getR();

    ActionForward forward = checkSubmit(request, mapping, form, Constants.ROLE_PARAM, roleId);
    if (forward != null) {
        BaseValidatorForm spiderForm = (BaseValidatorForm) form;

        if (spiderForm.isCancelClicked() || spiderForm.isResetClicked()) {
            log.debug("removing pending group list");
            SessionUtils.removeList(session, Constants.PENDING_RESGRPS_SES_ATTR);
        } else if (spiderForm.isAddClicked()) {
            log.debug("adding to pending group list");
            SessionUtils.addToList(session, Constants.PENDING_RESGRPS_SES_ATTR, addForm.getAvailableGroups());
        } else if (spiderForm.isRemoveClicked()) {
            log.debug("removing from pending group list");
            SessionUtils.removeFromList(session, Constants.PENDING_RESGRPS_SES_ATTR,
                    addForm.getPendingGroups());
        }/*from ww  w  . j a  v  a  2  s .  c  o m*/

        return forward;
    }

    log.debug("getting pending group list");
    List<String> pendingGroupIds = SessionUtils.getListAsListStr(request.getSession(),
            Constants.PENDING_RESGRPS_SES_ATTR);
    for (String id : pendingGroupIds) {
        log.debug("adding group [" + id + "] for role [" + roleId + "]");
    }

    ldapManager.addLdapGroupsToRole(RequestUtils.getSubject(request), roleId, pendingGroupIds);

    log.debug("removing pending group list");
    SessionUtils.removeList(session, Constants.PENDING_RESGRPS_SES_ATTR);

    RequestUtils.setConfirmation(request, "admin.role.confirm.AddLdapGroups");
    return returnSuccess(request, mapping, Constants.ROLE_PARAM, roleId);
}

From source file:org.rhq.enterprise.gui.admin.role.AddResourceGroupsAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(AddResourceGroupsAction.class.getName());
    HttpSession session = request.getSession();

    AddResourceGroupsForm addForm = (AddResourceGroupsForm) form;
    Integer roleId = addForm.getR();

    ActionForward forward = checkSubmit(request, mapping, form, Constants.ROLE_PARAM, roleId);
    if (forward != null) {
        BaseValidatorForm spiderForm = (BaseValidatorForm) form;

        if (spiderForm.isCancelClicked() || spiderForm.isResetClicked()) {
            log.debug("removing pending group list");
            SessionUtils.removeList(session, Constants.PENDING_RESGRPS_SES_ATTR);
        } else if (spiderForm.isAddClicked()) {
            log.debug("adding to pending group list");
            SessionUtils.addToList(session, Constants.PENDING_RESGRPS_SES_ATTR, addForm.getAvailableGroups());
        } else if (spiderForm.isRemoveClicked()) {
            log.debug("removing from pending group list");
            SessionUtils.removeFromList(session, Constants.PENDING_RESGRPS_SES_ATTR,
                    addForm.getPendingGroups());
        }//from  w  w  w. j a  v  a2  s. com

        return forward;
    }

    log.debug("getting pending group list");
    int[] pendingGroupIds = ArrayUtils
            .unwrapArray(SessionUtils.getList(session, Constants.PENDING_RESGRPS_SES_ATTR));
    for (int i = 0; i < pendingGroupIds.length; i++) {
        log.debug("adding group [" + pendingGroupIds[i] + "] for role [" + roleId + "]");
    }

    RoleManagerLocal roleManager = LookupUtil.getRoleManager();
    roleManager.addResourceGroupsToRole(RequestUtils.getSubject(request), roleId, pendingGroupIds);

    log.debug("removing pending group list");
    SessionUtils.removeList(session, Constants.PENDING_RESGRPS_SES_ATTR);

    RequestUtils.setConfirmation(request, "admin.role.confirm.AddResourceGroups");
    return returnSuccess(request, mapping, Constants.ROLE_PARAM, roleId);
}

From source file:org.rhq.enterprise.gui.admin.role.AddUsersAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(AddUsersAction.class.getName());
    HttpSession session = request.getSession();
    AddUsersForm addForm = (AddUsersForm) form;
    Integer roleId = addForm.getR();
    ActionForward forward = checkSubmit(request, mapping, form, Constants.ROLE_PARAM, roleId);

    if (forward != null) {
        BaseValidatorForm spiderForm = (BaseValidatorForm) form;

        if (spiderForm.isCancelClicked() || spiderForm.isResetClicked()) {
            log.trace("removing pending user list");
            SessionUtils.removeList(session, Constants.PENDING_USERS_SES_ATTR);
        } else if (spiderForm.isAddClicked()) {
            log.trace("adding to pending user list");
            SessionUtils.addToList(session, Constants.PENDING_USERS_SES_ATTR, addForm.getAvailableUsers());
        } else if (spiderForm.isRemoveClicked()) {
            log.trace("removing from pending user list");
            SessionUtils.removeFromList(session, Constants.PENDING_USERS_SES_ATTR, addForm.getPendingUsers());
        }/* w  ww  . ja  v  a2 s.com*/

        return forward;
    }

    log.debug("getting role [" + roleId + "]");

    log.debug("getting pending user list");
    int[] pendingUserIds = ArrayUtils
            .unwrapArray(SessionUtils.getList(request.getSession(), Constants.PENDING_USERS_SES_ATTR));
    for (int i = 0; i < pendingUserIds.length; i++) {
        log.debug("adding user [" + pendingUserIds[i] + "] for role [" + roleId + "]");
    }

    try {
        LookupUtil.getRoleManager().addSubjectsToRole(RequestUtils.getSubject(request), roleId, pendingUserIds);
    } catch (PermissionException pe) {
        RequestUtils.setError(request, "admin.role.error.StaticRole");
        return returnFailure(request, mapping, Constants.ROLE_PARAM, roleId);
    } finally {
        log.debug("removing pending user list");
        SessionUtils.removeList(session, Constants.PENDING_USERS_SES_ATTR);
    }

    RequestUtils.setConfirmation(request, "admin.role.confirm.AddUsers");
    return returnSuccess(request, mapping, Constants.ROLE_PARAM, roleId);
}

From source file:org.rhq.enterprise.gui.admin.role.RemoveLdapGroupsAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(RemoveLdapGroupsAction.class.getName());

    RemoveResourceGroupsForm rmForm = (RemoveResourceGroupsForm) form;
    int roleId = rmForm.getR();
    int[] groupIds = ArrayUtils.unwrapArray(rmForm.getLdapGroups());

    log.debug("removing groups " + groupIds + "] for role [" + roleId + "]");
    ldapManager.removeLdapGroupsFromRole(RequestUtils.getSubject(request), roleId, groupIds);

    RequestUtils.setConfirmation(request, "admin.role.confirm.RemoveLdapGroups");
    return returnSuccess(request, mapping, Constants.ROLE_PARAM, roleId);
}

From source file:org.rhq.enterprise.gui.admin.role.RemoveResourceGroupsAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(RemoveResourceGroupsAction.class.getName());

    RemoveResourceGroupsForm rmForm = (RemoveResourceGroupsForm) form;
    int roleId = rmForm.getR();
    int[] groupIds = ArrayUtils.unwrapArray(rmForm.getGroups());

    log.debug("removing groups " + groupIds + "] for role [" + roleId + "]");
    LookupUtil.getRoleManager().removeResourceGroupsFromRole(RequestUtils.getSubject(request), roleId,
            groupIds);//w w w .j a  v a2 s.co m

    RequestUtils.setConfirmation(request, "admin.role.confirm.RemoveResourceGroups");
    return returnSuccess(request, mapping, Constants.ROLE_PARAM, roleId);
}

From source file:org.rhq.enterprise.gui.admin.user.EditPasswordAction.java

/**
 * @see BaseAction#execute(org.apache.struts.action.ActionMapping,org.apache.struts.action.ActionForm,
 *      javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*from w  w  w .  j  a v a 2 s.c om*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(NewAction.class.getName());

    EditPasswordForm pForm = (EditPasswordForm) form;
    ActionForward forward = checkSubmit(request, mapping, form, ParamConstants.USER_PARAM, pForm.getId());

    if (forward != null) {
        return forward;
    }

    SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
    Subject subject = WebUtility.getSubject(request);
    int subjectSession = subject.getSessionId();

    Subject userToBeModified = subjectManager.getSubjectById(pForm.getId());

    String userName = userToBeModified.getName();
    log.debug("Editing password for user [" + userName + "]");

    boolean admin = LookupUtil.getAuthorizationManager().hasGlobalPermission(subject,
            Permission.MANAGE_SECURITY);
    boolean isSameUser = subject.getName().equals(userName);

    // if this user cannot administer other user's passwords, make sure he gave the old password as confirmation
    if (!admin) {
        try {
            int dummySession = subjectManager.login(userName, pForm.getCurrentPassword()).getSessionId();
            subjectManager.logout(dummySession);

            // The above killed our session for subject if subject == userToBeModified
            if (isSameUser) {
                subject = subjectManager.login(userName, pForm.getCurrentPassword());
            }
        } catch (LoginException e) {
            RequestUtils.setError(request, "admin.user.error.WrongPassword", "currentPassword");
            return returnFailure(request, mapping, ParamConstants.USER_PARAM, pForm.getId());
        }
    }

    String newPassword = pForm.getNewPassword();
    subjectManager.changePassword(subject, userName, newPassword);

    // when we have arrived here, the password is changed.
    // If this was a change of our own password, we need to re-login now
    if (isSameUser) {
        subjectManager.logout(subject.getSessionId());
    }

    return returnSuccess(request, mapping, ParamConstants.USER_PARAM,

            pForm.getId());
}

From source file:org.rhq.enterprise.gui.admin.user.NewAction.java

/**
 * Create the user with the attributes specified in the given <code>NewForm</code> and save it into the session
 * attribute <code>Constants.USER_ATTR</code>.
 *///  w w  w .j ava2  s .  c  o  m
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(NewAction.class.getName());

    Subject whoami = RequestUtils.getWebUser(request).getSubject();
    NewForm userForm = (NewForm) form;

    ActionForward forward = checkSubmit(request, mapping, form);
    if (forward != null) {
        return forward;
    }

    Subject user = new Subject();

    user.setName(userForm.getName());
    user.setFirstName(userForm.getFirstName());
    user.setLastName(userForm.getLastName());
    user.setDepartment(userForm.getDepartment());
    user.setEmailAddress(userForm.getEmailAddress());
    user.setSmsAddress(userForm.getSmsAddress());
    user.setPhoneNumber(userForm.getPhoneNumber());
    user.setFactive(!userForm.getEnableLogin().equals("no"));
    user.setFsystem(false);

    // add both a subject and a principal as normal
    log.debug("creating subject [" + user.getName() + "]");

    SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
    Subject newUser = subjectManager.createSubject(whoami, user);

    log.debug("creating principal [" + user.getName() + "]");
    subjectManager.createPrincipal(whoami, user.getName(), userForm.getNewPassword());

    HashMap parms = new HashMap(1);
    parms.put(Constants.USER_PARAM, newUser.getId());

    return returnOkAssign(request, mapping, parms, false);
}

From source file:org.rhq.enterprise.gui.admin.user.RemoveRolesAction.java

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(RemoveAction.class.getName());

    RemoveRolesForm rmForm = (RemoveRolesForm) form;
    Integer[] roles = rmForm.getRoles();

    if ((roles == null) || (roles.length < 1)) {
        log.debug("no roles specified in request");
        return returnFailure(request, mapping);
    }//  ww  w  .j  a v  a  2  s  . c o m

    for (int i = 0; i < roles.length; i++) {
        log.debug("removing role [" + roles[i] + "]");
    }

    int[] rolesInts = ArrayUtils.unwrapArray(roles);
    LookupUtil.getRoleManager().removeRolesFromSubject(RequestUtils.getSubject(request), rmForm.getU(),
            rolesInts);

    RequestUtils.setConfirmation(request, "admin.role.confirm.Remove");

    return returnSuccess(request, mapping);
}

From source file:org.rhq.enterprise.gui.authentication.AuthenticateUserAction.java

/**
 * @see TilesAction#execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse)
 */// ww w.j a va  2 s  .c o  m
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Log log = LogFactory.getLog(AuthenticateUserAction.class.getName());

    HttpSession session = request.getSession(true);
    LogonForm logonForm = (LogonForm) form;
    ServletContext ctx = getServlet().getServletContext();

    WebUser webUser = null;
    Map<String, Boolean> userGlobalPermissionsMap = new HashMap<String, Boolean>();
    boolean needsRegistration = false;

    try {
        // authenticate the credentials
        SubjectManagerLocal subjectManager = LookupUtil.getSubjectManager();
        Subject subject = subjectManager.login(logonForm.getJ_username(), logonForm.getJ_password());
        Integer sessionId = subject.getSessionId(); // this is the RHQ session ID, not related to the HTTP session

        log.debug("Logged in as [" + logonForm.getJ_username() + "] with session id [" + sessionId + "]");

        boolean hasPrincipal = true;
        if (subject.getId() == 0) {
            // Subject with a ID of 0 means the subject wasn't in the database but the login succeeded.
            // This means the login method detected that LDAP authenticated the user and just gave us a dummy subject.
            // Set the needs-registration flag so we can eventually steer the user to the LDAP registration workflow.
            needsRegistration = true;
        }

        if (!needsRegistration) {
            subject = subjectManager.loadUserConfiguration(subject.getId());
            subject.setSessionId(sessionId); // put the transient data back into our new subject

            if (subject.getUserConfiguration() == null) {
                subject.setUserConfiguration((Configuration) ctx.getAttribute(Constants.DEF_USER_PREFS));
                subject = subjectManager.updateSubject(subject, subject);
                subject.setSessionId(sessionId); // put the transient data back into our new subject
            }

            // look up the user's permissions
            Set<Permission> all_permissions = LookupUtil.getAuthorizationManager()
                    .getExplicitGlobalPermissions(subject);

            for (Permission permission : all_permissions) {
                userGlobalPermissionsMap.put(permission.toString(), Boolean.TRUE);
            }
        }

        webUser = new WebUser(subject, hasPrincipal);
    } catch (Exception e) {
        String msg = e.getMessage().toLowerCase();
        if ((msg.indexOf("username") >= 0) || (msg.indexOf("password") >= 0)) {
            request.setAttribute(Constants.LOGON_STATUS, "login.info.bad");
        } else {
            log.error("Could not log into the web application", e);
            request.setAttribute(Constants.LOGON_STATUS, "login.bad.backend");
        }

        return (mapping.findForward("bad"));
    }

    // compute the post-login destination
    ActionForward af;
    if (needsRegistration) {
        // Since we are authenticating the user with LDAP and the user has never logged in before,
        // that user has no subject record yet. We need to send him through the LDAP registration workflow.
        log.debug("LDAP registration required for user [" + logonForm.getJ_username() + "]");
        af = new ActionForward(URL_REGISTER);
    } else {
        // if the user's session timed out, we "bookmarked" the url that he was going to
        // so that we can send him there after login. otherwise, he gets the dashboard.
        String url = getBookmarkedUrl(session);
        if ((url == null) || url.equals("/Logout.do")) {
            url = URL_DASHBOARD;
        }
        if (url.toLowerCase().indexOf("ajax") != -1) {
            // we can't return to a URL that was a partial page request
            // because the view no longer exists, and will blow up.
            // instead, redirect back to the last saved URL
            url = webUser.getWebPreferences().getLastVisitedURL(2);
            log.info("Bypassing partial-page with " + url);
        }

        af = new ActionForward(url);
    }

    af.setRedirect(true);

    // now that we've constructed a forward to the bookmarked url,
    // if any, forget the old session and start a new one,
    // setting the web user to show that we're logged in
    session.invalidate();
    session = request.getSession(true);
    SessionUtils.setWebUser(session, webUser);
    session.setAttribute(Constants.USER_OPERATIONS_ATTR, userGlobalPermissionsMap);

    if (needsRegistration) {
        // will be cleaned out during registration
        session.setAttribute(Constants.PASSWORD_SES_ATTR, logonForm.getJ_password());
    }

    return af;
}