Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#11 #12 - Bootstrap enhancements #13

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,21 @@ Options are:
* `-a` or `--admin`: **required**, the email address of the super administrator.
* `-p` or `--password`: the administrator's password;
one will be generated and printed to the standard output if not given.
* `-r` or `--redirect-uri`: **required**, the Ozwillo Portal's `redirect_uri`.
* `-plr` or `--post-logout-redirect-uri`: **required**, the Ozwillo Portal's `post_logout_redirect_uri`.
* `-pr` or `--portal-redirect-uri`: **required**, the Ozwillo Portal's `redirect_uri`.
* `-plr` or `--portal-post-logout-redirect-uri`: **required**, the Ozwillo Portal's `post_logout_redirect_uri`.
* `-dr` or `--datacore-redirect-uri`: **required**, the Ozwillo Datacore Playground's `redirect_uri`.
* `-ds` or `--datacore-service-uri`: **required**, the Ozwillo Datacore Playground's `service_uri`.
* `-di` or `--datacore-icon`: **required**, the Ozwillo Datacore Playground's icon.
* `-der` or `--dcexporter-redirect-uri`: the Ozwillo Datacore Exporter's `redirect_uri`.
* `-des` or `--dcexporter-service-uri`: the Ozwillo Datacore Exporter's `service_uri`.

The tool will create:
* the OpenID Connect 1.0 scopes,
* a super administrator user,
* an _“Ozwillo”_ organization, whose administrator will be the super administrator user,
* the Ozwillo Portal application, instance, and service,
* the Ozwillo DataCore application and instance (note: it does **not** create the _playground_ service.)
* the Ozwillo DataCore application, instance, and its Playground service,
* the Ozwillo DataCore Exporter application, instance and service

Periodic tasks
--------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
package oasis.model.bootstrap;

public interface ClientIds {
static final String PORTAL = "portal";
static final String DATACORE = "dc";
String PORTAL = "portal";
String DATACORE = "dc";
String DCEXPORTER = "dcexporter";
// XXX: add a "www" for the CMS part of the portal?
}
84 changes: 81 additions & 3 deletions oasis-webapp/src/main/java/oasis/tools/Bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,34 @@ public static void main(String[] args) throws Exception {
usage = "Administrator's password")
private String adminPassword;

