Search in sources :

Example 1 with SymphonyIdentity

use of com.symphony.api.id.SymphonyIdentity in project spring-bot by finos.

the class BasicAppIdentityProvider method getIdentity.

public SymphonyIdentity getIdentity() throws Exception {
    SymphonyIdentity out = null;
    IdentityProperties identity = p.getIdentity();
    String appId = getAppId(p);
    if (identity != null) {
        out = performIdentityLoad(identity, appId);
    }
    if (out == null) {
        out = performIdentityLoad(getClasspathResourceLocation(appId), appId);
    }
    if (out == null) {
        out = performIdentityLoad(getFileResourceLocation(appId), appId);
    }
    if (out == null) {
        throw new IdentityConfigurationException("Couldn't load app identity", null);
    }
    return out;
}
Also used : SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) IdentityConfigurationException(com.symphony.api.id.IdentityConfigurationException) IdentityProperties(org.finos.symphony.toolkit.spring.api.properties.IdentityProperties)

Example 2 with SymphonyIdentity

use of com.symphony.api.id.SymphonyIdentity in project spring-bot by finos.

the class GeneratingAppIdentityProvider method performIdentityLoad.

/**
 * Augments the identity process by generating a new self-signed certificate
 * and storing it in the application directory.
 *
 * Note - terrible idea if running with multiple instances and not sharing the f/s.
 */
@Override
protected SymphonyIdentity performIdentityLoad(IdentityProperties identity, String appId) throws Exception {
    SymphonyIdentity out = super.performIdentityLoad(identity, appId);
    if (out == null) {
        String location = identity.getLocation();
        Resource r = loader.getResource(location);
        if (r.isFile()) {
            LOG.info("Creating a new identity in {}, since one couldn't be loaded", location);
            KeyPair keyPair = certTools.createKeyPair();
            X509Certificate cert = certTools.createSelfSignedCertificate(appId, keyPair);
            out = new SingleSymphonyIdentity((RSAPrivateCrtKey) keyPair.getPrivate(), null, new X509Certificate[] { cert }, appId);
            OutputStream os = new FileOutputStream(r.getFile());
            om.writeValue(os, out);
            os.close();
        } else {
        }
    }
    return out;
}
Also used : SingleSymphonyIdentity(com.symphony.api.id.SingleSymphonyIdentity) KeyPair(java.security.KeyPair) RSAPrivateCrtKey(java.security.interfaces.RSAPrivateCrtKey) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Resource(org.springframework.core.io.Resource) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) SingleSymphonyIdentity(com.symphony.api.id.SingleSymphonyIdentity) X509Certificate(java.security.cert.X509Certificate)

Example 3 with SymphonyIdentity

use of com.symphony.api.id.SymphonyIdentity in project spring-bot by finos.

the class SymphonyAppConfig method appIdentity.

@Bean(name = APP_IDENTITY_BEAN)
@ConditionalOnMissingBean(name = APP_IDENTITY_BEAN)
public SymphonyIdentity appIdentity() throws Exception {
    GeneratingAppIdentityProvider provider = new GeneratingAppIdentityProvider(appProperties(), loader, objectMapper);
    SymphonyIdentity out = provider.getIdentity();
    return out;
}
Also used : SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) GeneratingAppIdentityProvider(org.finos.symphony.toolkit.spring.app.id.GeneratingAppIdentityProvider) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with SymphonyIdentity

use of com.symphony.api.id.SymphonyIdentity in project spring-bot by finos.

the class JWTHelperIT method testWithSuppliedId.

@Test
public void testWithSuppliedId() throws Exception {
    SymphonyIdentity id = TestIdentityProvider.getIdentity("symphony-develop-bot1-identity");
    long future = 1562389592;
    String jwt = JWTHelper.createSignedJwt("supercomputa", future, id.getPrivateKey());
    String[] parts = jwt.split("\\.");
    verifySignature(id.getPublicKey(), parts);
    Assertions.assertEquals("{\"alg\":\"RS512\"}{\"sub\":\"supercomputa\",\"exp\":1562389592}", JWTHelper.decodeJwt(jwt));
}
Also used : SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) Test(org.junit.jupiter.api.Test)

Example 5 with SymphonyIdentity

use of com.symphony.api.id.SymphonyIdentity in project spring-bot by finos.

the class SymphonyApiConfig method botIdentity.

@Bean(name = SINGLE_BOT_IDENTITY_BEAN)
@ConditionalOnMissingBean
@ConditionalOnExpression("'${" + SINGLE_BOT_IDENTITY_PROPERTY + ".email:}${" + SINGLE_BOT_IDENTITY_PROPERTY + ".location:}' != ''")
public SymphonyIdentity botIdentity() throws IOException {
    LOG.warn("Loading identity from " + SINGLE_BOT_IDENTITY_PROPERTY);
    SymphonyIdentity id = IdentityProperties.instantiateIdentityFromDetails(resourceLoader, identityDetails(), mapper);
    if (id == null) {
        throw new IdentityConfigurationException("Couldn't create bot identity from properties", null);
    }
    return id;
}
Also used : SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) IdentityConfigurationException(com.symphony.api.id.IdentityConfigurationException) ConditionalOnExpression(org.springframework.boot.autoconfigure.condition.ConditionalOnExpression) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

SymphonyIdentity (com.symphony.api.id.SymphonyIdentity)12 IdentityConfigurationException (com.symphony.api.id.IdentityConfigurationException)2 AuthenticationApi (com.symphony.api.login.AuthenticationApi)2 AuthenticateRequest (com.symphony.api.model.AuthenticateRequest)2 Token (com.symphony.api.model.Token)2 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 ApiInstance (org.finos.symphony.toolkit.spring.api.factories.ApiInstance)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)2 Bean (org.springframework.context.annotation.Bean)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ApiBuilder (com.symphony.api.bindings.ApiBuilder)1 ConfigurableApiBuilder (com.symphony.api.bindings.ConfigurableApiBuilder)1 CXFApiBuilder (com.symphony.api.bindings.cxf.CXFApiBuilder)1 P12SymphonyIdentity (com.symphony.api.id.P12SymphonyIdentity)1 PemSymphonyIdentity (com.symphony.api.id.PemSymphonyIdentity)1 SingleSymphonyIdentity (com.symphony.api.id.SingleSymphonyIdentity)1