All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.smartcosmos.extension.stormpath.util.StormpathInitializer Maven / Gradle / Ivy

The newest version!
package net.smartcosmos.extension.stormpath.util;

import com.stormpath.sdk.api.ApiKey;
import com.stormpath.sdk.api.ApiKeys;
import com.stormpath.sdk.application.Application;
import com.stormpath.sdk.application.ApplicationList;
import com.stormpath.sdk.application.Applications;
import com.stormpath.sdk.client.Client;
import com.stormpath.sdk.client.Clients;
import com.stormpath.sdk.tenant.Tenant;

import net.smartcosmos.extension.stormpath.config.StormpathProperties;

public class StormpathInitializer {

    public static ApiKey getApiKeyFromProperties(StormpathProperties.ApiKey apiKeyProperties) {

        return ApiKeys.builder()
            .setId(apiKeyProperties.getId())
            .setSecret(apiKeyProperties.getSecret())
            .build();
    }

    public static Client getClientFromProperties(StormpathProperties.ApiKey apiKeyProperties) {

        ApiKey apiKey = getApiKeyFromProperties(apiKeyProperties);

        return Clients.builder()
            .setApiKey(apiKey)
            .build();
    }

    public static Application getSingleApplication(Tenant tenant, String applicationName) {

        ApplicationList applications = tenant.getApplications(
            Applications.where(Applications.name()
                                   .eqIgnoreCase(applicationName)));

        return applications.single();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy