Search in sources :

Example 6 with SymphonyIdentity

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

the class RSAAuthIT method testKeyManagerAuthWithRSA.

@ParameterizedTest
@MethodSource("setupConfigurations")
public void testKeyManagerAuthWithRSA(TestClientStrategy s) throws Exception {
    SymphonyIdentity id = s.getIdentity();
    String jwt = JWTHelper.createSignedJwt(id.getCommonName(), id.getPrivateKey());
    AuthenticationApi keyApi = s.getRSAKeyAuthApi();
    AuthenticateRequest req = new AuthenticateRequest();
    req.setToken(jwt);
    Token done = keyApi.pubkeyAuthenticatePost(req);
    System.out.println(done);
}
Also used : AuthenticationApi(com.symphony.api.login.AuthenticationApi) AuthenticateRequest(com.symphony.api.model.AuthenticateRequest) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) Token(com.symphony.api.model.Token) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with SymphonyIdentity

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

the class RSAAuthIT method testSessionAuthWithRSA.

@ParameterizedTest
@MethodSource("setupConfigurations")
public void testSessionAuthWithRSA(TestClientStrategy s) throws Exception {
    SymphonyIdentity id = s.getIdentity();
    String jwt = JWTHelper.createSignedJwt(id.getCommonName(), id.getPrivateKey());
    System.out.println(jwt);
    System.out.println(JWTHelper.decodeJwt(jwt));
    AuthenticationApi sessionApi = s.getRSASessionAuthApi();
    AuthenticateRequest req = new AuthenticateRequest();
    req.setToken(jwt);
    Token done = sessionApi.pubkeyAuthenticatePost(req);
    System.out.println(done);
}
Also used : AuthenticationApi(com.symphony.api.login.AuthenticationApi) AuthenticateRequest(com.symphony.api.model.AuthenticateRequest) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) Token(com.symphony.api.model.Token) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 8 with SymphonyIdentity

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

the class IdentityProperties method instantiateIdentityFromDetails.

@SuppressWarnings("deprecation")
public static SymphonyIdentity instantiateIdentityFromDetails(ResourceLoader loader, IdentityProperties details, ObjectMapper om) throws IOException {
    if (!StringUtils.isEmpty(details.getLocation())) {
        Resource r = loader.getResource(details.getLocation());
        boolean pkcs12 = (details.getType() == Type.PKCS12) || (details.getType() == null) && (details.getLocation().endsWith("p12"));
        boolean json = (details.getType() == Type.JSON) || (details.getType() == null) && (details.getLocation().endsWith("json"));
        if (r.isReadable()) {
            if (pkcs12) {
                P12SymphonyIdentity id = new P12SymphonyIdentity(r.getInputStream(), details.getPassword(), details.getEmail());
                return id;
            } else if (json) {
                SymphonyIdentity id = om.readValue(r.getInputStream(), SymphonyIdentity.class);
                return id;
            }
        }
    }
    if (!StringUtils.isEmpty(details.getPrivateKey())) {
        if ((details.getCertificates() != null) && (details.getCertificates().size() > 0)) {
            String[] certs = (String[]) details.getCertificates().toArray(new String[details.getCertificates().size()]);
            PemSymphonyIdentity id = new PemSymphonyIdentity(details.getPrivateKey(), certs, details.getEmail());
            return id;
        } else {
            PemSymphonyIdentity id = new PemSymphonyIdentity(details.getPrivateKey(), details.getCommonName(), details.getEmail());
            return id;
        }
    }
    return null;
}
Also used : PemSymphonyIdentity(com.symphony.api.id.PemSymphonyIdentity) P12SymphonyIdentity(com.symphony.api.id.P12SymphonyIdentity) Resource(org.springframework.core.io.Resource) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) PemSymphonyIdentity(com.symphony.api.id.PemSymphonyIdentity) P12SymphonyIdentity(com.symphony.api.id.P12SymphonyIdentity)

Example 9 with SymphonyIdentity

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

the class SymphonyAdminController method getAPI.