@Option(name = "-r", aliases = "--redirect-uri", required = true,
@Option(name = "-pr", aliases = "--portal-redirect-uri", required = true,
usage = "Portal's redirect_uri")
private String portalRedirectUri;

@Option(name = "-plr", aliases = "--post-logout-redirect-uri", required = true,
@Option(name = "-plr", aliases = "--portal-post-logout-redirect-uri", required = true,
usage = "Portal's post_logout_redirect_uri")
private String portalPostLogoutRedirectUri;

@Option(name = "-dr", aliases = "--datacore-redirect-uri", required = true,
usage = "Datacore Playground's redirect_uri")
private String datacoreRedirectUri;

@Option(name = "-ds", aliases = "--datacore-service-uri", required = true,
usage = "Datacore Playground's service_uri")
private String datacoreServiceUri;

@Option(name = "-di", aliases = "--datacore-icon", required = true,
usage = "Datacore Playground's icon")
private String datacoreIcon;

@Option(name = "-der", aliases = "--dcexporter-redirect-uri",
usage = "Datacore Exporter's redirect_uri")
private String dcexporterRedirectUri;

@Option(name = "-des", aliases = "--dcexporter-service-uri",
usage = "Datacore Exporter's service_uri")
private String dcexporterServiceUri;

@Inject JongoService jongoService;
@Inject Provider<Jongo> jongoProvider;
@Inject Provider<ScopeRepository> scopeRepositoryProvider;
Expand Down Expand Up @@ -136,6 +156,10 @@ protected void configure() {
logger().info("Generated client_secret for {} instance: {}", ClientIds.PORTAL, portalSecret);
String dcSecret = createDatacore(oasisOrgId, adminAccountId);
logger().info("Generated client_secret for {} instance: {}", ClientIds.DATACORE, dcSecret);
if (!Strings.isNullOrEmpty(dcexporterRedirectUri) && !Strings.isNullOrEmpty(dcexporterServiceUri)) {
String dcExporterSecret = createDcExporter(oasisOrgId, adminAccountId);
logger().info("Generated client_secret for {} instance: {}", ClientIds.DCEXPORTER, dcExporterSecret);
}
} finally {
jongoService.stop();
}
Expand Down Expand Up @@ -308,6 +332,7 @@ private String createPortal(String oasisOrgId, String adminAccountId) {
instance.setApplication_id(app.getId());
instance.setStatus(AppInstance.InstantiationStatus.RUNNING);
instance.setInstantiator_id(adminAccountId);
instance.setProvider_id(oasisOrgId);
for (String scopeId : new String[] { Scopes.OPENID, Scopes.PROFILE, Scopes.EMAIL, Scopes.ADDRESS, Scopes.PHONE, "datacore" }) {
AppInstance.NeededScope neededScope = new AppInstance.NeededScope();
neededScope.setScope_id(scopeId);
Expand All @@ -321,6 +346,7 @@ private String createPortal(String oasisOrgId, String adminAccountId) {
Service service = new Service();
service.setLocal_id("front");
service.setInstance_id(instance.getId());
service.setProvider_id(instance.getProvider_id());
service.setVisibility(Service.Visibility.HIDDEN);
service.setAccess_control(Service.AccessControl.ANYONE);
service.setStatus(Service.Status.AVAILABLE);
Expand All @@ -345,6 +371,7 @@ private String createDatacore(String oasisOrgId, String adminAccountId) {
instance.setApplication_id(app.getId());
instance.setStatus(AppInstance.InstantiationStatus.RUNNING);
instance.setInstantiator_id(adminAccountId);
instance.setProvider_id(oasisOrgId);
jongoProvider.get().getCollection(JongoAppInstanceRepository.COLLECTION_NAME).insert(instance);

String clientSecret = passwordGeneratorProvider.get().generate();
Expand All @@ -359,8 +386,59 @@ private String createDatacore(String oasisOrgId, String adminAccountId) {
scope.getName().set(ULocale.ROOT, "Datacore");
scopeRepositoryProvider.get().createOrUpdateScope(scope);

// XXX: do we need a service?
Service service = new Service();
service.setLocal_id("playground");
service.setInstance_id(instance.getId());
service.setProvider_id(instance.getProvider_id());
service.setVisibility(Service.Visibility.HIDDEN);
service.setAccess_control(Service.AccessControl.RESTRICTED);
service.setStatus(Service.Status.AVAILABLE);
service.getName().set(ULocale.ROOT, "Ozwillo Datacore Playground");
service.getRedirect_uris().add(datacoreRedirectUri);
service.setService_uri(datacoreServiceUri);
service.getIcon().set(ULocale.ROOT, datacoreIcon);
serviceRepositoryProvider.get().createService(service);

return clientSecret;
}

private String createDcExporter(String oasisOrgId, String adminAccountId) {
Application app = new Application();
app.getName().set(ULocale.ROOT, "Ozwillo Datacore Exporter");
app.setProvider_id(oasisOrgId);
app.setVisible(false);
app = applicationRepositoryProvider.get().createApplication(app);

JongoAppInstance instance = new JongoAppInstance();
instance.setId(ClientIds.DCEXPORTER);
instance.getName().set(ULocale.ROOT, "Ozwillo Datacore Exporter");
instance.setApplication_id(app.getId());
instance.setStatus(AppInstance.InstantiationStatus.RUNNING);
instance.setInstantiator_id(adminAccountId);
instance.setProvider_id(oasisOrgId);
for (String scopeId : new String[] { Scopes.OPENID, Scopes.PROFILE, Scopes.EMAIL, "datacore" }) {
AppInstance.NeededScope neededScope = new AppInstance.NeededScope();
neededScope.setScope_id(scopeId);
instance.getNeeded_scopes().add(neededScope);
}
jongoProvider.get().getCollection(JongoAppInstanceRepository.COLLECTION_NAME).insert(instance);

String clientSecret = passwordGeneratorProvider.get().generate();
credentialsServiceProvider.get().setPassword(ClientType.PROVIDER, instance.getId(), clientSecret);

Service service = new Service();
service.setLocal_id("dcexporter");
service.setInstance_id(instance.getId());
service.setProvider_id(instance.getProvider_id());
service.setVisibility(Service.Visibility.HIDDEN);
service.setAccess_control(Service.AccessControl.RESTRICTED);
service.setStatus(Service.Status.AVAILABLE);
service.getName().set(ULocale.ROOT, "Ozwillo Datacore Exporter");
service.getRedirect_uris().add(dcexporterRedirectUri);
service.setService_uri(dcexporterServiceUri);
serviceRepositoryProvider.get().createService(service);

return clientSecret;

}
}