Skip to content

Commit

Permalink
object selectors and type selector for authorization playground
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Jun 29, 2023
1 parent 7a60f96 commit 20b1109
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,16 @@ public class ValueChoosePanel<R extends Referencable> extends BasePanel<R> {

public ValueChoosePanel(String id, IModel<R> value) {
super(id, value);
}

@Override
protected void onInitialize() {
super.onInitialize();
initLayout();
setOutputMarkupId(true);
initLayer();
}

private void initLayer() {
private void initLayout() {
WebMarkupContainer textWrapper = new WebMarkupContainer(ID_TEXT_WRAPPER);

textWrapper.setOutputMarkupId(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ <h3>Introduction</h3>
<div class="col-lg-12">
<h3><wicket:message key="PageAuthorizationPlayground.Subject"/></h3>
<div style="padding: 15px; margin-bottom: 15px">
<b>TODO</b> Here will be a select box that would allow us to select any subject. For the time being, you may specify the OID here:
<input class="input-sm form-control" wicket:id="subjectOid"/>
Select any subject. For the time being, you may specify the OID here:
<div wicket:id="subjectOid"/>
</div>
</div>
<div class="col-lg-12">
Expand All @@ -45,7 +45,7 @@ <h3>Filter processing</h3>
</div>
<div>
<label for="type">Please select the type of objects:</label>
<input id="type" class="input-sm form-control" wicket:id="type"/>
<div id="type" wicket:id="type"/>
</div>
<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> <!-- hack (as everything on this page) -->
<div class="col-lg-12; margin-top: 10px">
Expand All @@ -60,7 +60,7 @@ <h3>Object processing</h3>
</div>
<div>
<label for="objectOid">Please enter the object OID (temporary):</label>
<input id="objectOid" class="input-sm form-control" wicket:id="objectOid"/>
<div id="objectOid" wicket:id="objectOid"/>
</div>
</div>
<div class="row" style="margin-top: 10px">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@
import java.util.List;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.util.CloneUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.form.ValueChoosePanel;
import com.evolveum.midpoint.web.component.input.DropDownChoicePanel;
import com.evolveum.midpoint.web.component.input.QNameChoiceRenderer;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
Expand Down Expand Up @@ -92,14 +97,13 @@ public class PageAuthorizationPlayground extends PageAdminConfiguration {
// TODO add other ones
);

private final IModel<String> subjectOidModel = Model.of("");

private final IModel<String> additionalAuthorizationsModel =
new Model<>("<additionalAuthorizations>\n</additionalAuthorizations>");

private final IModel<String> typeModel = new Model<>("UserType");
private final IModel<QName> typeModel = new Model<>(UserType.COMPLEX_TYPE);
private final IModel<String> filterModel = new Model<>();
private final IModel<String> objectOidModel = Model.of("");
private final IModel<ObjectReferenceType> objectModel = Model.of(new ObjectReferenceType());
private final IModel<ObjectReferenceType> subjectModel = Model.of(new ObjectReferenceType());

private final IModel<Boolean> selectorTracingModel = Model.of(false);

Expand All @@ -114,21 +118,34 @@ private void initLayout() {
Form<?> mainForm = new MidpointForm<>(ID_MAIN_FORM);
add(mainForm);

mainForm.add(new TextField<>(ID_SUBJECT_OID, subjectOidModel));
mainForm.add(new ValueChoosePanel<>(ID_SUBJECT_OID, subjectModel) {

@Override
protected <O extends ObjectType> Class<O> getDefaultType(List<QName> supportedTypes) {
return (Class<O>) WebComponentUtil.qnameToClass(PrismContext.get(), typeModel.getObject());
}

@Override
public List<QName> getSupportedTypes() {
return WebComponentUtil.createObjectTypeList();
}
});

mainForm.add(new ValueChoosePanel<>(ID_OBJECT_OID, objectModel));

var additionalAuthorizationsEditor = new AceEditor(ID_ADDITIONAL_AUTHORIZATIONS, additionalAuthorizationsModel);
additionalAuthorizationsEditor.setHeight(400);
additionalAuthorizationsEditor.setResizeToMaxHeight(false);
mainForm.add(additionalAuthorizationsEditor);

mainForm.add(new TextField<>(ID_TYPE, typeModel));
mainForm.add(new DropDownChoicePanel<>(ID_TYPE, typeModel, () -> WebComponentUtil.createObjectTypeList(), new QNameChoiceRenderer()));

var filterEditor = new AceEditor(ID_OBJECT_FILTER, filterModel);
filterEditor.setHeight(400);
filterEditor.setResizeToMaxHeight(false);
mainForm.add(filterEditor);

mainForm.add(new TextField<>(ID_OBJECT_OID, objectOidModel));
// mainForm.add(new TextField<>(ID_OBJECT_OID, objectOidModel));

mainForm.add(new CheckBox(ID_SELECTOR_TRACING, selectorTracingModel));

Expand Down Expand Up @@ -215,18 +232,16 @@ private void evaluatePerformed(AjaxRequestTarget target) {

/** Returns request without adornments like extra authorizations etc. */
private AuthorizationEvaluationRequestType createRequestRaw() throws SchemaException {
String objectOid = objectOidModel.getObject();
ObjectReferenceType objectOid = objectModel.getObject();
if (objectOid != null) {
return new AuthorizationEvaluationAccessDecisionRequestType()
.objectRef(new ObjectReferenceType()
.type(ObjectType.COMPLEX_TYPE) // will be fixed when appropriate GUI component is used
.oid(objectOid));
.objectRef(objectOid);
}

String typeName = typeModel.getObject();
QName typeName = typeModel.getObject();
if (typeName != null) {
return new AuthorizationEvaluationFilterProcessingRequestType()
.type(new QName(typeName))
.type(typeName)
.filter(createFilterBean());
}

Expand All @@ -243,11 +258,9 @@ private SearchFilterType createFilterBean() throws SchemaException {
}

private void setSubjectRef(AuthorizationEvaluationRequestType request) {
String subjectOid = subjectOidModel.getObject();
if (StringUtils.isNotEmpty(subjectOid)) {
request.setSubjectRef(new ObjectReferenceType()
.type(FocusType.COMPLEX_TYPE)
.oid(subjectOid));
ObjectReferenceType subjectOid = subjectModel.getObject();
if (StringUtils.isNotEmpty(subjectOid.getOid())) {
request.setSubjectRef(subjectOid);
}
}

Expand Down

0 comments on commit 20b1109

Please sign in to comment.