protected <X> X getAPI(Class<X> x) throws IOException, Exception {
    Config config = getConfig();
    SymphonyIdentity identity = IdentityProperties.instantiateIdentityFromDetails(rl, config.getIdentityProperties(), getObjectMapper());
    ApiBuilderFactory abf = new ApiBuilderFactory() {

        @Override
        public boolean isSingleton() {
            return false;
        }

        @Override
        public Class<?> getObjectType() {
            return ApiBuilder.class;
        }

        @Override
        public ConfigurableApiBuilder getObject() throws Exception {
            return new CXFApiBuilder();
        }
    };
    ApiInstanceFactory apiInstanceFactory = new TokenManagingApiInstanceFactory(abf);
    ApiInstance instance = apiInstanceFactory.createApiInstance(identity, config.getPodProperties(), null);
    X out = instance.getAgentApi(x);
    return out;
}
Also used : CXFApiBuilder(com.symphony.api.bindings.cxf.CXFApiBuilder) TokenManagingApiInstanceFactory(org.finos.symphony.toolkit.spring.api.factories.TokenManagingApiInstanceFactory) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) ApiInstance(org.finos.symphony.toolkit.spring.api.factories.ApiInstance) ApiBuilderFactory(org.finos.symphony.toolkit.spring.api.builders.ApiBuilderFactory) ApiInstanceFactory(org.finos.symphony.toolkit.spring.api.factories.ApiInstanceFactory) TokenManagingApiInstanceFactory(org.finos.symphony.toolkit.spring.api.factories.TokenManagingApiInstanceFactory) CXFApiBuilder(com.symphony.api.bindings.cxf.CXFApiBuilder) ApiBuilder(com.symphony.api.bindings.ApiBuilder) ConfigurableApiBuilder(com.symphony.api.bindings.ConfigurableApiBuilder)

Example 10 with SymphonyIdentity

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

the class SymphonyMessageSenderIT method testSymphonyMessageSender.

@Test
public void testSymphonyMessageSender() throws IOException {
    SymphonyIdentity id = TestIdentityProvider.getTestIdentity();
    ProxyingWrapper pod = new ProxyingWrapper(null, Collections.singletonList(null), POD_URL, id, LOGGER);
    ProxyingWrapper agent = new ProxyingWrapper(null, Collections.singletonList(null), AGENT_URL, id, LOGGER);
    ProxyingWrapper relay = new ProxyingWrapper(null, Collections.singletonList(null), RELAY_URL, id, LOGGER);
    ProxyingWrapper login = new ProxyingWrapper(null, Collections.singletonList(null), LOGIN_URL, id, LOGGER);
    SymphonyMessageSender sms = new SymphonyMessageSender(pod, agent, null, null, relay, login, id);
    Map<String, Object> data = new HashMap<String, Object>();
    Developer d = new Developer();
    d.setName("John Johnson");
    d.setEmail("john@example.com");
    data.put("projects", Collections.emptyList());
    data.put("exceptions", Collections.emptyList());
    data.put("developers", Collections.singletonList(d));
    data.put("title", "Some Test Project");
    data.put("date", new Date());
    data.put("passed", true);
    data.put("url", "https://github.com/finos/symphony-java-toolkit");
    data.put("recipients", Collections.singletonList("y3EJYqKMwG7Jn7/YqyYdiX///pR3YrnTdA=="));
    data.put("hashtags", Collections.singletonList("some-hash-tag"));
    data.put("version", "1.0");
    data.put("type", "org.finos.symphony.toolkit.maven-event");
    sms.sendMessage(Collections.singletonMap("event", data));
}
Also used : HashMap(java.util.HashMap) SymphonyIdentity(com.symphony.api.id.SymphonyIdentity) Developer(org.apache.maven.model.Developer) ProxyingWrapper(org.finos.symphony.toolkit.maven.ProxyingWrapper) SymphonyMessageSender(org.finos.symphony.toolkit.maven.SymphonyMessageSender) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

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