Skip to content

Commit 31b8b13

Browse files
committed
Requiring more Entitlements to check for Connectors and / or Resources
1 parent e9ab897 commit 31b8b13

6 files changed

Lines changed: 27 additions & 21 deletions

File tree

‎client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorDetailsPanel.java‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.util.Iterator;
2222
import java.util.List;
2323
import java.util.Optional;
24-
import java.util.stream.Collectors;
2524
import org.apache.commons.lang3.tuple.Pair;
2625
import org.apache.syncope.client.console.SyncopeWebApplication;
2726
import org.apache.syncope.client.console.commons.RealmsUtils;
@@ -91,8 +90,7 @@ protected Iterator<String> getChoices(final String input) {
9190
"bundleName",
9291
new PropertyModel<>(connInstanceTO, "bundleName"), false);
9392
bundleName.setEnabled(connInstanceTO.getKey() == null || connInstanceTO.isErrored());
94-
bundleName.setChoices(bundles.stream().map(ConnIdBundle::getBundleName).
95-
distinct().sorted().collect(Collectors.toList()));
93+
bundleName.setChoices(bundles.stream().map(ConnIdBundle::getBundleName).distinct().sorted().toList());
9694
bundleName.getField().setOutputMarkupId(true);
9795
add(bundleName.addRequiredLabel().setOutputMarkupId(true));
9896

