Skip to content

Commit

Permalink
tweaks and enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Jul 10, 2024
1 parent 5b2a01d commit 65946e4
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.dominokit.brix.api.ConfigImpl;
import org.dominokit.brix.api.StartupTask;
import org.dominokit.brix.events.BrixEvents;
import org.dominokit.brix.security.IsSecurityContext;
import org.dominokit.brix.security.SecurityContext;
import org.dominokit.brix.tasks.TasksRunner;
import org.dominokit.domino.client.history.StateHistory;
Expand Down Expand Up @@ -64,7 +65,7 @@ public BrixSlots slots() {

@Singleton
@Provides
public SecurityContext securityContext() {
public IsSecurityContext securityContext() {
return new SecurityContext();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.dominokit.brix.api.BrixSlots;
import org.dominokit.brix.api.Config;
import org.dominokit.brix.events.BrixEvents;
import org.dominokit.brix.security.SecurityContext;
import org.dominokit.brix.security.IsSecurityContext;
import org.dominokit.domino.history.AppHistory;

@Module
Expand Down Expand Up @@ -60,7 +60,7 @@ default Config globalConfig() {

@Singleton
@Provides
default SecurityContext globalSecurityContext() {
default IsSecurityContext globalSecurityContext() {
return coreComponent().core().getSecurityContext();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import org.dominokit.brix.events.BrixEvent;
import org.dominokit.brix.events.BrixEvents;
import org.dominokit.brix.events.EventListener;
import org.dominokit.brix.events.HasRoles;
import org.dominokit.brix.events.RegistrationRecord;
import org.dominokit.brix.security.Authorizer;
import org.dominokit.brix.security.DefaultAuthorizer;
import org.dominokit.brix.security.HasAuthorizer;
import org.dominokit.brix.security.HasRoles;
import org.dominokit.brix.security.SecurityContext;
import org.dominokit.brix.security.IsSecurityContext;
import org.dominokit.domino.history.AppHistory;
import org.dominokit.domino.history.DominoHistory;
import org.dominokit.domino.history.HistoryInterceptor;
Expand All @@ -54,7 +54,7 @@ public abstract class Presenter<V extends Viewable>

@Inject @Global protected BrixSlots slots;

@Inject protected SecurityContext securityContext;
@Inject protected IsSecurityContext securityContext;
@Inject @Global protected Config config;

private RegistrationRecord eventsListenerRecord;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package org.dominokit.brix.security;

import org.dominokit.brix.events.HasRoles;

public interface Authorizer {
boolean isAuthorized(SecurityContext context, HasRoles hasRoles);
boolean isAuthorized(IsSecurityContext context, HasRoles hasRoles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
*/
package org.dominokit.brix.security;

import org.dominokit.brix.events.HasRoles;

public class DefaultAuthorizer implements Authorizer {

public static final Authorizer INSTANCE = new DefaultAuthorizer();

@Override
public boolean isAuthorized(SecurityContext context, HasRoles hasRoles) {
public boolean isAuthorized(IsSecurityContext context, HasRoles hasRoles) {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package org.dominokit.brix.security;

import org.dominokit.brix.events.HasRoles;

public class DenyAllAuthorizer implements Authorizer {
public static final Authorizer INSTANCE = new DenyAllAuthorizer();

@Override
public boolean isAuthorized(SecurityContext context, HasRoles hasRoles) {
public boolean isAuthorized(IsSecurityContext context, HasRoles hasRoles) {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © 2019 Dominokit
*
* 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.dominokit.brix.security;

import java.util.Collection;
import java.util.Optional;
import org.dominokit.brix.events.BrixUser;

public interface IsSecurityContext {
<U extends BrixUser> Optional<U> getUser();

boolean isAuthorizedFor(String role);

boolean isAuthorizedForAll(String... roles);

void reportUnAuthorizedAccess();

boolean isAuthorizedForAll(Collection<String> roles);

boolean isAuthorizedForAny(String... roles);

boolean isAuthorizedForAny(Collection<String> roles);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package org.dominokit.brix.security;

import org.dominokit.brix.events.BrixUser;
import org.dominokit.brix.events.HasRoles;

public class PermitAllAuthorizer implements Authorizer {
public static final Authorizer INSTANCE = new PermitAllAuthorizer();

@Override
public boolean isAuthorized(SecurityContext context, HasRoles hasRoles) {
public boolean isAuthorized(IsSecurityContext context, HasRoles hasRoles) {
return context.getUser().map(BrixUser::isAuthenticated).orElse(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@
*/
package org.dominokit.brix.security;

import org.dominokit.brix.events.BrixUser;
import org.dominokit.brix.events.HasRoles;

public class RolesAllowedAuthorizer implements Authorizer {
public static final Authorizer INSTANCE = new RolesAllowedAuthorizer();

@Override
public boolean isAuthorized(SecurityContext context, HasRoles hasRoles) {
public boolean isAuthorized(IsSecurityContext context, HasRoles hasRoles) {
Boolean authenticated = context.getUser().map(BrixUser::isAuthenticated).orElse(false);
return authenticated && context.isAuthorizedForAny(hasRoles.getRoles());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.dominokit.brix.events.BrixUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Singleton
public class SecurityContext {
public class SecurityContext implements IsSecurityContext {

private static final Logger LOGGER = LoggerFactory.getLogger(SecurityContext.class);

Expand All @@ -48,7 +49,7 @@ public SecurityContext setUser(BrixUser user) {
return this;
}

public void unauthorizedAccessHandler(Runnable handler) {
public void setUnauthorizedAccessHandler(Runnable handler) {
this.unauthorizedAccessHandler = handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dominokit.brix.security;
package org.dominokit.brix.events;

public interface BrixUser extends HasRoles {
boolean isAuthenticated();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dominokit.brix.security;
package org.dominokit.brix.events;

import java.util.Set;

Expand Down

0 comments on commit 65946e4

Please sign in to comment.