This repository has been archived by the owner on Jun 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #683 from zalando/ARUHA-759-per-event-type-authz
Aruha 759 per event type authz
- Loading branch information
Showing
6 changed files
with
95 additions
and
32 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
57 changes: 57 additions & 0 deletions
57
src/main/java/org/zalando/nakadi/config/PluginsConfig.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,57 @@ | ||
package org.zalando.nakadi.config; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.BeanCreationException; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.DefaultResourceLoader; | ||
import org.zalando.nakadi.plugin.api.ApplicationService; | ||
import org.zalando.nakadi.plugin.api.ApplicationServiceFactory; | ||
import org.zalando.nakadi.plugin.api.SystemProperties; | ||
import org.zalando.nakadi.plugin.api.authz.AuthorizationService; | ||
import org.zalando.nakadi.plugin.api.authz.AuthorizationServiceFactory; | ||
|
||
@Configuration | ||
public class PluginsConfig { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(PluginsConfig.class); | ||
|
||
@Bean | ||
public SystemProperties systemProperties(final ApplicationContext context) { | ||
return name -> context.getEnvironment().getProperty(name); | ||
} | ||
|
||
@Bean | ||
@SuppressWarnings("unchecked") | ||
public ApplicationService applicationService(@Value("${nakadi.plugins.auth.factory}") final String factoryName, | ||
final SystemProperties systemProperties, | ||
final DefaultResourceLoader loader) { | ||
try { | ||
LOGGER.info("Initialize application service factory: " + factoryName); | ||
final Class<ApplicationServiceFactory> factoryClass = | ||
(Class<ApplicationServiceFactory>) loader.getClassLoader().loadClass(factoryName); | ||
final ApplicationServiceFactory factory = factoryClass.newInstance(); | ||
return factory.init(systemProperties); | ||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { | ||
throw new BeanCreationException("Can't create ApplicationService " + factoryName, e); | ||
} | ||
} | ||
|
||
@Bean | ||
public AuthorizationService authorizationService(@Value("${nakadi.plugins.authz.factory}") final String factoryName, | ||
final SystemProperties systemProperties, | ||
final DefaultResourceLoader loader) { | ||
try { | ||
LOGGER.info("Initialize per-resource authorization service factory: " + factoryName); | ||
final Class<AuthorizationServiceFactory> factoryClass = | ||
(Class<AuthorizationServiceFactory>) loader.getClassLoader().loadClass(factoryName); | ||
final AuthorizationServiceFactory factory = factoryClass.newInstance(); | ||
return factory.init(systemProperties); | ||
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { | ||
throw new BeanCreationException("Can't create AuthorizationService " + factoryName, e); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/org/zalando/nakadi/plugin/auth/DefaultAuthorizationService.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,19 @@ | ||
package org.zalando.nakadi.plugin.auth; | ||
|
||
import org.zalando.nakadi.plugin.api.authz.AuthorizationAttribute; | ||
import org.zalando.nakadi.plugin.api.authz.AuthorizationService; | ||
import org.zalando.nakadi.plugin.api.authz.Resource; | ||
import org.zalando.nakadi.plugin.api.authz.Subject; | ||
|
||
public class DefaultAuthorizationService implements AuthorizationService { | ||
|
||
@Override | ||
public boolean isAuthorized(final Subject subject, final Operation operation, final Resource resource) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isAuthorizationAttributeValid(final AuthorizationAttribute authorizationAttribute) { | ||
return true; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/zalando/nakadi/plugin/auth/DefaultAuthorizationServiceFactory.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,13 @@ | ||
package org.zalando.nakadi.plugin.auth; | ||
|
||
import org.zalando.nakadi.plugin.api.SystemProperties; | ||
import org.zalando.nakadi.plugin.api.authz.AuthorizationService; | ||
import org.zalando.nakadi.plugin.api.authz.AuthorizationServiceFactory; | ||
|
||
public class DefaultAuthorizationServiceFactory implements AuthorizationServiceFactory { | ||
|
||
@Override | ||
public AuthorizationService init(final SystemProperties systemProperties) { | ||
return new DefaultAuthorizationService(); | ||
} | ||
} |
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