@@ -123,7 +121,7 @@ protected void onUpdate(final AjaxRequestTarget target) {
123121
List<Pair<String, String>> connectors = bundles.stream().
124122
filter(bundle -> bundle.getBundleName().equals(connInstanceTO.getBundleName())).
125123
map(bundle -> Pair.of(bundle.getConnectorName(), bundle.getVersion())).
126-
toList();
124+
toList();
127125
if (connectors.size() == 1) {
128126
Pair<String, String> entry = connectors.getFirst();
129127

@@ -135,11 +133,9 @@ protected void onUpdate(final AjaxRequestTarget target) {
135133
version.getField().setModelObject(entry.getRight());
136134
version.setChoices(List.of(entry.getRight()));
137135
} else {
138-
connectorName.setChoices(connectors.stream().
139-
map(Pair::getLeft).distinct().sorted().collect(Collectors.toList()));
136+
connectorName.setChoices(connectors.stream().map(Pair::getLeft).distinct().sorted().toList());
140137

141-
List<String> versions = connectors.stream().
142-
map(Pair::getRight).distinct().sorted().collect(Collectors.toList());
138+
List<String> versions = connectors.stream().map(Pair::getRight).distinct().sorted().toList();
143139
version.setChoices(versions);
144140

145141
if (versions.size() == 1) {
@@ -165,7 +161,7 @@ protected void onUpdate(final AjaxRequestTarget target) {
165161
List<String> versions = bundles.stream().
166162
filter(bundle -> bundle.getBundleName().equals(connInstanceTO.getBundleName())
167163
&& bundle.getConnectorName().equals(connInstanceTO.getConnectorName())).
168-
map(ConnIdBundle::getVersion).collect(Collectors.toList());
164+
map(ConnIdBundle::getVersion).toList();
169165
if (versions.size() == 1) {
170166
connInstanceTO.setVersion(versions.getFirst());
171167
version.getField().setModelObject(versions.getFirst());

‎client/idm/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorWizardBuilder.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import java.io.Serializable;
2222
import java.net.URI;
2323
import java.util.List;
24-
import java.util.stream.Collectors;
2524
import org.apache.commons.lang3.tuple.Pair;
2625
import org.apache.syncope.client.console.rest.ConnectorRestClient;
2726
import org.apache.syncope.client.console.topology.TopologyNode;
@@ -53,7 +52,7 @@ public ConnectorWizardBuilder(
5352
super(defaultItem, pageRef);
5453

5554
this.bundles = connectorRestClient.getAllBundles().stream().
56-
filter(object -> object.getLocation().equals(defaultItem.getLocation())).collect(Collectors.toList());
55+
filter(object -> object.getLocation().equals(defaultItem.getLocation())).toList();
5756
this.connectorRestClient = connectorRestClient;
5857
}
5958

@@ -68,7 +67,7 @@ protected WizardModel buildModelSteps(final Serializable modelObject, final Wiza
6867
@Override
6968
protected Pair<Boolean, String> check(final AjaxRequestTarget target) {
7069
ConnInstanceTO connInstanceTO = ConnInstanceTO.class.cast(modelObject);
71-
ConnIdBundle bundleTO = ConnectorWizardBuilder.getBundle(connInstanceTO, bundles);
70+
ConnIdBundle bundleTO = getBundle(connInstanceTO, bundles);
7271

7372
connInstanceTO.setConnectorName(bundleTO.getConnectorName());
7473
connInstanceTO.setBundleName(bundleTO.getBundleName());

‎core/idm/logic/src/main/java/org/apache/syncope/core/logic/ConnectorLogic.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ public List<ConnIdObjectClass> buildObjectClassInfo(
239239
}).toList();
240240
}
241241

242-
@PreAuthorize("hasRole('" + IdMEntitlement.CONNECTOR_READ + "')")
242+
@PreAuthorize("hasRole('" + IdMEntitlement.CONNECTOR_READ + "') "
243+
+ "and (hasRole('" + IdMEntitlement.CONNECTOR_CREATE + "') "
244+
+ "or hasRole('" + IdMEntitlement.CONNECTOR_UPDATE + "'))")
243245
@Transactional(readOnly = true)
244246
public void check(final ConnInstanceTO connInstanceTO) {
245247
if (connInstanceTO.getAdminRealm() == null) {

‎core/idm/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,9 @@ public void handleResult(final SearchResult sr) {
427427
return Pair.of(searchResult, connObjects);
428428
}
429429

430-
@PreAuthorize("hasRole('" + IdMEntitlement.CONNECTOR_READ + "')")
430+
@PreAuthorize("hasRole('" + IdMEntitlement.CONNECTOR_READ + "') "
431+
+ "and (hasRole('" + IdMEntitlement.CONNECTOR_CREATE + "') "
432+
+ "or hasRole('" + IdMEntitlement.CONNECTOR_UPDATE + "'))")
431433
@Transactional(readOnly = true)
432434
public void check(final ResourceTO resourceTO) {
433435
ConnInstance connInstance = connInstanceDAO.findById(resourceTO.getConnector()).

‎core/workflow-java/src/main/java/org/apache/syncope/core/workflow/java/DefaultUserWorkflowAdapter.java‎

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.syncope.core.workflow.java;
2020

21+
import java.util.Optional;
2122
import org.apache.commons.lang3.tuple.Pair;
2223
import org.apache.syncope.common.keymaster.client.api.ConfParamOps;
2324
import org.apache.syncope.common.lib.request.PasswordPatch;
@@ -79,11 +80,17 @@ public DefaultUserWorkflowAdapter(
7980
this.notificationManager = notificationManager;
8081
}
8182

82-
protected void throwApprovalRequired(final String executor, final boolean condition) {
83-
if (!securityProperties.getAdminUser().equals(executor)
83+
protected void throwApprovalRequired(final String key, final boolean condition, final String executor) {
84+
if (securityProperties.getAdminUser().equals(executor)) {
85+
return;
86+
}
87+
88+
boolean isSelf = securityProperties.getAnonymousUser().equals(executor)
89+
|| Optional.ofNullable(key).flatMap(userDAO::findUsername).map(executor::equals).orElse(false);
90+
if (isSelf
91+
&& condition
8492
&& confParamOps.get(
85-
AuthContextUtils.getDomain(), "default.workflow.requires.approval", true, boolean.class)
86-
&& condition) {
93+
AuthContextUtils.getDomain(), "default.workflow.requires.approval", true, boolean.class)) {
8794

8895
throw new WorkflowException(new UnsupportedOperationException("This operation requires approval"));
8996
}
@@ -97,7 +104,7 @@ protected UserWorkflowResult<Pair<String, Boolean>> doCreate(
97104
final String creator,
98105
final String context) {
99106

100-
throwApprovalRequired(creator, userCR.requiresApproval());
107+
throwApprovalRequired(null, userCR.requiresApproval(), creator);
101108

102109
User user = entityFactory.newEntity(User.class);
103110
dataBinder.create(user, userCR);
@@ -159,7 +166,7 @@ protected UserWorkflowResult<String> doActivate(
159166
protected UserWorkflowResult<Pair<UserUR, Boolean>> doUpdate(
160167
final User user, final UserUR userUR, final String updater, final String context) {
161168

162-
throwApprovalRequired(updater, userUR.requiresApproval());
169+
throwApprovalRequired(userUR.getKey(), userUR.requiresApproval(), updater);
163170

164171
UserWorkflowResult.PropagationInfo propInfo = dataBinder.update(user, userUR);
165172

‎pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ under the License.
432432
<connid.ldup.version>0.1.0</connid.ldup.version>
433433

434434
<cxf.version>4.1.7</cxf.version>
435-
<bouncycastle.version>1.84</bouncycastle.version>
435+
<bouncycastle.version>1.85</bouncycastle.version>
436436
<nimbus-jose-jwt.version>10.9.1</nimbus-jose-jwt.version>
437437

438438
<spring-framework.version>6.2.19</spring-framework.version>

0 commit comments

Comments
 (0)