Search in sources :

Example 26 with ProjectId

use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.

the class PersistentJobRegistry method enqueueOperation.

@Override
public JobData enqueueOperation(Action action, ProjectAuthorization auth, PlatformLayerKey targetItem) throws OpsException {
    ProjectId projectId;
    try {
        projectId = opsContextBuilder.getRunAsProjectId(auth);
    } catch (OpsException e) {
        throw new OpsException("Error getting projectId", e);
    }
    JobData jobData = new JobData();
    jobData.action = action;
    jobData.targetId = targetItem;
    try {
        String jobId = repository.insertJob(projectId, jobData);
        jobData.key = JobData.buildKey(projectId, new ManagedItemId(jobId));
    } catch (RepositoryException e) {
        throw new OpsException("Error inserting job", e);
    }
    operationQueue.submit(auth, jobData);
    return jobData;
}
Also used : OpsException(org.platformlayer.ops.OpsException) ProjectId(org.platformlayer.ids.ProjectId) RepositoryException(org.platformlayer.RepositoryException) JobData(org.platformlayer.jobs.model.JobData) ManagedItemId(org.platformlayer.ids.ManagedItemId)

Example 27 with ProjectId

use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.

the class OpsContextBuilder method getRunAsProjectId.

public ProjectId getRunAsProjectId(ProjectAuthorization project) throws OpsException {
    // authentication.getProject();
    ProjectAuthorization runAsProject = project;
    MultitenantConfiguration multitenant = opsSystem.getMultitenantConfiguration();
    if (multitenant != null) {
        runAsProject = multitenant.getMasterProject();
    }
    ProjectId runAsProjectId = new ProjectId(runAsProject.getName());
    return runAsProjectId;
}
Also used : ProjectAuthorization(org.platformlayer.model.ProjectAuthorization) ProjectId(org.platformlayer.ids.ProjectId) MultitenantConfiguration(org.platformlayer.ops.MultitenantConfiguration)

Example 28 with ProjectId

use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.

the class ProjectContext method getProjectCredentials.

public CertificateAndKey getProjectCredentials() throws OpsException {
    // OK... this is weird... we sign the project cert with the project cert.
    // It sort of makes sense, in that we don't want to share the project signing cert outside the auth server
    ProjectId projectId = getProjectId();
    KeyPair keyPair = privateData.findKeyPair(projectId, null, METADATA_PROJECT_KEY);
    List<X509Certificate> chain = privateData.findCertificate(projectId, null, METADATA_PROJECT_CERT);
    if (keyPair == null) {
        keyPair = RsaUtils.generateRsaKeyPair();
        privateData.putKeyPair(projectId, null, METADATA_PROJECT_KEY, keyPair);
    }
    if (chain == null) {
        AuthenticationTokenValidator authenticationTokenValidator = OpsContext.get().getInjector().getInstance(AuthenticationTokenValidator.class);
        ProjectAuthorization projectAuthorization = Scope.get().get(ProjectAuthorization.class);
        String projectKey = projectAuthorization.getName();
        if (!projectKey.equals(projectId.getKey())) {
            throw new IllegalStateException();
        }
        PlatformLayerAuthAdminClient adminClient = PlatformLayerAuthAdminClient.find(authenticationTokenValidator);
        Csr csr = Csr.buildCsr(keyPair, getX500Principal());
        chain = adminClient.signCsr(projectId.getKey(), projectAuthorization.getProjectSecret(), csr.getEncoded());
        privateData.putCertificate(projectId, null, METADATA_PROJECT_CERT, chain);
    }
    return new SimpleCertificateAndKey(chain, keyPair.getPrivate());
}
Also used : KeyPair(java.security.KeyPair) SimpleCertificateAndKey(com.fathomdb.crypto.SimpleCertificateAndKey) ProjectId(org.platformlayer.ids.ProjectId) ProjectAuthorization(org.platformlayer.model.ProjectAuthorization) AuthenticationTokenValidator(org.platformlayer.auth.AuthenticationTokenValidator) PlatformLayerAuthAdminClient(org.platformlayer.auth.system.PlatformLayerAuthAdminClient) X509Certificate(java.security.cert.X509Certificate)

Example 29 with ProjectId

use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.

the class FederationMap method addDefault.

public void addDefault(TypedPlatformLayerClient defaultClient) {
    FederationKey host = FederationKey.LOCAL;
    ProjectId project = defaultClient.getProject();
    FederationMapping mapKey = new FederationMapping(host, project);
    MappedTarget target = new MappedTarget();
    target.client = defaultClient;
    addMapping(mapKey, target);
}
Also used : ProjectId(org.platformlayer.ids.ProjectId) FederationKey(org.platformlayer.ids.FederationKey)

Example 30 with ProjectId

use of org.platformlayer.ids.ProjectId in project platformlayer by platformlayer.

the class FederationMap method buildRules.

private void buildRules(FederationConfiguration config) {
    for (FederationRule federationRule : config.rules) {
        Rule rule = new Rule();
        rule.mappedItems = PlatformLayerKey.fromServiceAndItem(federationRule.serviceType, null);
        for (PlatformLayerConnectionConfiguration system : config.systems) {
            if (Objects.equal(system.key, federationRule.target)) {
                if (rule.targetKey != null) {
                    throw new IllegalStateException();
                }
                FederationKey host = FederationKey.build(system.authenticationEndpoint);
                ProjectId project = new ProjectId(system.tenant);
                rule.targetKey = new FederationMapping(host, project);
            }
        }
        if (rule.targetKey == null) {
            throw new IllegalStateException();
        }
        addRule(rule);
    }
}
Also used : FederationRule(org.platformlayer.federation.model.FederationRule) PlatformLayerConnectionConfiguration(org.platformlayer.federation.model.PlatformLayerConnectionConfiguration) ProjectId(org.platformlayer.ids.ProjectId) FederationRule(org.platformlayer.federation.model.FederationRule) FederationKey(org.platformlayer.ids.FederationKey)

Aggregations

ProjectId (org.platformlayer.ids.ProjectId)33 RepositoryException (org.platformlayer.RepositoryException)14 FederationKey (org.platformlayer.ids.FederationKey)11 PlatformLayerKey (org.platformlayer.core.model.PlatformLayerKey)10 ManagedItemId (org.platformlayer.ids.ManagedItemId)9 OpsException (org.platformlayer.ops.OpsException)8 JdbcTransaction (com.fathomdb.jdbc.JdbcTransaction)7 SQLException (java.sql.SQLException)7 ServiceType (org.platformlayer.ids.ServiceType)7 ItemType (org.platformlayer.ids.ItemType)6 ProjectAuthorization (org.platformlayer.model.ProjectAuthorization)4 PlatformLayerClient (org.platformlayer.PlatformLayerClient)3 ItemBase (org.platformlayer.core.model.ItemBase)3 JobData (org.platformlayer.jobs.model.JobData)3 TypedPlatformLayerClient (org.platformlayer.TypedPlatformLayerClient)2 Authenticator (org.platformlayer.auth.Authenticator)2 DirectAuthenticator (org.platformlayer.auth.DirectAuthenticator)2 FederatedPlatformLayerClient (org.platformlayer.federation.FederatedPlatformLayerClient)2 PlatformLayerConnectionConfiguration (org.platformlayer.federation.model.PlatformLayerConnectionConfiguration)2 DirectPlatformLayerClient (org.platformlayer.ops.DirectPlatformLayerClient)2