📄 cmschacc.java
字号:
/**
* Determines the int type of the current access control entry.<p>
*
* @param flags the value of the current flags
* @return int representation of the ace type as int
*/
protected int getEntryTypeInt(int flags) {
for (int i = 0; i < getTypes().length; i++) {
if ((flags & getTypesInt()[i]) > 0) {
return i;
}
}
return -1;
}
/**
* Returns if the access control entry can be inherited to subfolders and can overwrite inherited permissions.<p>
*
* @return true to show the checkbox, otherwise false
*/
protected boolean getInheritOption() {
return m_inherit;
}
/**
* Returns if the inherited permissions information should be displayed.<p>
*
* @return true if the inherited permissions information should be displayed, otherwise false
*/
public boolean getShowInheritedPermissions() {
return m_showInheritedPermissions;
}
/**
* Returns a String array with the possible entry types.<p>
*
* @return the possible types
*/
protected String[] getTypes() {
return m_types;
}
/**
* Returns an int array with possible entry types.<p>
*
* @return the possible types as int array
*/
protected int[] getTypesInt() {
return m_typesInt;
}
/**
* Returns a String array with the possible localized entry types.<p>
*
* @return the possible localized types
*/
protected String[] getTypesLocalized() {
return m_typesLocalized;
}
/**
* @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
*/
protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
// fill the parameter values in the get/set methods
fillParamValues(request);
// set the detail mode of the "inherited" list view
String detail = request.getParameter(PARAM_VIEW);
if (detail != null) {
settings.setPermissionDetailView(detail);
setShowInheritedPermissions(true);
}
// determine which action has to be performed
if (DIALOG_TYPE.equals(getParamAction())) {
setAction(ACTION_DEFAULT);
} else if (DIALOG_SET.equals(getParamAction())) {
setAction(ACTION_SET);
} else if (DIALOG_DELETE.equals(getParamAction())) {
setAction(ACTION_DELETE);
} else if (DIALOG_ADDACE.equals(getParamAction())) {
setAction(ACTION_ADDACE);
} else if (DIALOG_CANCEL.equals(getParamAction())) {
setAction(ACTION_CANCEL);
} else if (DIALOG_INTERNALUSE.equals(getParamAction())) {
setAction(ACTION_INTERNALUSE);
} else {
setAction(ACTION_DEFAULT);
// build the title for chacc dialog
setParamTitle(key(Messages.GUI_PERMISSION_CHANGE_1, new Object[] {CmsResource.getName(getParamResource())}));
}
}
/**
* Checks if a certain permission of a permission set is allowed.<p>
*
* @param p the current CmsPermissionSet
* @param value the int value of the permission to check
* @return true if the permission is allowed, otherwise false
*/
protected boolean isAllowed(CmsPermissionSet p, int value) {
if ((p.getAllowedPermissions() & value) > 0) {
return true;
}
return false;
}
/**
* Checks if a certain permission of a permission set is denied.<p>
*
* @param p the current CmsPermissionSet
* @param value the int value of the permission to check
* @return true if the permission is denied, otherwise false
*/
protected boolean isDenied(CmsPermissionSet p, int value) {
if ((p.getDeniedPermissions() & value) > 0) {
return true;
}
return false;
}
/**
* Check if the current permissions are inherited to subresources.<p>
*
* @param flags value of all flags of the current entry
* @return true if permissions are inherited to subresources, otherwise false
*/
protected boolean isInheriting(int flags) {
if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_INHERIT) > 0) {
return true;
}
return false;
}
/**
* Check if the current permissions are overwriting the inherited ones.<p>
*
* @param flags value of all flags of the current entry
* @return true if permissions are overwriting the inherited ones, otherwise false
*/
protected boolean isOverWritingInherited(int flags) {
if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE) > 0) {
return true;
}
return false;
}
/**
* Check if the user is a responsible for the resource.<p>
*
* @param flags value of all flags of the current entry
* @return true if user is responsible for the resource, otherwise false
*/
protected boolean isResponsible(int flags) {
if ((flags & CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE) > 0) {
return true;
}
return false;
}
/**
* Sets the current users permissions on the resource.
* This is set in the init() method.<p>
*
* @param value the CmsPermissionSet
*/
protected void setCurPermissions(CmsPermissionSet value) {
m_curPermissions = value;
}
/**
* Sets the editable flag for the forms.
* This is set in the init() method.<p>
*
* @param value true if user can edit the permissions, otherwise false
*/
protected void setEditable(boolean value) {
m_editable = value;
}
/**
* Sets if the access control entry can be inherited to subfolders and can overwrite inherited permissions.<p>
*
* This is set in the init() method.<p>
*
* @param value set to true for folders, otherwise false
*/
protected void setInheritOption(boolean value) {
m_inherit = value;
}
/**
* Sets if the inherited permissions information should be displayed.<p>
*
* @param showInheritedPermissions true if the inherited permissions information should be displayed, otherwise false
*/
protected void setShowInheritedPermissions(boolean showInheritedPermissions) {
m_showInheritedPermissions = showInheritedPermissions;
}
/**
* Builds a String with HTML code to display the form to add a new access control entry for the current resource.<p>
*
* @return HTML String with the form
*/
private String buildAddForm() {
StringBuffer result = new StringBuffer(256);
// only display form if the current user has the "control" right
if (getEditable()) {
result.append(dialogSpacer());
result.append(dialogBlockStart(key(Messages.GUI_PERMISSION_ADD_ACE_0)));
// get all possible entry types
ArrayList options = new ArrayList();
ArrayList optionValues = new ArrayList();
for (int i = 0; i < getTypes().length; i++) {
options.add(getTypesLocalized()[i]);
optionValues.add(Integer.toString(i));
}
// create the input form for adding an ace
result.append("<form action=\"").append(getDialogUri()).append(
"\" method=\"post\" name=\"add\" class=\"nomargin\">\n");
// set parameters to show correct hidden input fields
setParamAction(DIALOG_ADDACE);
setParamType(null);
setParamName(null);
result.append(paramsAsHidden());
result.append("<table border=\"0\" width=\"100%\">\n");
result.append("<tr>\n");
result.append("\t<td>").append(buildSelect("name=\"" + PARAM_TYPE + "\"", options, optionValues, -1)).append("</td>\n");
result.append("\t<td class=\"maxwidth\"><input type=\"text\" class=\"maxwidth\" name=\"");
result.append(PARAM_NAME);
result.append("\" value=\"\"></td>\n");
result.append("\t<td><input class=\"dialogbutton\" style=\"width: 60px;\" type=\"button\" value=\"");
result.append(key(Messages.GUI_LABEL_SEARCH_0)).append(
"\" onClick=\"javascript:openDialogWin('chaccbrowser.jsp','UserGroup');\"></td>\n");
result.append("\t<td><input class=\"dialogbutton\" type=\"submit\" value=\"").append(key(Messages.GUI_LABEL_ADD_0)).append(
"\"></td>\n");
result.append("</tr>\n");
result.append("</form>\n");
result.append("</table>\n");
result.append(dialogBlockEnd());
}
return result.toString();
}
/**
* Builds a StringBuffer with HTML code to show a list of all inherited access control entries.<p>
*
* @param entries ArrayList with all entries to show for the long view
* @param parents Map of parent resources needed to get the connected resources for the detailed view
* @return StringBuffer with HTML code for all entries
*/
private StringBuffer buildInheritedList(ArrayList entries, Map parents) {
StringBuffer result = new StringBuffer(32);
String view = getSettings().getPermissionDetailView();
Iterator i;
// display the long view
if ("long".equals(view)) {
i = entries.iterator();
while (i.hasNext()) {
CmsAccessControlEntry curEntry = (CmsAccessControlEntry)i.next();
// build the list with enabled extended view and resource name
result.append(buildPermissionEntryForm(curEntry, false, true, getConnectedResource(curEntry, parents)));
}
} else {
// show the short view, use an ACL to build the list
try {
// get the inherited ACL of the parent folder
CmsAccessControlList acList = getCms().getAccessControlList(getParamResource(), true);
Set principalSet = acList.getPrincipals();
i = principalSet.iterator();
while (i.hasNext()) {
CmsUUID principalId = (CmsUUID)i.next();
I_CmsPrincipal principal = getCms().lookupPrincipal(principalId);
CmsPermissionSet permissions = acList.getPermissions(principal);
// build the list with enabled extended view only
result.append(buildPermissionEntryForm(principalId, permissions, false, true));
}
} catch (CmsException e) {
// can usually be ignored
if (LOG.isInfoEnabled()) {
LOG.info(e.getLocalizedMessage());
}
}
}
return result;
}
/**
* Builds a String with HTML code to display the form to add a new access control entry for the current resource.<p>
*
* @return HTML String with the form
*/
private String buildInternalForm() {
StringBuffer result = new StringBuffer(128);
CmsResource resource = null;
boolean internal = false;
// try to read the internal flag from the resource
try {
resource = getCms().readResource(getParamResource(), CmsResourceFilter.ALL);
internal = ((resource.getFlags() & CmsResource.FLAG_INTERNAL) > 0);
} catch (CmsException e) {
// an error occured reading the resource
LOG.error(e.getLocalizedMessage());
}
if ((resource != null) && (resource.isFile())) {
// only show internal checkbox on files
result.append("<form action=\"").append(getDialogUri()).append(
"\" method=\"post\" name=\"internal\" class=\"nomargin\">\n");
result.append("<table border=\"0\" width=\"100%\">\n");
result.append("<tr>\n");
result.append("\t<td class=\"dialogpermissioncell\">").append(key(Messages.GUI_PERMISSION_INTERNAL_0));
result.append(" <input type=\"checkbox\" name=\"");
result.append(PARAM_INTERNAL);
result.append("\" value=\"true\"");
if (internal) {
result.append(" checked=\"checked\"");
}
if (!getEditable()) {
result.append(" disabled=\"disabled\"");
}
result.append(" ></td>\n");
if (getEditable()) {
result.append("<td><input type=\"submit\" class=\"dialogbutton\" value=\"").append(
key(Messages.GUI_LABEL_SET_0)).append("\">");
}
result.append("</td>\n");
result.append("</tr>\n");
result.append("</table>\n");
setParamAction(DIALOG_INTERNALUSE);
setParamType(null);
setParamName(null);
result.append(paramsAsHidden());
result.append("</form>\n");
}
return result.toString();
}
/**
* Creates an HTML input form for the current access control entry.<p>
*
* @param entry the current access control entry
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -