Search in sources :

Example 1 with WhoAmI

use of net.sourceforge.processdash.tool.perm.WhoAmI in project processdash by dtuma.

the class WBSPermissionManager method init.

/**
     * Identify the current user and determine their permissions.
     */
public static void init(WorkingDirectory workingDirectory, TeamProject proj) throws HttpException.Unauthorized {
    // determine the identity of the current user.
    String pdesUrl;
    if (workingDirectory instanceof BridgedWorkingDirectory)
        pdesUrl = workingDirectory.getDescription();
    else
        pdesUrl = ExternalLocationMapper.getInstance().getDatasetUrl();
    WhoAmI whoAmI = new WhoAmI(pdesUrl);
    currentUser = whoAmI.getUsername();
    // look at the team settings.xml file. if it was written by an old
    // version of the dashboard, it will not contain a version. In that
    // case, exit without any further analysis.
    Element settings = proj.getProjectSettings();
    if (settings == null)
        return;
    version = settings.getAttribute("version");
    if (!XMLUtils.hasValue(version))
        return;
    // the settings.xml file was written by a version of the dashboard that
    // knows how to publish permissions. Check to ensure that it has not
    // been tampered with. If it has, grant no permissions.
    File settingsFile = new File(proj.getStorageDirectory(), WBSFilenameConstants.SETTINGS_FILENAME);
    try {
        TamperDeterrent.getInstance().verifyThumbprint(settingsFile, FileType.WBS);
    } catch (Exception te) {
        System.err.println("The file " + settingsFile + " is corrupt; " + "locking down WBS permissions");
        version = "999.999";
        return;
    }
    // find the permissions granted in the settings.xml file
    Set<WBSPermission> perms = getPermissionsForUser(settings, currentUser.toLowerCase());
    perms.remove(null);
    // add the externally granted permissions of the current user
    for (String onePerm : whoAmI.getExternalPermissionGrants()) {
        if ("pdash.all".equals(onePerm))
            onePerm = ALL_PERMISSIONS;
        perms.add(new WBSPermission(onePerm));
    }
    // store these permissions for future use
    permissions = Collections.unmodifiableSet(perms);
    debugLogPermissions();
}
Also used : Element(org.w3c.dom.Element) BridgedWorkingDirectory(net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory) WhoAmI(net.sourceforge.processdash.tool.perm.WhoAmI) File(java.io.File) HttpException(net.sourceforge.processdash.util.HttpException)

Aggregations

File (java.io.File)1 BridgedWorkingDirectory (net.sourceforge.processdash.tool.bridge.client.BridgedWorkingDirectory)1 WhoAmI (net.sourceforge.processdash.tool.perm.WhoAmI)1 HttpException (net.sourceforge.processdash.util.HttpException)1 Element (org.w3c.dom.Element)1