Using the SDK Maven modules
core module is required
<!-- core module required for configuring sdk -->
<dependency>
<groupId>com.graphgrid</groupId>
<artifactId>graphgrid-sdk-java-core</artifactId>
<version>${project.version}</version>
</dependency> client/service module should be added as needed
<dependency>
<groupId>com.graphgrid</groupId>
<artifactId>graphgrid-sdk-java-files</artifactId>
<version>${project.version}</version>
</dependency> Configuring with Spring Framework
its recommended to use a Spring Configuration Class and create client services as Spring Beans
adding the security configuration that is needed for authentication
@ConfigurationpublicclassAppGraphGridSdkConfig
{
@Value( "${spring.security.base.url}" )
privateStringspringOauthTokenUrl;
@Value( "${spring.oauth.client.id}" )
privateStringoAuthClientId;
@Value( "${spring.oauth.client.secret}" )
privateStringoAuthClientSecret;
@BeanpublicSessionFactoryggTokenSession()
{
returnnewSpringSecurityContextTokenFactory( () -> SecurityContextHolder.getContext().getAuthentication().getDetails() );
}
@BeanpublicSecurityConfigggSecurityConfig()
{
finalSecurityConfigsecurityConfig = newSecurityConfig();
securityConfig.setClientSecret( oAuthClientSecret );
securityConfig.setClientId( oAuthClientId );
securityConfig.setBaseSecurityUrl( springOauthTokenUrl );
returnsecurityConfig;
}
}SessionFactory ggTokenSession() acts as an interceptor that will automatically add the token of a REST request to the header of call made by the SDK. Although its not required its recommended to add it for monitoring purpose.
a client module can be added as follows:
@Value( "${spring.services.files.url}" )
privateStringfilesEndpoint;
@BeanpublicGraphGridFilesClientgraphGridFilesClient()
{
returnnewGraphGridFilesClient( filesEndpoint, ggSecurityConfig(), ggTokenSession() );
}the graphGridFilesClient can now be @Autowired in any spring service
@AutowiredprivateGraphGridFilesClientgraphGridFilesClient;By default all requests made with the sdk will get and reuse a token based on the security credentials the client was configured with. However its possible to overwrite those for an individual call by overwriting AuthMethod of the request.
//use a specific tokennewGraphGridServiceRequest( ).withAuthMethod( newTokenRequest( "123456-1234-1234-1234" ) ) // in case there is no auth required or for testing purposenewGraphGridServiceRequest( ).withAuthMethod( newNoTokenRequest() )