diff --git a/README.md b/README.md index 13785b80..9ddb0888 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ and other changes required for customizing Web Flow for clients. ## Documentation -Visit our wiki for [technical details about PowerAuth 2.0 Web Flow](https://github.com/lime-company/powerauth-webflow/wiki). +For the most recent documentation and tutorials, please visit [PowerAuth Web Flow Customization Documentation](./docs/Home.md). ## License diff --git a/docs/Customizing-Web-Flow-Appearance.md b/docs/Customizing-Web-Flow-Appearance.md new file mode 100644 index 00000000..1074452e --- /dev/null +++ b/docs/Customizing-Web-Flow-Appearance.md @@ -0,0 +1,60 @@ +# Customizing PowerAuth Web Flow Appearance + +Web Flow resources which can be customized are available in the ext-resources folder: + +- [ext-resources](../ext-resources) + +## Overriding Default Web Flow Resource Location + +The general process of updating Web Flow resources: + +- Clone project [powerauth-webflow-customization](https://github.com/wultra/powerauth-webflow-customization) from GitHub. +- Update Web Flow resources by overriding existing texts, CSS, fonts and images or by adding additional resources. +- When deploying Web Flow, configure the following Spring Boot property: + +```properties +powerauth.webflow.page.ext-resources.location=classpath:/static/resources/ +``` + +For example, if you placed the Web Flow customization files to `/opt/webflow/ext-resources`, set the property to: + +```properties +powerauth.webflow.page.ext-resources.location=file:/opt/webflow/ext-resources +``` + +See the documentation of your container for configuration of properties. + +## Customizing Web Flow Texts + +Web Flow texts are stored in `ext-resources/message_[lang].properties` files, see: + +- [ext-resources/messages_en.properties](../ext-resources/messages_en.properties) + +- [ext-resources/messages_cs.properties](../ext-resources/messages_cs.properties) + +After you make a copy of the `powerauth-webflow-customization` project, you can update the texts and deploy changes to the folder `/path/to/your/ext-resources`. + +## Customizing Web Flow CSS Styles + +Web Flow CSS files are stored in `ext-resources/css` folder, see: + +- [ext-resources/css](../ext-resources/css) + +After you make a copy of the `powerauth-webflow-customization` project, you can update the CSS and deploy changes to the folder `/path/to/your/ext-resources/css`. Make sure to only edit the `customization.css` file. We may change CSS in `base.css` file at any time and you would have to migrate the changes we made to your customization. + +## Customizing Web Flow Images + +Web Flow images are stored in `ext-resources/images` folder, see: + +- [ext-resources/images](../ext-resources/images) + +After you make a copy of the `powerauth-webflow-customization` project, you can update the images and deploy changes to the folder `/path/to/your/ext-resources/css`. + +You can also add new images and configure these images in overridden CSS files. + +## Customizing Web Flow Fonts + +Additional fonts for Web Flow can be stored in `ext-resources/fonts` folder, see: +- [ext-resources/fonts](../ext-resources/fonts) + +After you make a copy of the `powerauth-webflow-customization` project, you can add new fonts to the folder `/path/to/your/ext-resources/fonts` and update the `customization.css` file (see above) to use the added fonts in Web Flow. diff --git a/docs/Home.md b/docs/Home.md new file mode 100644 index 00000000..2dac7e32 --- /dev/null +++ b/docs/Home.md @@ -0,0 +1,10 @@ +# PowerAuth Web Flow Customization + +The purpose of this project is to provide client specific customization, such as adapting to client backend APIs, CSS customization, updated texts, images, fonts and other changes required for customizing Web Flow for clients. + +Web Flow can be customized in following areas: + +- Appearance (texts, CSS, fonts and images) - chapter [Customizing Web Flow Appearance](./Customizing-Web-Flow-Appearance.md) +- Integration with clients backends - chapter [Implementing the Data Adapter Interface](./Implementing-the-Data-Adapter-Interface.md) + +Data Adapter is integrated with Web Flow using REST API. For documentation see: [Data Adapter REST API Reference](https://github.com/wultra/powerauth-webflow/blob/develop/docs/Data-Adapter-REST-API-Reference.md) \ No newline at end of file diff --git a/docs/Implementing-the-Data-Adapter-Interface.md b/docs/Implementing-the-Data-Adapter-Interface.md new file mode 100644 index 00000000..40a61835 --- /dev/null +++ b/docs/Implementing-the-Data-Adapter-Interface.md @@ -0,0 +1,42 @@ +# Implementing the Data Adapter Interface + +Data Adapter is used for connecting Web Flow to client backend systems. It allows to interact with backends for user authentication, SMS authorization, read additional data required for the operation as well as notify client backend about operation changes. + +## DataAdapter Interface + +The interface methods are defined in the [DataAdapter interface](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java): + +- [authenticateUser](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L43) - perform user authentication with remote backend based on provided credentials +- [fetchUserDetail](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L52) - retrieve user details for given user ID +- [decorateFormData](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L62) - retrieve operation form data and decorate it +- [formDataChangedNotification](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L71) - method is called when operation form data changes to allow notification of client backends +- [operationChangedNotification](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L80) - method is called when operation status changes to allow notification of client backends +- [generateAuthorizationCode](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L89) - generate authorization code for authorization SMS message +- [generateSMSText](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L100) - generate SMS text for authorization SMS message +- [sendAuthorizationSMS](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L110) - send authorization SMS message + +## Customizing Data Adapter + +Following steps are required for customization of Data Adapter. + +### 1. Implement Interface Methods + +Consider which of the following methods need to be implemented in your project: + + - [authenticateUser](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L43) (optional) - implementation is required in case any Web Flow operation needs to authenticate the user using a username/password login form + - [fetchUserDetail](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L52) (required) - provides information about the user (user ID and name) for the OAuth 2.0 protocol + - [decorateFormData](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L62) (optional) - implementation is required in case any Web Flow operation form data needs to be updated after authentication (e.g. add information about user bank accounts) + - [formDataChangedNotification](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L71) (optional) - implementation is required in case the client backends need to be notified about user input during an operation + - [operationChangedNotification](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L80) (optional) - implementation is required in case the client backends need to be notified about operation status changes + - [generateAuthorizationCode](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L89) (optional) - implementation is required in case any Web Flow operation needs to authorize the user using SMS authorization + - [generateSMSText](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L100) (optional) - implementation is required in case any Web Flow operation needs to authorize the user using SMS authorization + - [sendAuthorizationSMS](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java#L110) (optional) - implementation is required in case any Web Flow operation needs to authorize the user using SMS authorization + +### 2. Implement the `DataAdapter` Interface + +Implement the actual changes in Data Adapter so that it connects to an actual data source. + + - Clone project [powerauth-webflow-customization](https://github.com/wultra/powerauth-webflow-customization) from GitHub. + - Update the `pom.xml` to add any required additional dependencies. + - Create a proprietary client (+ client config) for your web services. + - Implement the Data Adapter interface by providing your own implementation in the [DataAdapterService class](../powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/DataAdapterService.java). You can override the sample implementation. diff --git a/docs/_Sidebar.md b/docs/_Sidebar.md new file mode 100644 index 00000000..f1fc987e --- /dev/null +++ b/docs/_Sidebar.md @@ -0,0 +1,6 @@ +**Customizing Web Flow** + +- [Home](./Home.md) +- [Customizing Web Flow Appearance](./Customizing-Web-Flow-Appearance.md) +- [Implementing Data Adapter Interface](./Implementing-the-Data-Adapter-Interface.md) +- [Data Adapter REST API Reference](https://github.com/wultra/powerauth-webflow/blob/develop/docs/Data-Adapter-REST-API-Reference.md) \ No newline at end of file diff --git a/powerauth-data-adapter/pom.xml b/powerauth-data-adapter/pom.xml index 5192f0b6..e6851e67 100644 --- a/powerauth-data-adapter/pom.xml +++ b/powerauth-data-adapter/pom.xml @@ -5,7 +5,7 @@ powerauth-data-adapter io.getlime.security - 0.20.0 + 0.21.0 war powerauth-data-adapter @@ -14,7 +14,7 @@ org.springframework.boot spring-boot-starter-parent - 2.0.4.RELEASE + 2.0.8.RELEASE @@ -22,8 +22,8 @@ http://powerauth.com/ - Lime - HighTech Solutions Inc. - http://getlime.io/ + Wultra s.r.o. + http://wultra.com @@ -36,14 +36,14 @@ Petr Dvorak - petr@lime-company.eu + petr@wultra.com developer Roman Strobl - roman.strobl@lime-company.eu + roman.strobl@wultra.com developer @@ -51,14 +51,14 @@ - scm:git:https://github.com/lime-company/powerauth-webflow-customization.git - scm:git:https://github.com/lime-company/powerauth-webflow-customization.git - https://github.com/lime-company/powerauth-webflow-customization + scm:git:https://github.com/wultra/powerauth-webflow-customization.git + scm:git:https://github.com/wultra/powerauth-webflow-customization.git + https://github.com/wultra/powerauth-webflow-customization Github - https://github.com/lime-company/powerauth-webflow-customization/issues + https://github.com/wultra/powerauth-webflow-customization/issues @@ -89,19 +89,19 @@ io.getlime.security powerauth-data-adapter-model - 0.20.0 + 0.21.0 io.getlime.security powerauth-java-crypto - 0.19.0 + 0.21.0 com.fasterxml.jackson.datatype jackson-datatype-joda - 2.9.4 + 2.9.8 org.bouncycastle @@ -113,12 +113,12 @@ io.springfox springfox-swagger2 - 2.8.0 + 2.9.2 io.springfox springfox-swagger-ui - 2.8.0 + 2.9.2 diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/DataAdapterApplication.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/DataAdapterApplication.java index e997ba78..c3d0672c 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/DataAdapterApplication.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/DataAdapterApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ /** * Spring Boot application main class. - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @SpringBootApplication public class DataAdapterApplication { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/ServletInitializer.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/ServletInitializer.java index da8acb83..198798f4 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/ServletInitializer.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/ServletInitializer.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ /** * Spring Boot servlet initializer. - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ public class ServletInitializer extends SpringBootServletInitializer { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java index 3236acf0..93df7943 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/api/DataAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ /** * Interface defines methods which should be implemented for integration of Web Flow with 3rd parties. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ public interface DataAdapter { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/DataAdapterConfiguration.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/DataAdapterConfiguration.java index 10b71ec6..1bc370fc 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/DataAdapterConfiguration.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/DataAdapterConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ /** * Configuration of Data Adapter. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Configuration @ComponentScan(basePackages = {"io.getlime.security.powerauth"}) diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/SwaggerConfiguration.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/SwaggerConfiguration.java index 2aba7a19..af68471e 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/SwaggerConfiguration.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/SwaggerConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ /** * Configuration class used for setting up Swagger documentation. * - * @author Petr Dvorak, petr@lime-company.eu + * @author Petr Dvorak, petr@wultra.com */ @Configuration @EnableSwagger2 diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/WebApplicationConfig.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/WebApplicationConfig.java index 35adc598..6c297588 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/WebApplicationConfig.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/configuration/WebApplicationConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,23 +16,23 @@ package io.getlime.security.powerauth.app.dataadapter.configuration; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.util.ISO8601DateFormat; +import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.joda.JodaModule; import org.springframework.context.annotation.Configuration; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.Jackson2ObjectMapperFactoryBean; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import java.util.List; /** * Default Web Application Configuration. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Configuration -public class WebApplicationConfig extends WebMvcConfigurerAdapter { +public class WebApplicationConfig implements WebMvcConfigurer { /** * Custom object mapper to make sure that dates and other values serialize @@ -43,10 +43,11 @@ public class WebApplicationConfig extends WebMvcConfigurerAdapter { private ObjectMapper objectMapper() { Jackson2ObjectMapperFactoryBean bean = new Jackson2ObjectMapperFactoryBean(); bean.setIndentOutput(true); - bean.setDateFormat(new ISO8601DateFormat()); bean.afterPropertiesSet(); ObjectMapper objectMapper = bean.getObject(); objectMapper.registerModule(new JodaModule()); + // replacement for ISO8601DateFormat which is deprecated + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); return objectMapper; } @@ -67,7 +68,6 @@ private MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter( @Override public void configureMessageConverters(List> converters) { converters.add(mappingJackson2HttpMessageConverter()); - super.configureMessageConverters(converters); } } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/AuthenticationController.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/AuthenticationController.java index 8e863894..0cc74641 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/AuthenticationController.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/AuthenticationController.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,6 +27,8 @@ import io.getlime.security.powerauth.lib.dataadapter.model.request.UserDetailRequest; import io.getlime.security.powerauth.lib.dataadapter.model.response.AuthenticationResponse; import io.getlime.security.powerauth.lib.dataadapter.model.response.UserDetailResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.MethodParameter; import org.springframework.stereotype.Controller; @@ -36,18 +38,19 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.lang.invoke.MethodHandles; /** * Controller class which handles user authentication. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Controller @RequestMapping("/api/auth/user") public class AuthenticationController { + private static final Logger logger = LoggerFactory.getLogger(AuthenticationController.class); + private final AuthenticationRequestValidator requestValidator; private final DataAdapter dataAdapter; @@ -84,19 +87,19 @@ private void initBinder(WebDataBinder binder) { @RequestMapping(value = "/authenticate", method = RequestMethod.POST) public @ResponseBody ObjectResponse authenticate(@Valid @RequestBody ObjectRequest request, BindingResult result) throws MethodArgumentNotValidException, DataAdapterRemoteException, AuthenticationFailedException { if (result.hasErrors()) { - // getEnclosingMethod() on new object returns a reference to current method - MethodParameter methodParam = new MethodParameter(new Object(){}.getClass().getEnclosingMethod(),0); - Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "The authenticate request failed due to validation errors"); + // Call of getEnclosingMethod() on class found using MethodHandles.lookup() returns a reference to current method + MethodParameter methodParam = new MethodParameter(MethodHandles.lookup().lookupClass().getEnclosingMethod(),0); + logger.warn("The authenticate request failed due to validation errors"); throw new MethodArgumentNotValidException(methodParam, result); } - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received authenticate request, username: {0}, operation ID: {1}", new String[]{request.getRequestObject().getUsername(), request.getRequestObject().getOperationContext().getId()}); + logger.info("Received authenticate request, username: {}, operation ID: {}", new String[]{request.getRequestObject().getUsername(), request.getRequestObject().getOperationContext().getId()}); AuthenticationRequest authenticationRequest = request.getRequestObject(); String username = authenticationRequest.getUsername(); String password = authenticationRequest.getPassword(); OperationContext operationContext = authenticationRequest.getOperationContext(); UserDetailResponse userDetailResponse = dataAdapter.authenticateUser(username, password, operationContext); AuthenticationResponse response = new AuthenticationResponse(userDetailResponse.getId()); - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "The authenticate request succeeded, user ID: {0}, operation ID: {1}", new String[]{request.getRequestObject().getUsername(), request.getRequestObject().getOperationContext().getId()}); + logger.info("The authenticate request succeeded, user ID: {}, operation ID: {}", new String[]{request.getRequestObject().getUsername(), request.getRequestObject().getOperationContext().getId()}); return new ObjectResponse<>(response); } @@ -110,11 +113,11 @@ private void initBinder(WebDataBinder binder) { */ @RequestMapping(value = "/info", method = RequestMethod.POST) public @ResponseBody ObjectResponse fetchUserDetail(@RequestBody ObjectRequest request) throws DataAdapterRemoteException, UserNotFoundException { - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received fetchUserDetail request, user ID: {0}", request.getRequestObject().getId()); + logger.info("Received fetchUserDetail request, user ID: {}", request.getRequestObject().getId()); UserDetailRequest userDetailRequest = request.getRequestObject(); String userId = userDetailRequest.getId(); UserDetailResponse response = dataAdapter.fetchUserDetail(userId); - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "The fetchUserDetail request succeeded"); + logger.info("The fetchUserDetail request succeeded"); return new ObjectResponse<>(response); } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/FormDataChangeController.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/FormDataChangeController.java index 647ad0ee..f6eb916a 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/FormDataChangeController.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/FormDataChangeController.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,8 @@ import io.getlime.security.powerauth.lib.dataadapter.model.request.DecorateOperationFormDataRequest; import io.getlime.security.powerauth.lib.dataadapter.model.request.FormDataChangeNotificationRequest; import io.getlime.security.powerauth.lib.dataadapter.model.response.DecorateOperationFormDataResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; @@ -33,18 +35,17 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * Controller class which handles notifications about changes of operation form data. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Controller @RequestMapping("/api/operation/formdata") public class FormDataChangeController { + private static final Logger logger = LoggerFactory.getLogger(FormDataChangeController.class); + private DataAdapter dataAdapter; /** @@ -65,14 +66,14 @@ public FormDataChangeController(DataAdapter dataAdapter) { */ @RequestMapping(value = "/change", method = RequestMethod.POST) public @ResponseBody Response formDataChangedNotification(@RequestBody ObjectRequest request) throws DataAdapterRemoteException { - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received formDataChangedNotification request for user: {0}, operation ID: {1}", + logger.info("Received formDataChangedNotification request for user: {}, operation ID: {}", new String[]{request.getRequestObject().getUserId(), request.getRequestObject().getOperationContext().getId()}); FormDataChangeNotificationRequest notification = request.getRequestObject(); String userId = notification.getUserId(); OperationContext operationContext = notification.getOperationContext(); FormDataChange formDataChange = notification.getFormDataChange(); dataAdapter.formDataChangedNotification(userId, formDataChange, operationContext); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "The formDataChangedNotification request succeeded"); + logger.debug("The formDataChangedNotification request succeeded"); return new Response(); } @@ -86,13 +87,13 @@ public FormDataChangeController(DataAdapter dataAdapter) { */ @RequestMapping(value = "/decorate", method = RequestMethod.POST) public @ResponseBody ObjectResponse decorateOperationFormData(@RequestBody ObjectRequest request) throws DataAdapterRemoteException, UserNotFoundException { - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received decorateOperationFormData request for user: {0}, operation ID: {1}", + logger.info("Received decorateOperationFormData request for user: {}, operation ID: {}", new String[]{request.getRequestObject().getUserId(), request.getRequestObject().getOperationContext().getId()}); DecorateOperationFormDataRequest requestObject = request.getRequestObject(); String userId = requestObject.getUserId(); OperationContext operationContext = requestObject.getOperationContext(); DecorateOperationFormDataResponse response = dataAdapter.decorateFormData(userId, operationContext); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "The decorateOperationFormData request succeeded"); + logger.debug("The decorateOperationFormData request succeeded"); return new ObjectResponse<>(response); } } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/OperationChangeController.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/OperationChangeController.java index ed6bf296..dad27586 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/OperationChangeController.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/OperationChangeController.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ import io.getlime.security.powerauth.lib.dataadapter.model.entity.OperationChange; import io.getlime.security.powerauth.lib.dataadapter.model.entity.OperationContext; import io.getlime.security.powerauth.lib.dataadapter.model.request.OperationChangeNotificationRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestBody; @@ -29,18 +31,17 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; -import java.util.logging.Level; -import java.util.logging.Logger; - /** * Controller class which handles notifications about changes of operation state. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Controller @RequestMapping("/api/operation") public class OperationChangeController { + private static final Logger logger = LoggerFactory.getLogger(OperationChangeController.class); + private DataAdapter dataAdapter; /** @@ -61,14 +62,14 @@ public OperationChangeController(DataAdapter dataAdapter) { */ @RequestMapping(value = "/change", method = RequestMethod.POST) public @ResponseBody Response operationChangedNotification(@RequestBody ObjectRequest request) throws DataAdapterRemoteException { - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received operationChangedNotification request for user: {0}, operation ID: {1}", + logger.info("Received operationChangedNotification request for user: {}, operation ID: {}", new String[]{request.getRequestObject().getUserId(), request.getRequestObject().getOperationContext().getId()}); OperationChangeNotificationRequest notification = request.getRequestObject(); String userId = notification.getUserId(); OperationContext operationContext = notification.getOperationContext(); OperationChange operationChange = notification.getOperationChange(); dataAdapter.operationChangedNotification(userId, operationChange, operationContext); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "The operationChangedNotification request succeeded"); + logger.debug("The operationChangedNotification request succeeded"); return new Response(); } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/SMSAuthorizationController.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/SMSAuthorizationController.java index 2f702519..b2c4d660 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/SMSAuthorizationController.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/SMSAuthorizationController.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,8 @@ import io.getlime.security.powerauth.lib.dataadapter.model.request.CreateSMSAuthorizationRequest; import io.getlime.security.powerauth.lib.dataadapter.model.request.VerifySMSAuthorizationRequest; import io.getlime.security.powerauth.lib.dataadapter.model.response.CreateSMSAuthorizationResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.MethodParameter; import org.springframework.stereotype.Controller; @@ -37,18 +39,19 @@ import org.springframework.web.bind.annotation.*; import javax.validation.Valid; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.lang.invoke.MethodHandles; /** * Controller class which handles SMS OTP authorization. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Controller @RequestMapping("/api/auth/sms") public class SMSAuthorizationController { + private static final Logger logger = LoggerFactory.getLogger(SMSAuthorizationController.class); + private final SMSPersistenceService smsPersistenceService; private final CreateSMSAuthorizationRequestValidator requestValidator; private final DataAdapter dataAdapter; @@ -89,12 +92,12 @@ private void initBinder(WebDataBinder binder) { @RequestMapping(value = "create", method = RequestMethod.POST) public @ResponseBody ObjectResponse createAuthorizationSMS(@Valid @RequestBody ObjectRequest request, BindingResult result) throws MethodArgumentNotValidException, DataAdapterRemoteException, SMSAuthorizationFailedException, InvalidOperationContextException { if (result.hasErrors()) { - // getEnclosingMethod() on new object returns a reference to current method - MethodParameter methodParam = new MethodParameter(new Object(){}.getClass().getEnclosingMethod(),0); - Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "The createAuthorizationSMS request failed due to validation errors"); + // Call of getEnclosingMethod() on class found using MethodHandles.lookup() returns a reference to current method + MethodParameter methodParam = new MethodParameter(MethodHandles.lookup().lookupClass().getEnclosingMethod(),0); + logger.warn("The createAuthorizationSMS request failed due to validation errors"); throw new MethodArgumentNotValidException(methodParam, result); } - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received createAuthorizationSMS request, operation ID: "+request.getRequestObject().getOperationContext().getId()); + logger.info("Received createAuthorizationSMS request, operation ID: "+request.getRequestObject().getOperationContext().getId()); CreateSMSAuthorizationRequest smsRequest = request.getRequestObject(); // Create authorization SMS and persist it. @@ -108,7 +111,7 @@ private void initBinder(WebDataBinder binder) { // Create response. CreateSMSAuthorizationResponse response = new CreateSMSAuthorizationResponse(messageId); - Logger.getLogger(this.getClass().getName()).log(Level.INFO,"The createAuthorizationSMS request succeeded, operation ID: "+request.getRequestObject().getOperationContext().getId()); + logger.info("The createAuthorizationSMS request succeeded, operation ID: "+request.getRequestObject().getOperationContext().getId()); return new ObjectResponse<>(response); } @@ -132,13 +135,13 @@ private SMSAuthorizationEntity createAuthorizationSMS(@Valid CreateSMSAuthorizat */ @RequestMapping(value = "verify", method = RequestMethod.POST) public @ResponseBody Response verifyAuthorizationSMS(@RequestBody ObjectRequest request) throws SMSAuthorizationFailedException { - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received verifyAuthorizationSMS request, operation ID: "+request.getRequestObject().getOperationContext().getId()); + logger.info("Received verifyAuthorizationSMS request, operation ID: "+request.getRequestObject().getOperationContext().getId()); VerifySMSAuthorizationRequest verifyRequest = request.getRequestObject(); String messageId = verifyRequest.getMessageId(); String authorizationCode = verifyRequest.getAuthorizationCode(); // Verify authorization code. smsPersistenceService.verifyAuthorizationSMS(messageId, authorizationCode); - Logger.getLogger(this.getClass().getName()).log(Level.INFO,"The verifyAuthorizationSMS request succeeded, operation ID: "+request.getRequestObject().getOperationContext().getId()); + logger.info("The verifyAuthorizationSMS request succeeded, operation ID: "+request.getRequestObject().getOperationContext().getId()); return new Response(); } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/ServiceController.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/ServiceController.java index d26e5b81..cb69e724 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/ServiceController.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/controller/ServiceController.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ import io.getlime.core.rest.model.base.response.ObjectResponse; import io.getlime.security.powerauth.app.dataadapter.configuration.DataAdapterConfiguration; import io.getlime.security.powerauth.lib.dataadapter.model.response.ServiceStatusResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.info.BuildProperties; import org.springframework.stereotype.Controller; @@ -27,18 +29,18 @@ import org.springframework.web.bind.annotation.ResponseBody; import java.util.Date; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Class representing controller used for service and maintenance purpose. * - * @author Petr Dvorak, petr@lime-company.eu + * @author Petr Dvorak, petr@wultra.com */ @Controller @RequestMapping(value = "/api/service") public class ServiceController { + private static final Logger logger = LoggerFactory.getLogger(ServiceController.class); + private final DataAdapterConfiguration dataAdapterConfiguration; private final BuildProperties buildProperties; @@ -59,7 +61,7 @@ public ServiceController(DataAdapterConfiguration dataAdapterConfiguration, Buil */ @RequestMapping(value = "status", method = RequestMethod.GET) public @ResponseBody ObjectResponse getServiceStatus() { - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Received getServiceStatus request"); + logger.info("Received getServiceStatus request"); ServiceStatusResponse response = new ServiceStatusResponse(); response.setApplicationName(dataAdapterConfiguration.getApplicationName()); response.setApplicationDisplayName(dataAdapterConfiguration.getApplicationDisplayName()); @@ -67,7 +69,7 @@ public ServiceController(DataAdapterConfiguration dataAdapterConfiguration, Buil response.setTimestamp(new Date()); response.setVersion(buildProperties.getVersion()); response.setBuildTime(Date.from(buildProperties.getTime())); - Logger.getLogger(this.getClass().getName()).log(Level.FINE, "The getServiceStatus request succeeded"); + logger.debug("The getServiceStatus request succeeded"); return new ObjectResponse<>(response); } } \ No newline at end of file diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/AuthenticationFailedException.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/AuthenticationFailedException.java index 840c53d1..7e49b0e6 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/AuthenticationFailedException.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/AuthenticationFailedException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ /** * Exception used for cases when authentication fails. * - * @author Petr Dvorak, petr@lime-company.eu + * @author Petr Dvorak, petr@wultra.com */ public class AuthenticationFailedException extends Exception { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DataAdapterRemoteException.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DataAdapterRemoteException.java index 315c5a01..bc80b706 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DataAdapterRemoteException.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DataAdapterRemoteException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ /** * Exception for unexpected remote communication errors. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ public class DataAdapterRemoteException extends Exception { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DefaultExceptionResolver.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DefaultExceptionResolver.java index 364dfe09..d9e6d716 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DefaultExceptionResolver.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/DefaultExceptionResolver.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,8 @@ import io.getlime.core.rest.model.base.response.ErrorResponse; import io.getlime.security.powerauth.lib.dataadapter.model.entity.DataAdapterError; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; import org.springframework.validation.ObjectError; import org.springframework.web.bind.MethodArgumentNotValidException; @@ -29,17 +31,17 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Controller advice responsible for default exception resolving. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @ControllerAdvice public class DefaultExceptionResolver { + private static final Logger logger = LoggerFactory.getLogger(DefaultExceptionResolver.class); + /** * Handling of unexpected errors. * @param t Throwable. @@ -48,7 +50,7 @@ public class DefaultExceptionResolver { @ExceptionHandler(Throwable.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody ErrorResponse handleDefaultException(Throwable t) { - Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error occurred in Data Adapter", t); + logger.error("Error occurred in Data Adapter", t); DataAdapterError error = new DataAdapterError(DataAdapterError.Code.ERROR_GENERIC, "Unknown Error"); return new ErrorResponse(error); } @@ -169,7 +171,7 @@ public class DefaultExceptionResolver { @ExceptionHandler(DataAdapterRemoteException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody ErrorResponse handleDataAdapterRemoteException(DataAdapterRemoteException ex) { - Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Error occurred while communicating with remote system", ex); + logger.error("Error occurred while communicating with remote system", ex); DataAdapterError error = new DataAdapterError(DataAdapterError.Code.REMOTE_ERROR, "error.remote"); return new ErrorResponse(error); } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/InvalidOperationContextException.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/InvalidOperationContextException.java index 30a4220f..6465123d 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/InvalidOperationContextException.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/InvalidOperationContextException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ /** * Exception used for case when operation context is invalid. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ public class InvalidOperationContextException extends Exception { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/SMSAuthorizationFailedException.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/SMSAuthorizationFailedException.java index bd04e206..56db9257 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/SMSAuthorizationFailedException.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/SMSAuthorizationFailedException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,7 @@ /** * Exception used for cases when SMS OTP authorization fails. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ public class SMSAuthorizationFailedException extends Exception { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/UserNotFoundException.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/UserNotFoundException.java index 06c2489e..14298dd1 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/UserNotFoundException.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/exception/UserNotFoundException.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ /** * Exception used for case when user is not found. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ public class UserNotFoundException extends Exception { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/DataAdapterService.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/DataAdapterService.java index a67f4402..c3cc0f72 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/DataAdapterService.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/DataAdapterService.java @@ -6,10 +6,11 @@ import io.getlime.security.powerauth.crypto.server.util.DataDigest; import io.getlime.security.powerauth.lib.dataadapter.model.entity.*; import io.getlime.security.powerauth.lib.dataadapter.model.entity.attribute.AmountAttribute; -import io.getlime.security.powerauth.lib.dataadapter.model.entity.attribute.Attribute; import io.getlime.security.powerauth.lib.dataadapter.model.entity.attribute.FormFieldConfig; import io.getlime.security.powerauth.lib.dataadapter.model.response.DecorateOperationFormDataResponse; import io.getlime.security.powerauth.lib.dataadapter.model.response.UserDetailResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; @@ -17,17 +18,17 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Sample implementation of DataAdapter interface which should be updated in real implementation. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Service public class DataAdapterService implements DataAdapter { + private static final Logger logger = LoggerFactory.getLogger(DataAdapterService.class); + private static final String BANK_ACCOUNT_CHOICE_ID = "operation.bankAccountChoice"; private final DataAdapterI18NService dataAdapterI18NService; @@ -124,9 +125,10 @@ public DecorateOperationFormDataResponse decorateFormData(String userId, Operati defaultValue = config.getDefaultValue(); } } - Attribute attr = formData.addBankAccountChoice(BANK_ACCOUNT_CHOICE_ID, bankAccounts, choiceEnabled, defaultValue); + formData.addBankAccountChoice(BANK_ACCOUNT_CHOICE_ID, bankAccounts, choiceEnabled, defaultValue); // Sample warning banner displayed above the bank account choice field. + // Attribute attr = formData.addBankAccountChoice(BANK_ACCOUNT_CHOICE_ID, bankAccounts, choiceEnabled, defaultValue); // formData.addBannerBeforeField(BannerType.BANNER_WARNING, "banner.invalidAccount", attr); return new DecorateOperationFormDataResponse(formData); @@ -135,27 +137,25 @@ public DecorateOperationFormDataResponse decorateFormData(String userId, Operati @Override public void formDataChangedNotification(String userId, FormDataChange change, OperationContext operationContext) throws DataAdapterRemoteException { String operationId = operationContext.getId(); - switch (change.getType()) { - case BANK_ACCOUNT_CHOICE: - // Handle bank account choice here (e.g. send notification to bank backend). - BankAccountChoice bankAccountChoice = (BankAccountChoice) change; - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Bank account chosen: {0}, operation ID: {1}", new String[] {bankAccountChoice.getBankAccountId(), operationContext.getId()}); - break; - case AUTH_METHOD_CHOICE: - // Handle authorization method choice here (e.g. send notification to bank backend). - AuthMethodChoice authMethodChoice = (AuthMethodChoice) change; - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Authorization method chosen: {0}, operation ID: {1}", new String[] {authMethodChoice.getChosenAuthMethod().toString(), operationContext.getId()}); - break; - default: - throw new IllegalStateException("Invalid change entity type: " + change.getType()); + if (change instanceof BankAccountChoice) { + // Handle bank account choice here (e.g. send notification to bank backend). + BankAccountChoice bankAccountChoice = (BankAccountChoice) change; + logger.info("Bank account chosen: {}, operation ID: {}", new String[]{bankAccountChoice.getBankAccountId(), operationId}); + return; + } else if (change instanceof AuthMethodChoice) { + // Handle authorization method choice here (e.g. send notification to bank backend). + AuthMethodChoice authMethodChoice = (AuthMethodChoice) change; + logger.info("Authorization method chosen: {}, operation ID: {}", new String[]{authMethodChoice.getChosenAuthMethod().toString(), operationId}); + return; } + throw new IllegalStateException("Invalid change entity type: " + change.getType()); } @Override public void operationChangedNotification(String userId, OperationChange change, OperationContext operationContext) throws DataAdapterRemoteException { String operationId = operationContext.getId(); // Handle operation change here (e.g. send notification to bank backend). - Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Operation changed, status: {0}, operation ID: {1}", new String[] {change.toString(), operationContext.getId()}); + logger.info("Operation changed, status: {}, operation ID: {}", new String[] {change.toString(), operationId}); } @Override @@ -183,6 +183,9 @@ public AuthorizationCode generateAuthorizationCode(String userId, OperationConte } final DataDigest.Result digestResult = new DataDigest().generateDigest(digestItems); + if (digestResult == null) { + throw new InvalidOperationContextException("Digest generation failed"); + } return new AuthorizationCode(digestResult.getDigest(), digestResult.getSalt()); } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/OperationValueExtractionService.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/OperationValueExtractionService.java index 9445e9f2..f92f8d11 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/OperationValueExtractionService.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/service/OperationValueExtractionService.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ /** * Service which extracts form data from an operation based on required input for SMS text. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Service public class OperationValueExtractionService { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/AuthenticationRequestValidator.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/AuthenticationRequestValidator.java index 02db7445..29e926bb 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/AuthenticationRequestValidator.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/AuthenticationRequestValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ import io.getlime.security.powerauth.lib.dataadapter.model.entity.OperationContext; import io.getlime.security.powerauth.lib.dataadapter.model.enumeration.AuthenticationType; import io.getlime.security.powerauth.lib.dataadapter.model.request.AuthenticationRequest; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; @@ -29,7 +31,7 @@ * * Additional validation logic can be added if applicable. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Component public class AuthenticationRequestValidator implements Validator { @@ -40,7 +42,7 @@ public class AuthenticationRequestValidator implements Validator { * @return Whether validator can validate given class. */ @Override - public boolean supports(Class clazz) { + public boolean supports(@NonNull Class clazz) { return ObjectRequest.class.isAssignableFrom(clazz); } @@ -51,15 +53,22 @@ public boolean supports(Class clazz) { */ @Override @SuppressWarnings("unchecked") - public void validate(Object o, Errors errors) { + public void validate(@Nullable Object o, @NonNull Errors errors) { ObjectRequest requestObject = (ObjectRequest) o; + if (requestObject == null) { + errors.rejectValue("requestObject.operationContext", "operationContext.missing"); + return; + } + AuthenticationRequest authRequest = requestObject.getRequestObject(); // update validation logic based on the real Data Adapter requirements String username = authRequest.getUsername(); String password = authRequest.getPassword(); OperationContext operationContext = authRequest.getOperationContext(); - + if (operationContext == null) { + errors.rejectValue("requestObject.operationContext", "operationContext.missing"); + } ValidationUtils.rejectIfEmptyOrWhitespace(errors, "requestObject.username", "login.username.empty"); if (username!=null && username.length() > 30) { errors.rejectValue("requestObject.username", "login.username.long"); @@ -74,9 +83,5 @@ public void validate(Object o, Errors errors) { if (authType != AuthenticationType.BASIC) { errors.rejectValue("requestObject.type", "login.type.unsupported"); } - - if (operationContext == null) { - errors.rejectValue("requestObject.operationContext", "operationContext.missing"); - } } } diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/CreateSMSAuthorizationRequestValidator.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/CreateSMSAuthorizationRequestValidator.java index 84ec9aec..690047a5 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/CreateSMSAuthorizationRequestValidator.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/impl/validation/CreateSMSAuthorizationRequestValidator.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ import io.getlime.security.powerauth.lib.dataadapter.model.entity.attribute.AmountAttribute; import io.getlime.security.powerauth.lib.dataadapter.model.request.CreateSMSAuthorizationRequest; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.lang.NonNull; +import org.springframework.lang.Nullable; import org.springframework.stereotype.Component; import org.springframework.validation.Errors; import org.springframework.validation.ValidationUtils; @@ -34,7 +36,7 @@ * * Additional validation logic can be added if applicable. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Component public class CreateSMSAuthorizationRequestValidator implements Validator { @@ -56,7 +58,7 @@ public CreateSMSAuthorizationRequestValidator(OperationValueExtractionService op * @return Whether validator can validate given class. */ @Override - public boolean supports(Class clazz) { + public boolean supports(@NonNull Class clazz) { return ObjectRequest.class.isAssignableFrom(clazz); } @@ -67,8 +69,12 @@ public boolean supports(Class clazz) { */ @Override @SuppressWarnings("unchecked") - public void validate(Object o, Errors errors) { + public void validate(@Nullable Object o, @NonNull Errors errors) { ObjectRequest requestObject = (ObjectRequest) o; + if (requestObject == null) { + errors.rejectValue("requestObject.operationContext", "operationContext.missing"); + return; + } CreateSMSAuthorizationRequest authRequest = requestObject.getRequestObject(); // update validation logic based on the real Data Adapter requirements diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/SMSAuthorizationRepository.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/SMSAuthorizationRepository.java index bf99c012..13110e6b 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/SMSAuthorizationRepository.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/SMSAuthorizationRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ /** * Crud repository for persistence of SMS OTP authorization messages. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Component public interface SMSAuthorizationRepository extends CrudRepository { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/model/entity/SMSAuthorizationEntity.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/model/entity/SMSAuthorizationEntity.java index 5278a095..c953ed38 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/model/entity/SMSAuthorizationEntity.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/repository/model/entity/SMSAuthorizationEntity.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ /** * Entity which stores SMS OTP authorization messages and related data. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Entity @Table(name = "da_sms_authorization") diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/DataAdapterI18NService.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/DataAdapterI18NService.java index 31227532..3699643e 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/DataAdapterI18NService.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/DataAdapterI18NService.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ /** * Service for i18n of Data Adapter. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Service public class DataAdapterI18NService { diff --git a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/SMSPersistenceService.java b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/SMSPersistenceService.java index 69e55ff5..20eb9759 100644 --- a/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/SMSPersistenceService.java +++ b/powerauth-data-adapter/src/main/java/io/getlime/security/powerauth/app/dataadapter/service/SMSPersistenceService.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Lime - HighTech Solutions s.r.o. + * Copyright 2017 Wultra s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ /** * Service class for generating SMS with OTP authorization code and verification of authorization code. * - * @author Roman Strobl, roman.strobl@lime-company.eu + * @author Roman Strobl, roman.strobl@wultra.com */ @Service public class SMSPersistenceService {