-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Luca Bassi
committed
Dec 13, 2024
1 parent
54978b2
commit 7d6fb5f
Showing
15 changed files
with
404 additions
and
367 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/main/java/org/italiangrid/storm/webdav/authz/managers/ConsensusBasedManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.authz.managers; | ||
|
||
import java.util.List; | ||
import java.util.function.Supplier; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.security.authorization.AuthorizationDecision; | ||
import org.springframework.security.authorization.AuthorizationManager; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.access.intercept.RequestAuthorizationContext; | ||
|
||
public class ConsensusBasedManager implements AuthorizationManager<RequestAuthorizationContext> { | ||
|
||
public static final Logger LOG = LoggerFactory.getLogger(ConsensusBasedManager.class); | ||
|
||
private final List<AuthorizationManager<RequestAuthorizationContext>> managers; | ||
|
||
private final String name; | ||
|
||
public ConsensusBasedManager(String name, | ||
List<AuthorizationManager<RequestAuthorizationContext>> managers) { | ||
this.name = name; | ||
this.managers = managers; | ||
} | ||
|
||
@Override | ||
public AuthorizationDecision check(Supplier<Authentication> authentication, | ||
RequestAuthorizationContext requestAuthorizationContext) { | ||
int grant = 0; | ||
int notGrant = 0; | ||
|
||
for (AuthorizationManager<RequestAuthorizationContext> manager : managers) { | ||
AuthorizationDecision result = manager.check(authentication, requestAuthorizationContext); | ||
|
||
if (LOG.isDebugEnabled()) { | ||
LOG.debug("Voter: {}, returned: {}", manager, result); | ||
} | ||
|
||
if (result != null) { | ||
if (result.isGranted()) { | ||
grant++; | ||
} else { | ||
notGrant++; | ||
} | ||
} | ||
} | ||
|
||
if (grant == 0 && notGrant == 0) { | ||
return new AuthorizationDecision(true); | ||
} else { | ||
return new AuthorizationDecision(grant >= notGrant); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/italiangrid/storm/webdav/authz/managers/MacaroonAuthzManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/** | ||
* Copyright (c) Istituto Nazionale di Fisica Nucleare, 2014-2023. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.italiangrid.storm.webdav.authz.managers; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import org.springframework.http.HttpMethod; | ||
import org.springframework.security.authorization.AuthorizationDecision; | ||
import org.springframework.security.authorization.AuthorizationManager; | ||
import org.springframework.security.core.Authentication; | ||
import org.springframework.security.web.access.intercept.RequestAuthorizationContext; | ||
import org.springframework.util.Assert; | ||
|
||
public class MacaroonAuthzManager implements AuthorizationManager<RequestAuthorizationContext> { | ||
|
||
@Override | ||
public AuthorizationDecision check(Supplier<Authentication> authentication, | ||
RequestAuthorizationContext requestAuthorizationContext) { | ||
Assert.notNull(authentication.get(), "authentication must not be null"); | ||
Assert.notNull(requestAuthorizationContext, "filterInvocation must not be null"); | ||
|
||
if (HttpMethod.POST.name().equals(requestAuthorizationContext.getRequest().getMethod())) { | ||
return new AuthorizationDecision(true); | ||
} | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.