Configuring REST Client for Spring
This tutorial shows the way internet banking (or other similar application) developers integrate with PowerAuth Server using a REST client.
Prerequisites For the Tutorial
- Running PowerAuth Server with available REST interface.
- Knowledge of web applications based on Spring Framework.
- Software: IDE, Application Server (Tomcat, Wildfly…)
Integration Manual
Add a Maven Dependency
To add a PowerAuth REST client support in your application, add Maven dependency for PowerAuth REST client module in your pom.xml
file:
<dependency>
<groupId>io.getlime.security</groupId>
<artifactId>powerauth-rest-client-spring</artifactId>
<version>${powerauth.version}</version>
</dependency>
Configure PowerAuth REST Client
In order to connect to the correct PowerAuth Server, you need to add following configuration:
@Configuration
@ComponentScan(basePackages = {"com.wultra.security.powerauth"})
public class PowerAuthClientConfiguration {
@Value("${powerauth.rest.url}")
private String powerAuthRestUrl;
@Bean
public PowerAuthClient powerAuthRestClient() {
return new PowerAuthRestClient(powerAuthRestUrl);
}
}
In case you need to configure the client, use:
@Bean
public PowerAuthRestClient powerAuthRestClient() {
PowerAuthRestClientConfiguration config = new PowerAuthRestClientConfiguration();
config.setConnectTimeout(3000);
...
return new PowerAuthRestClient(powerAuthRestUrl, config);
}
The following REST client options are available:
maxMemorySize
- configures maximum memory size per request, default 1 MBconnectTimeout
- configures connection timeout, default 5000 msproxyEnabled
- enables proxy, disabled by defaultproxyHost
- proxy hostname or IP addressproxyPort
- proxy server portproxyUsername
- proxy username in case proxy authentication is requiredproxyPassword
- proxy password in case proxy authentication is requiredpowerAuthClientToken
- client token for PowerAuth server authentication, used in case authentication is enabled on PowerAuth serverpowerAuthClientSecret
- client secret for PowerAuth server authentication, used in case authentication is enabled on PowerAuth serveracceptInvalidSslCertificate
- whether SSL certificates should be validated, used during development
Using the PowerAuth REST Client
In order to use a PowerAuthServiceClient
instance, you can easily @Autowire
it in your class, for example in your Spring MVC @Controller
, like this:
@Controller
@RequestMapping(value = "ib/settings")
public class AuthenticationController {
@Autowired
public void setPowerAuthClient(PowerAuthClient powerAuthClient) {
this.powerAuthClient = powerAuthClient;
}
}
Last updated on May 11, 2021 (16:44)
Edit on Github
Send Feedback