diff --git a/src/pom.xml b/src/pom.xml index 7755868..c492a4b 100644 --- a/src/pom.xml +++ b/src/pom.xml @@ -5,7 +5,10 @@ ca.bc.gov.open spring-starters - 0.1.1 + 0.1.2 + + + spring-starters pom @@ -20,8 +23,27 @@ all spring-sftp-starter + spring-bceid-starter + spring-starters-bom + + + + + spring-sftp-starter + + spring-starters-bom + spring-sftp-starter + + + spring-bceid-starter + + spring-starters-bom + spring-bceid-starter + + + diff --git a/src/spring-bceid-starter/README.md b/src/spring-bceid-starter/README.md new file mode 100644 index 0000000..10344c6 --- /dev/null +++ b/src/spring-bceid-starter/README.md @@ -0,0 +1,50 @@ +# spring-bceid-starter + +A stater to facilitate usage of bceid service. + +## Usage + +Add spring-bceid-starter as a maven dependency + +```xml + + + ca.bc.gov.open + spring-bceid-starter + 0.1.2 + + +``` + +## Configuration + +| name | definition | required | +| --- | --- | --- | +| [bcgov.bceid.service.uri](#cgovbceidserviceuri) | String | Yes | +| [bcgov.bceid.service.username](#bcgovbceidserviceusername) | String | Yes | +| [bcgov.bceid.service.password](#bcgovbceidservicepassword) | String | Yes | +| [bcgov.bceid.service.onlineServiceId](#bcgovbceidserviceonlineServiceId) | String | Yes | + +#### bcgov.bceid.service.uri + +* Value type is String + +Sets the BCeID service URI + +#### bcgov.bceid.service.username + +* Value type is String + +Sets the username used to set basic authentication on the BCeID service + +#### bcgov.bceid.service.password + +* Value type is String + +Sets the password used to set basic authentication on the BCeID service + +#### bcgov.bceid.service.onlineServiceId + +* Value type is String + +Sets the onlineServiceId diff --git a/src/spring-bceid-starter/pom.xml b/src/spring-bceid-starter/pom.xml new file mode 100644 index 0000000..bf8f86e --- /dev/null +++ b/src/spring-bceid-starter/pom.xml @@ -0,0 +1,148 @@ + + + 4.0.0 + + ca.bc.gov.open + spring-bceid-starter + 0.1.2 + + + 1.8 + UTF-8 + 1.8 + 1.8 + 2.2.4.RELEASE + 1.3.1.Final + + + + + + org.springframework.boot + spring-boot-starter-web-services + + + org.springframework.boot + spring-boot-starter-tomcat + + + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + + + + org.apache.cxf + cxf-rt-transports-http + + + + org.apache.cxf + cxf-rt-transports-http-jetty + + + + org.apache.commons + commons-lang3 + + + + joda-time + joda-time + + + + org.mapstruct + mapstruct + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + ca.bc.gov.open + spring-starters-bom + 0.1.2 + pom + import + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.5.1 + + ${java.version} + ${java.version} + + + org.mapstruct + mapstruct-processor + ${org.mapstruct.version} + + + + + + + + org.apache.cxf + cxf-codegen-plugin + 3.3.7 + + + generate-sources + generate-sources + + ${project.build.directory}/generated-sources/cxf + + + ${project.basedir}/src/main/resources/wsdl/BCeIDService.wsdl + + -client + -autoNameResolution + + + + + + wsdl2java + + + + + + + + + + diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java new file mode 100644 index 0000000..bf47365 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/AutoConfiguration.java @@ -0,0 +1,54 @@ +package ca.bc.gov.open.bceid.starter; + +import ca.bc.gov.open.bceid.starter.account.BCeIDAccountService; +import ca.bc.gov.open.bceid.starter.account.BCeIDAccountServiceImpl; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapperImpl; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapperImpl; +import ca.bceid.webservices.client.v9.BCeIDServiceSoap; +import org.apache.commons.lang3.StringUtils; +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(BCeIdProperties.class) +public class AutoConfiguration { + + private final BCeIdProperties bCeIdProperties; + + public AutoConfiguration(BCeIdProperties bCeIdProperties) { + this.bCeIdProperties = bCeIdProperties; + } + + @Bean + public AccountDetailRequestMapper accountDetailRequestMapper() { + return new AccountDetailRequestMapperImpl(); + } + + @Bean + public IndividualIdentityMapper individualIdentityMapper() { + return new IndividualIdentityMapperImpl(); + } + + @Bean + public BCeIDServiceSoap bCeIDServiceSoap() { + + JaxWsProxyFactoryBean jaxWsProxyFactoryBean = new JaxWsProxyFactoryBean(); + jaxWsProxyFactoryBean.setServiceClass(BCeIDServiceSoap.class); + jaxWsProxyFactoryBean.setAddress(bCeIdProperties.getUri()); + if(StringUtils.isNotBlank(bCeIdProperties.getUsername())) + jaxWsProxyFactoryBean.setUsername(bCeIdProperties.getUsername()); + if(StringUtils.isNotBlank(bCeIdProperties.getPassword())) + jaxWsProxyFactoryBean.setPassword(bCeIdProperties.getPassword()); + return (BCeIDServiceSoap) jaxWsProxyFactoryBean.create(); + + } + + @Bean + public BCeIDAccountService bCeIDUserService(BCeIDServiceSoap bCeIDServiceSoap, AccountDetailRequestMapper accountDetailRequestMapper, IndividualIdentityMapper individualIdentityMapper) { + return new BCeIDAccountServiceImpl(bCeIDServiceSoap, bCeIdProperties, accountDetailRequestMapper, individualIdentityMapper); + } +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java new file mode 100644 index 0000000..e4de6ae --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/BCeIdProperties.java @@ -0,0 +1,44 @@ +package ca.bc.gov.open.bceid.starter; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +@ConfigurationProperties(prefix = "bcgov.bceid.service") +public class BCeIdProperties { + + private String uri; + private String username; + private String password; + private String onlineServiceId; + + public String getUri() { + return uri; + } + + public void setUri(String uri) { + this.uri = uri; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getOnlineServiceId() { + return onlineServiceId; + } + + public void setOnlineServiceId(String onlineServiceId) { + this.onlineServiceId = onlineServiceId; + } +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountService.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountService.java new file mode 100644 index 0000000..33f17ba --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountService.java @@ -0,0 +1,11 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; + +import java.util.Optional; + +public interface BCeIDAccountService { + + Optional getIndividualIdentity(GetAccountRequest request); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java new file mode 100644 index 0000000..09f2201 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImpl.java @@ -0,0 +1,48 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bc.gov.open.bceid.starter.BCeIdProperties; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapper; +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; +import ca.bceid.webservices.client.v9.AccountDetailRequest; +import ca.bceid.webservices.client.v9.AccountDetailResponse; +import ca.bceid.webservices.client.v9.BCeIDServiceSoap; +import ca.bceid.webservices.client.v9.ResponseCode; + +import java.util.Optional; + +public class BCeIDAccountServiceImpl implements BCeIDAccountService { + + private final BCeIDServiceSoap bCeIDServiceSoap; + + private final BCeIdProperties bCeIdProperties; + + private final AccountDetailRequestMapper accountDetailRequestMapper; + + private final IndividualIdentityMapper individualIdentityMapper; + + public BCeIDAccountServiceImpl(BCeIDServiceSoap bCeIDServiceSoap, BCeIdProperties bCeIdProperties, AccountDetailRequestMapper accountDetailRequestMapper, IndividualIdentityMapper individualIdentityMapper) { + this.bCeIDServiceSoap = bCeIDServiceSoap; + this.bCeIdProperties = bCeIdProperties; + this.accountDetailRequestMapper = accountDetailRequestMapper; + this.individualIdentityMapper = individualIdentityMapper; + } + + @Override + public Optional getIndividualIdentity(GetAccountRequest request) { + + AccountDetailRequest accountDetailRequest = accountDetailRequestMapper.toAccountDetailRequest(request, bCeIdProperties.getOnlineServiceId()); + + AccountDetailResponse response = bCeIDServiceSoap.getAccountDetail(accountDetailRequest); + + if (response.getCode() == ResponseCode.SUCCESS) { + + return Optional.of(individualIdentityMapper.toIndividualIdentity(response)); + + } + + return Optional.empty(); + + } + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java new file mode 100644 index 0000000..ce61a5c --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequest.java @@ -0,0 +1,86 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bceid.webservices.client.v9.BCeIDAccountTypeCode; +import org.apache.commons.lang3.StringUtils; + +public class GetAccountRequest { + + private String id; + private BCeIDAccountTypeCode bCeIDAccountTypeCode; + private String requesterId; + private BCeIDAccountTypeCode requesterBCeIDAccountTypeCode; + + private GetAccountRequest(String id, BCeIDAccountTypeCode bCeIDAccountTypeCode) { + if(StringUtils.isBlank(id)) throw new IllegalArgumentException("Id value is required"); + this.id = id; + this.bCeIDAccountTypeCode = bCeIDAccountTypeCode; + this.requesterId = id; + this.requesterBCeIDAccountTypeCode = bCeIDAccountTypeCode; + } + + public String getId() { + return id; + } + + public BCeIDAccountTypeCode getbCeIDAccountTypeCode() { + return bCeIDAccountTypeCode; + } + + public String getRequesterId() { + return requesterId; + } + + public BCeIDAccountTypeCode getRequesterBCeIDAccountTypeCode() { + return requesterBCeIDAccountTypeCode; + } + + public static GetAccountRequest BusinessSelfRequest(String id) { + return new GetAccountRequest(id, BCeIDAccountTypeCode.BUSINESS); + } + + /** + * Build a request EDS Federated Accounts + * @param id + * @return + */ + public static GetAccountRequest EdsSelfRequest(String id) { + return new GetAccountRequest(id, BCeIDAccountTypeCode.EDS); + } + + /** + * Build a request for individual + * @param id + * @return + */ + public static GetAccountRequest IndividualSelfRequest(String id) { + return new GetAccountRequest(id, BCeIDAccountTypeCode.INDIVIDUAL); + } + + /** + * Build a request for internal + * @param id + * @return + */ + public static GetAccountRequest InternalSelfRequest(String id) { + return new GetAccountRequest(id, BCeIDAccountTypeCode.INTERNAL); + } + + /** + * Build a request for Liquor Distribution Branch Federated Accounts + * @param id + * @return + */ + public static GetAccountRequest LdbSelfRequest(String id) { + return new GetAccountRequest(id, BCeIDAccountTypeCode.LDB); + } + + /** + * Build a request for Verified Individual. + * @param id + * @return + */ + public static GetAccountRequest VerifiedIndividualSelfRequest(String id) { + return new GetAccountRequest(id, BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL); + } + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AccountDetailRequestMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AccountDetailRequestMapper.java new file mode 100644 index 0000000..9ca16a9 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AccountDetailRequestMapper.java @@ -0,0 +1,18 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.GetAccountRequest; +import ca.bceid.webservices.client.v9.AccountDetailRequest; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper +public interface AccountDetailRequestMapper { + + @Mapping(target = "userGuid", source = "getAccountRequest.id") + @Mapping(target = "accountTypeCode", source="getAccountRequest.bCeIDAccountTypeCode") + @Mapping(target = "requesterUserGuid", source="getAccountRequest.requesterId") + @Mapping(target = "requesterAccountTypeCode", source="getAccountRequest.requesterBCeIDAccountTypeCode") + @Mapping(target = "onlineServiceId", source = "onlineServiceId") + AccountDetailRequest toAccountDetailRequest(GetAccountRequest getAccountRequest, String onlineServiceId); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AddressMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AddressMapper.java new file mode 100644 index 0000000..205dad0 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/AddressMapper.java @@ -0,0 +1,20 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.models.Address; +import ca.bceid.webservices.client.v9.BCeIDAddress; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(uses = { BCeIdMapper.class }) +public interface AddressMapper { + + @Mapping(source="addressLine1", target = "addressLine1", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="addressLine2", target = "addressLine2", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="city", target = "city", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="postal", target = "postal", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="province", target = "province", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="country", target = "country", qualifiedByName= {"BCeIdMapper", "toString"}) + @Mapping(source="unstructuredAddress", target = "unstructuredAddress", qualifiedByName= {"BCeIdMapper", "toString"}) + Address toAddress(BCeIDAddress bCeIDAddress); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java new file mode 100644 index 0000000..7b80af3 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/BCeIdMapper.java @@ -0,0 +1,22 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bceid.webservices.client.v9.BCeIDDateTime; +import ca.bceid.webservices.client.v9.BCeIDString; +import org.joda.time.DateTime; +import org.mapstruct.Named; + +@Named("BCeIdMapper") +public interface BCeIdMapper { + + @Named("toString") + static String toString(BCeIDString bCeIDString) { + return bCeIDString.getValue(); + } + + @Named("toDateTime") + static DateTime toDateTime(BCeIDDateTime bCeIDDateTime) { + return new DateTime(bCeIDDateTime.getValue().toGregorianCalendar().getTime()); + } + + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/IndividualIdentityMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/IndividualIdentityMapper.java new file mode 100644 index 0000000..e0f1a4e --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/IndividualIdentityMapper.java @@ -0,0 +1,18 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; +import ca.bceid.webservices.client.v9.AccountDetailResponse; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(uses = {NameMapper.class, BCeIdMapper.class, AddressMapper.class}) +public interface IndividualIdentityMapper { + + @Mapping(target = "dateOfBirth", source="account.individualIdentity.dateOfBirth", qualifiedByName= {"BCeIdMapper", "toDateTime"}) + @Mapping(target = "name", source="account.individualIdentity.name") + @Mapping(target = "residentialAddress", source="account.individualIdentity.residentialAddress") + @Mapping(target = "mailingAddress", source="account.individualIdentity.mailingAddress") + IndividualIdentity toIndividualIdentity(AccountDetailResponse accountDetailResponse); + + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/NameMapper.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/NameMapper.java new file mode 100644 index 0000000..f021d08 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/mappers/NameMapper.java @@ -0,0 +1,18 @@ +package ca.bc.gov.open.bceid.starter.account.mappers; + +import ca.bc.gov.open.bceid.starter.account.models.Name; +import ca.bceid.webservices.client.v9.BCeIDName; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(uses = BCeIdMapper.class) +public interface NameMapper { + + @Mapping(target = "firstName", source = "firstname", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "middleName", source = "middleName", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "otherMiddleName", source = "otherMiddleName", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "surname", source = "surname", qualifiedByName= { "BCeIdMapper", "toString"} ) + @Mapping(target = "initials", source = "initials", qualifiedByName= { "BCeIdMapper", "toString"} ) + Name toName(BCeIDName bCeIDName); + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java new file mode 100644 index 0000000..bdfa4e1 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Address.java @@ -0,0 +1,116 @@ +package ca.bc.gov.open.bceid.starter.account.models; + +public class Address { + + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String province; + private String country; + private String unstructuredAddress; + + protected Address(Builder builder) { + this.addressLine1 = builder.addressLine1; + this.addressLine2 = builder.addressLine2; + this.city = builder.city; + this.postal = builder.postal; + this.province = builder.province; + this.country = builder.country; + this.unstructuredAddress = builder.unstructuredAddress; + } + + public Address(String addressLine1, String addressLine2, String city, String postal, String province, String country, String unstructuredAddress) { + this.addressLine1 = addressLine1; + this.addressLine2 = addressLine2; + this.city = city; + this.postal = postal; + this.province = province; + this.country = country; + this.unstructuredAddress = unstructuredAddress; + } + + public String getAddressLine1() { + return addressLine1; + } + + public String getAddressLine2() { + return addressLine2; + } + + public String getCity() { + return city; + } + + public String getPostal() { + return postal; + } + + public String getProvince() { + return province; + } + + public String getCountry() { + return country; + } + + public String getUnstructuredAddress() { + return unstructuredAddress; + } + + public static Address.Builder builder() { + return new Address.Builder(); + } + + public static class Builder { + + private String addressLine1; + private String addressLine2; + private String city; + private String postal; + private String province; + private String country; + private String unstructuredAddress; + + public Builder addressLine1(String addressLine1) { + this.addressLine1 = addressLine1; + return this; + } + + public Builder addressLine2(String addressLine2) { + this.addressLine2 = addressLine2; + return this; + } + + public Builder city(String city) { + this.city = city; + return this; + } + + public Builder postal(String postal) { + this.postal = postal; + return this; + } + + public Builder province(String province) { + this.province = province; + return this; + } + + public Builder country(String country) { + this.country = country; + return this; + } + + public Builder unstructuredAddress(String unstructuredAddress) { + this.unstructuredAddress = unstructuredAddress; + return this; + } + + public Address create() { + return new Address(this); + } + + } + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java new file mode 100644 index 0000000..0489be6 --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/IndividualIdentity.java @@ -0,0 +1,79 @@ +package ca.bc.gov.open.bceid.starter.account.models; + +import org.joda.time.DateTime; + +public class IndividualIdentity { + + private Name name; + private DateTime dateOfBirth; + private Address residentialAddress; + private Address mailingAddress; + + protected IndividualIdentity(Builder builder) { + this.name = builder.name; + this.dateOfBirth = builder.dateOfBirth; + this.residentialAddress = builder.residentialAddress; + this.mailingAddress = builder.mailingAddress; + } + + public IndividualIdentity(Name name, DateTime dateOfBirth, Address residentialAddress, Address mailingAddress) { + this.name = name; + this.dateOfBirth = dateOfBirth; + this.residentialAddress = residentialAddress; + this.mailingAddress = mailingAddress; + } + + public Name getName() { + return name; + } + + public DateTime getDateOfBirth() { + return dateOfBirth; + } + + public Address getResidentialAddress() { + return residentialAddress; + } + + public Address getMailingAddress() { + return mailingAddress; + } + + public static IndividualIdentity.Builder builder() { + return new IndividualIdentity.Builder(); + } + + public static class Builder { + + private Name name; + private DateTime dateOfBirth; + private Address residentialAddress; + private Address mailingAddress; + + public Builder name(Name name) { + this.name = name; + return this; + } + + public Builder dateOfBirth(DateTime dateOfBirth) { + this.dateOfBirth = dateOfBirth; + return this; + } + + public Builder residentialAddress(Address residentialAddress) { + this.residentialAddress = residentialAddress; + return this; + } + + public Builder mailingAddress(Address mailingAddress) { + this.mailingAddress = mailingAddress; + return this; + } + + public IndividualIdentity create() { + return new IndividualIdentity(this); + } + + } + +} diff --git a/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java new file mode 100644 index 0000000..8c981fd --- /dev/null +++ b/src/spring-bceid-starter/src/main/java/ca/bc/gov/open/bceid/starter/account/models/Name.java @@ -0,0 +1,92 @@ +package ca.bc.gov.open.bceid.starter.account.models; + +public class Name { + + private String firstName; + private String middleName; + private String otherMiddleName; + private String surname; + private String initials; + + protected Name(Builder builder) { + this.firstName = builder.firstName; + this.middleName = builder.middleName; + this.otherMiddleName = builder.otherMiddleName; + this.surname = builder.surname; + this.initials = builder.initials; + } + + public Name(String firstName, String middleName, String otherMiddleName, String surname, String initials) { + this.firstName = firstName; + this.middleName = middleName; + this.otherMiddleName = otherMiddleName; + this.surname = surname; + this.initials = initials; + } + + public String getFirstName() { + return firstName; + } + + public String getMiddleName() { + return middleName; + } + + public String getOtherMiddleName() { + return otherMiddleName; + } + + public String getSurname() { + return surname; + } + + public String getInitials() { + return initials; + } + + public static Name.Builder builder() { + return new Name.Builder(); + } + + public static class Builder { + + private String firstName; + private String middleName; + private String otherMiddleName; + private String surname; + private String initials; + + + public Builder firstName(String firstName) { + this.firstName = firstName; + return this; + } + + public Builder middleName(String middleName) { + this.middleName = middleName; + return this; + } + + public Builder otherMiddleName(String otherMiddleName) { + this.otherMiddleName = otherMiddleName; + return this; + } + + public Builder surname(String surname) { + this.surname = surname; + return this; + } + + public Builder initials(String initials) { + this.initials = initials; + return this; + } + + + public Name create() { + return new Name(this); + } + + } + +} diff --git a/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories b/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..17e8183 --- /dev/null +++ b/src/spring-bceid-starter/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ + ca.bc.gov.open.bceid.starter.AutoConfiguration diff --git a/src/spring-bceid-starter/src/main/resources/wsdl/BCeIDService.wsdl b/src/spring-bceid-starter/src/main/resources/wsdl/BCeIDService.wsdl new file mode 100644 index 0000000..480b3fc --- /dev/null +++ b/src/spring-bceid-starter/src/main/resources/wsdl/BCeIDService.wsdl @@ -0,0 +1,1086 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Get Internal User Group Membership Information + + + + + Search for all BCeID accounts. + + + + + Search for all internal accounts. + + + + + Get details for a given list of accounts. + + + + + Get details for a given account. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java new file mode 100644 index 0000000..f3a005e --- /dev/null +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/AutoConfigurationTest.java @@ -0,0 +1,29 @@ +package ca.bc.gov.open.bceid.starter; + +import ca.bc.gov.open.bceid.starter.account.BCeIDAccountService; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; +import ca.bceid.webservices.client.v9.BCeIDServiceSoap; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisplayName("Test AutoConfiguration") +public class AutoConfigurationTest { + ApplicationContextRunner context = new ApplicationContextRunner(); + + @Test + @DisplayName("Test Beans Exist") + public void testConfigure() { + + context.run(it -> { + Assertions.assertNotNull(assertThat(it).getBean(AccountDetailRequestMapper.class)); + Assertions.assertNotNull(assertThat(it).getBean(BCeIDServiceSoap.class)); + Assertions.assertNotNull(assertThat(it).getBean(BCeIDAccountService.class)); + }); + + } +} diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java new file mode 100644 index 0000000..b0cc21a --- /dev/null +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/BCeIDAccountServiceImplTest.java @@ -0,0 +1,178 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bc.gov.open.bceid.starter.BCeIdProperties; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.AccountDetailRequestMapperImpl; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapper; +import ca.bc.gov.open.bceid.starter.account.mappers.IndividualIdentityMapperImpl; +import ca.bc.gov.open.bceid.starter.account.models.IndividualIdentity; +import ca.bceid.webservices.client.v9.*; +import org.junit.jupiter.api.*; +import org.mockito.ArgumentMatchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; +import java.util.Calendar; +import java.util.Date; +import java.util.GregorianCalendar; +import java.util.Optional; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisplayName("Test BCeIDAccountServiceImpl") +public class BCeIDAccountServiceImplTest { + private static final String SUCCESS = "SUCCESS"; + private static final String FIRSTNAME = "FIRSTNAME"; + private static final String MIDDLENAME = "MIDDLENAME"; + private static final String OTHERMIDDLE = "OTHERMIDDLE"; + private static final String SURNAME = "SURNAME"; + private static final String INITIAL = "INITIAL"; + private static final String ADDRESS_1 = "ADDRESS1"; + private static final String ADDRESS_2 = "ADDRESS2"; + private static final String COUNTRY = "COUNTRY"; + private static final String POSTAL = "POSTAL"; + private static final String PROVINCE = "PROVINCE"; + private static final String UNSTRUCTUREDADDRESS = "UNSTRUCTUREDADDRESS"; + private static final String CITY = "CITY"; + private static final String FAILED = "FAILED"; + BCeIDAccountServiceImpl sut; + + @Mock + private BCeIDServiceSoap bCeIDServiceSoapMock; + + @Mock + private BCeIdProperties bCeIdPropertiesMock; + + private AccountDetailRequestMapper accountDetailRequestMapper; + + private IndividualIdentityMapper individualIdentityMapper; + + @BeforeEach + public void init() { + + MockitoAnnotations.initMocks(this); + + Mockito.doReturn(createAccountDetailsResponse(ResponseCode.SUCCESS)) + .when(bCeIDServiceSoapMock) + .getAccountDetail(ArgumentMatchers.argThat(x -> x.getUserGuid().equals(SUCCESS) && x.getAccountTypeCode() == BCeIDAccountTypeCode.INDIVIDUAL)); + + Mockito + .doReturn(createAccountDetailsResponse(ResponseCode.FAILED)) + .when(bCeIDServiceSoapMock) + .getAccountDetail(ArgumentMatchers.argThat(x -> x.getUserGuid().equals(FAILED))); + + // Testing mapper as part of the test + accountDetailRequestMapper = new AccountDetailRequestMapperImpl(); + individualIdentityMapper = new IndividualIdentityMapperImpl(); + + sut = new BCeIDAccountServiceImpl(bCeIDServiceSoapMock, bCeIdPropertiesMock, accountDetailRequestMapper, individualIdentityMapper); + + } + + @Test + @DisplayName("Test Return Individual Identity") + public void withValidRequestReturnAccount() { + + Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(SUCCESS)); + + Assertions.assertTrue(result.isPresent()); + Assertions.assertEquals(FIRSTNAME, result.get().getName().getFirstName()); + Assertions.assertEquals(INITIAL, result.get().getName().getInitials()); + Assertions.assertEquals(MIDDLENAME, result.get().getName().getMiddleName()); + Assertions.assertEquals(OTHERMIDDLE, result.get().getName().getOtherMiddleName()); + Assertions.assertEquals(SURNAME, result.get().getName().getSurname()); + + Assertions.assertEquals(ADDRESS_1, result.get().getResidentialAddress().getAddressLine1()); + Assertions.assertEquals(ADDRESS_2, result.get().getResidentialAddress().getAddressLine2()); + Assertions.assertEquals(CITY, result.get().getResidentialAddress().getCity()); + Assertions.assertEquals(COUNTRY, result.get().getResidentialAddress().getCountry()); + Assertions.assertEquals(POSTAL, result.get().getResidentialAddress().getPostal()); + Assertions.assertEquals(PROVINCE, result.get().getResidentialAddress().getProvince()); + Assertions.assertEquals(UNSTRUCTUREDADDRESS, result.get().getResidentialAddress().getUnstructuredAddress()); + + Assertions.assertEquals(ADDRESS_1, result.get().getMailingAddress().getAddressLine1()); + Assertions.assertEquals(ADDRESS_2, result.get().getMailingAddress().getAddressLine2()); + Assertions.assertEquals(CITY, result.get().getMailingAddress().getCity()); + Assertions.assertEquals(COUNTRY, result.get().getMailingAddress().getCountry()); + Assertions.assertEquals(POSTAL, result.get().getMailingAddress().getPostal()); + Assertions.assertEquals(PROVINCE, result.get().getMailingAddress().getProvince()); + Assertions.assertEquals(UNSTRUCTUREDADDRESS, result.get().getMailingAddress().getUnstructuredAddress()); + + Assertions.assertNotNull(result.get().getDateOfBirth()); + + } + + @Test + @DisplayName("Test Return Failure") + public void withValidRequestReturnFailure() { + + Optional result = sut.getIndividualIdentity(GetAccountRequest.IndividualSelfRequest(FAILED)); + + Assertions.assertFalse(result.isPresent()); + } + + private BCeIDString getString(String value) { + + BCeIDString stringVal = new BCeIDString(); + stringVal.setValue(value); + return stringVal; + + } + + private AccountDetailResponse createAccountDetailsResponse(ResponseCode responseCode) { + + AccountDetailResponse accountDetailResponse = new AccountDetailResponse(); + + BCeIDAccount account = new BCeIDAccount(); + + BCeIDIndividualIdentity identity = new BCeIDIndividualIdentity(); + BCeIDDateTime birthDate = new BCeIDDateTime(); + birthDate.setValue(getDate()); + identity.setDateOfBirth(birthDate); + + BCeIDName name = new BCeIDName(); + + name.setFirstname(getString(FIRSTNAME)); + name.setMiddleName(getString(MIDDLENAME)); + name.setOtherMiddleName(getString(OTHERMIDDLE)); + name.setSurname(getString(SURNAME)); + name.setInitials(getString(INITIAL)); + identity.setName(name); + + BCeIDAddress address = new BCeIDAddress(); + address.setAddressLine1(getString(ADDRESS_1)); + address.setAddressLine2(getString(ADDRESS_2)); + address.setCity(getString(CITY)); + address.setCountry(getString(COUNTRY)); + address.setPostal(getString(POSTAL)); + address.setProvince(getString(PROVINCE)); + address.setUnstructuredAddress(getString(UNSTRUCTUREDADDRESS)); + identity.setResidentialAddress(address); + identity.setMailingAddress(address); + + account.setIndividualIdentity(identity); + + accountDetailResponse.setAccount(account); + + accountDetailResponse.setCode(responseCode); + return accountDetailResponse; + + } + private XMLGregorianCalendar getDate() { + + Calendar createDate = Calendar.getInstance(); + Date cDate = createDate.getTime(); + GregorianCalendar c = new GregorianCalendar(); + c.setTime(cDate); + try { + return DatatypeFactory.newInstance().newXMLGregorianCalendar(c); + } catch (DatatypeConfigurationException e) { + return null; + } + + } + +} diff --git a/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java new file mode 100644 index 0000000..bc176f1 --- /dev/null +++ b/src/spring-bceid-starter/src/test/java/ca/bc/gov/open/bceid/starter/account/GetAccountRequestTest.java @@ -0,0 +1,100 @@ +package ca.bc.gov.open.bceid.starter.account; + +import ca.bceid.webservices.client.v9.BCeIDAccountTypeCode; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@DisplayName("Test BCeIDAccountServiceImpl") +public class GetAccountRequestTest { + + private static final String ID = "ID"; + + @Test + @DisplayName("Test Static BusinessSelfRequest") + public void testStaticMethodBusinessSelfRequest() { + + GetAccountRequest result = GetAccountRequest.BusinessSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.BUSINESS, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.BUSINESS, result.getRequesterBCeIDAccountTypeCode()); + + } + + @Test + @DisplayName("Test Static EdsSelfRequest") + public void testStaticMethodEdsSelfRequest() { + + GetAccountRequest result = GetAccountRequest.EdsSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.EDS, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.EDS, result.getRequesterBCeIDAccountTypeCode()); + + } + + + @Test + @DisplayName("Test Static IndividualSelfRequest") + public void testStaticMethodIndividualSelfRequest() { + + GetAccountRequest result = GetAccountRequest.IndividualSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.INDIVIDUAL, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.INDIVIDUAL, result.getRequesterBCeIDAccountTypeCode()); + + } + + + @Test + @DisplayName("Test Static InternalSelfRequest") + public void testStaticMethodInternalSelfRequest() { + + GetAccountRequest result = GetAccountRequest.InternalSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.INTERNAL, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.INTERNAL, result.getRequesterBCeIDAccountTypeCode()); + + } + + @Test + @DisplayName("Test Static LdbSelfRequest") + public void testStaticMethodLdbSelfRequest() { + + GetAccountRequest result = GetAccountRequest.LdbSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.LDB, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.LDB, result.getRequesterBCeIDAccountTypeCode()); + + } + + @Test + @DisplayName("Test Static VerifiedIndividualSelfRequest") + public void testStaticMethodVerifiedIndividualSelfRequest() { + GetAccountRequest result = GetAccountRequest.VerifiedIndividualSelfRequest(ID); + + Assertions.assertEquals(ID, result.getId()); + Assertions.assertEquals(ID, result.getRequesterId()); + Assertions.assertEquals(BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL, result.getbCeIDAccountTypeCode()); + Assertions.assertEquals(BCeIDAccountTypeCode.VERIFIED_INDIVIDUAL, result.getRequesterBCeIDAccountTypeCode()); + } + + @Test + @DisplayName("Test No Id Exception") + public void testException() { + + Assertions.assertThrows(IllegalArgumentException.class,() -> GetAccountRequest.IndividualSelfRequest(null)); + + } +} diff --git a/src/spring-sftp-starter/pom.xml b/src/spring-sftp-starter/pom.xml index c662ddb..4a2561b 100644 --- a/src/spring-sftp-starter/pom.xml +++ b/src/spring-sftp-starter/pom.xml @@ -7,7 +7,7 @@ ca.bc.gov.open spring-sftp-starter - 0.1.1 + 0.1.2 UTF-8 @@ -32,7 +32,6 @@ commons-io commons-io - 1.4 @@ -68,6 +67,13 @@ pom import + + ca.bc.gov.open + spring-starters-bom + 0.1.2 + pom + import + diff --git a/src/spring-starters-bom/pom.xml b/src/spring-starters-bom/pom.xml new file mode 100644 index 0000000..8e2489e --- /dev/null +++ b/src/spring-starters-bom/pom.xml @@ -0,0 +1,69 @@ + + + + 4.0.0 + + ca.bc.gov.open + spring-starters-bom + 0.1.2 + + + 3.3.7 + 2.11.2 + 2.3.1 + 1.4 + 2.10.6 + 1.3.1.Final + + + + + + + + org.mapstruct + mapstruct + ${org.mapstruct.version} + + + + + org.apache.cxf + cxf-rt-frontend-jaxws + ${org.apache.cxf.version} + + + org.apache.cxf + cxf-rt-transports-http + ${org.apache.cxf.version} + + + org.apache.cxf + cxf-rt-transports-http-jetty + ${org.apache.cxf.version} + + + javax.xml.bind + jaxb-api + ${javax.xml.bind.version} + + + + commons-io + commons-io + ${commons.io.version} + + + + joda-time + joda-time + ${joda-time.version} + + + + + + +