{
refreshData();
}
Form profileForm = new Form("profileForm");
add(profileForm);
profileForm.add(new CheckBox("userEnabled", new PropertyModel(this,
"userEnabled")));
profileForm.add(new Label("enabledLabel", new ResourceModel(
"common.enabled")));
profileForm.add(new Button("submit", new ResourceModel(
principalParam + ".update.button")){
@Override
public void onSubmit()
{
try
{
getPrincipal().setEnabled(isUserEnabled());
getManager().updatePrincipal(principal);
setPrincipal(principal);
principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
}
catch (SecurityException jSx)
{
log.error("Failed to update principal.", jSx);
}
}
});
profileForm.add(new Button("remove", new ResourceModel(principalParam + ".remove.button")){
@Override
public void onSubmit()
{
try
{
getManager().removePrincipal(principal.getName());
setPrincipal(null);
controlPannels(false);
principalDataProvider.refresh(getManager(),getRoleManager(),getSearchString());
}
catch (SecurityException e)
{
error(e.getMessage());
}
}
}.add(new JavascriptEventConfirmation("onclick",new ResourceModel("action.delete.confirm"))));
Form userRulesForm = new Form("userRulesForm")
{
protected void onSubmit()
{
try
{
Collection rules = getServiceLocator().getProfiler()
.getRulesForPrincipal(getPrincipal());
for (Iterator it = getUserRules().iterator(); it
.hasNext();)
{
Map ruleMap = (Map) it.next();
if (Boolean.TRUE.equals(ruleMap.get("checked")))
{
String locatorName = ((PrincipalRule) ruleMap
.get("rule")).getLocatorName();
for (Iterator ruleIter = rules.iterator(); ruleIter
.hasNext();)
{
PrincipalRule rule = (PrincipalRule) ruleIter
.next();
if (rule.getLocatorName().equals(
locatorName))
{
getServiceLocator().getProfiler()
.deletePrincipalRule(rule);
getServiceLocator()
.getAuditActivity()
.logAdminAuthorizationActivity(
getPortletRequest()
.getUserPrincipal()
.getName(),
getIPAddress(),
getSelectedPrincipal(),
AuditActivity.USER_DELETE_PROFILE,
rule.getProfilingRule()
.getId()
+ "-"
+ rule
.getLocatorName(),
AdminPortletWebPage.USER_ADMINISTRATION);
}
}
}
}
} catch (Exception e)
{
error(e.getMessage());
}
refreshData();
}
};
SortableDataProvider dataProvider = new SortableDataProvider()
{
public int size()
{
return getUserRules().size();
}
public IModel model(Object object)
{
Map ruleMap = (Map) object;
return new Model((Serializable) ruleMap);
}
public Iterator iterator(int first, int count)
{
return getUserRules().subList(first, first + count)
.iterator();
}
};
IColumn[] columns =
{
new CheckBoxPropertyColumn(new Model(" "), "checked"),
new PropertyColumn(new ResourceModel("user.ruleName"),
"rule.locatorName"),
new PropertyColumn(new ResourceModel("user.ruleValue"),
"rule.profilingRule")};
DataTable userRulesDataTable = new DataTable("entries", columns,
dataProvider, 10)
{
protected Item newRowItem(String id, int index, IModel model)
{
return new PortletOddEvenItem(id, index, model);
}
};
userRulesDataTable.addTopToolbar(new HeadersToolbar(
userRulesDataTable, dataProvider));
userRulesDataTable.addBottomToolbar(new NavigationToolbar(
userRulesDataTable));
userRulesForm.add(userRulesDataTable);
userRulesForm.add(new Button("submit", new ResourceModel(
"common.delete")));
add(userRulesForm);
Form addRuleForm = new Form("addRuleForm")
{
protected void onSubmit()
{
String locatorName = getLocatorName();
if (locatorName != null && locatorName.trim().length() > 0)
{
try
{
String ruleName = getRuleName();
Profiler profiler = getServiceLocator().getProfiler();
ProfilingRule profilingRule = profiler.getRule(ruleName);
if (profilingRule != null)
{
profiler.setRuleForPrincipal(getPrincipal(), profilingRule, locatorName);
}
else
{
log.error("Failed to set profiling rule for the principal. Invalid profiling rule: " + ruleName);
}
getServiceLocator()
.getAuditActivity()
.logAdminAuthorizationActivity(
getPortletRequest()
.getUserPrincipal()
.getName(),
getIPAddress(),
getSelectedPrincipal(),
AuditActivity.USER_ADD_PROFILE,
ruleName + "-" + locatorName,
AdminPortletWebPage.USER_ADMINISTRATION);
} catch (Exception e)
{
error(e.getMessage());
}
refreshData();
}
}
};
addRuleForm.add(new Label("userruleNamelabel", new ResourceModel(
"user.ruleName")));
addRuleForm.add(new Label("userruledesclabel", new ResourceModel(
"user.rule.desc")));
RequiredTextField locatorNameField = new RequiredTextField(
"locatorName", new PropertyModel(this, "locatorName"));
addRuleForm.add(locatorNameField);
addRuleForm.add(new Label("userrulelabel", new ResourceModel(
"user.ruleValue")));
DropDownChoice ruleNameField = new DropDownChoice("ruleName",
new PropertyModel(this, "ruleName"), getFullRules());
addRuleForm.add(ruleNameField);
addRuleForm.add(new Button("addRule", new ResourceModel(
"user.rule.add")));
add(addRuleForm);
add(new FeedbackPanel("feedback"));