Skip to content

Commit dc5e2da

Browse files
authored
App2App additional service implementation (#39)
* App2App additional service -rest and cli initial implementation * App2App additional service -soap implementation * App2App additional service SignatureRequest model enhancements, refactoring and code quality checks
1 parent ca36fba commit dc5e2da

48 files changed

Lines changed: 2007 additions & 913 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/use-the-client-via-cli.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ Arguments:
4242
-receipt - For sign operation. Send a receipt after the signature is acquired successfully
4343
4444
-geofencing - For sign operation. Request additional geofencing data
45+
46+
-app2app="myapp://example" - For sign operation (async only). Request App2App service which allows an Application Provider to automatically switch from
47+
their App to the Mobile ID App (and the Mobile ID App to automatically switch back to the originating App)
4548
4649
-validate - For sign operation. Validate the signature once it is successfully acquired
4750
@@ -78,6 +81,7 @@ Use cases:
7881
- ./bin/mid-client.sh -profile-query -msisdn=41790000000 -soap
7982
- ./bin/mid-client.sh -sign -receipt -msisdn=41790000000 -lang=en -dtbs="Do you want to login?" -req-timeout=120
8083
- ./bin/mid-client.sh -sign -sync -receipt -msisdn=41790000000 -lang=en -dtbs="Do you want to login?" -soap -vv
84+
- ./bin/mid-client.sh -sign -async -msisdn=41790000000 -lang=en -app2app="myapp://example" -dtbs="Do you want to login?" -rest -vv
8185
- ./bin/mid-client.sh \
8286
-config=my-config.properties \
8387
-sign -sync -receipt -geofencing \
@@ -95,46 +99,64 @@ Use the _-v_, _-vv_ and _-vvv_ arguments for increasingly detailed log levels, i
9599
exchanged packets.
96100

97101
## Examples
102+
98103
Start with a fresh set of configuration files:
104+
99105
```shell
100106
./bin/mid-client.sh -init
101107
```
102108

103109
Get the profile information for a particular phone number (MSISDN) that your application provider is controlling:
110+
104111
```shell
105112
./bin/mid-client.sh -profile-query -msisdn 41790000000
106113
```
107114

108115
Get the same profile information using a particular configuration file and the SOAP interface of Mobile ID:
116+
109117
```shell
110118
./bin/mid-client.sh -profile-query -msisdn 41790000000 -config local-config.properties -soap
111119
```
112120

113121
Request a digital signature to a particular phone number (MSISDN), in sync mode:
122+
114123
```shell
115124
./bin/mid-client.sh -sign -msisdn=41790000000 -geofencing -lang=en -dtbs "Do you want to login?" -sync
116125
```
117126

118127
Request a digital signature to a particular phone number (MSISDN), in async mode (this is the default mode) and with signature receipt:
128+
119129
```shell
120130
./bin/mid-client.sh -sign -msisdn=41790000000 -lang=en -dtbs "Do you want to login?" -receipt -req-timeout 120
121131
```
122132

133+
Request a digital signature to a particular phone number (MSISDN), in async mode (this is the default mode) and with app2app service:
134+
135+
```shell
136+
./bin/mid-client.sh -sign -msisdn=41790000000 -lang=en -app2app="myapp://example" -req-timeout 120
137+
```
138+
123139
Request a Mobile ID Serial number based on particular phone number (MSISDN), in async mode:
140+
124141
```shell
125142
./bin/mid-client.sh -get-mid-sn -msisdn=41790000000 -rest
126143
```
127144

128145
Note: when working with arguments that have values (such as _-msisdn_) you can pass the value either as the next argument:
146+
129147
```shell
130148
./bin/mid-client.sh -sign -msisdn 41790000000
131149
```
150+
132151
or in the form _name=value_:
152+
133153
```shell
134154
./bin/mid-client.sh -sign -msisdn=41790000000
135155
```
156+
136157
Please note that the _-dtbs_ argument is a bit more special, as it will most likely contain spaces, so either the entire name=value
137158
construct is enclosed in double quotes or, if you use the name<space>value form, then the value is enclosed in double quotes:
159+
138160
```shell
139161
./bin/mid-client.sh -sign -msisdn=41790000000 -dtbs "Do you want to login?"
140162
./bin/mid-client.sh -sign -msisdn=41790000000 "-dtbs=Do you want to login?"

mid-java-client-core/src/main/java/ch/swisscom/mid/client/config/DefaultConfiguration.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public class DefaultConfiguration {
3232
public static final String ADDITIONAL_SERVICE_USER_LANG_URI = "http://mss.ficom.fi/TS102204/v1.0.0#userLang";
3333
public static final String ADDITIONAL_SERVICE_SIGNATURE_VALIDATION_URI = "http://uri.etsi.org/TS102204/v1.1.2#validate";
3434
public static final String ADDITIONAL_SERVICE_GEOFENCING = "http://mid.swisscom.ch/as#geofencing";
35+
public static final String ADDITIONAL_SERVICE_APP2APP = "http://mid.swisscom.ch/as#app2app";
3536

3637
public static final String SIGNATURE_REQUEST_MAJOR_VERSION = "1";
3738
public static final String SIGNATURE_REQUEST_MINOR_VERSION = "2";

mid-java-client-core/src/main/java/ch/swisscom/mid/client/impl/Loggers.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public class Loggers {
2929
public static final String REQUEST_RESPONSE = "ch.swisscom.mid.client.requestResponse";
3030
public static final String FULL_REQUEST_RESPONSE = "ch.swisscom.mid.client.fullRequestResponse";
3131
public static final String SIGNATURE_VALIDATOR = "ch.swisscom.mid.signatureValidator";
32+
public static final String STATUS_QUERY_MODEL_UTILS = "ch.swisscom.mid.client.rest.statusQueryModelUtils";
33+
public static final String SIGN_REQ_MODEL_UTILS = "ch.swisscom.mid.client.rest.signatureRequestModelUtils";
3234

3335
// ----------------------------------------------------------------------------------------------------
3436

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
*
3+
* * Copyright 2021-2026 Swisscom (Schweiz) AG
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * http://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
package ch.swisscom.mid.client.model;
20+
21+
public class App2App {
22+
private String redirectUri;
23+
24+
public String getRedirectUri() {
25+
return redirectUri;
26+
}
27+
28+
public void setRedirectUri(String redirectUri) {
29+
this.redirectUri = redirectUri;
30+
}
31+
32+
@Override
33+
public String toString() {
34+
return "App2App{" +
35+
"redirectUri='" + redirectUri + '\'' +
36+
'}';
37+
}
38+
}

mid-java-client-core/src/main/java/ch/swisscom/mid/client/model/SignatureRequest.java

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@
1515
*/
1616
package ch.swisscom.mid.client.model;
1717

18-
import java.util.ArrayList;
19-
import java.util.List;
20-
2118
import ch.swisscom.mid.client.config.DefaultConfiguration;
2219
import ch.swisscom.mid.client.config.TrafficObserver;
20+
import ch.swisscom.mid.client.model.service.AdditionalService;
21+
import ch.swisscom.mid.client.model.service.UserLangAdditionalService;
2322

24-
import static ch.swisscom.mid.client.utils.Utils.dataNotEmpty;
25-
import static ch.swisscom.mid.client.utils.Utils.dataNotNull;
26-
import static ch.swisscom.mid.client.utils.Utils.dataTrue;
23+
import java.util.ArrayList;
24+
import java.util.List;
25+
26+
import static ch.swisscom.mid.client.utils.Utils.*;
2727

2828
public class SignatureRequest {
2929

@@ -35,7 +35,7 @@ public class SignatureRequest {
3535
* If this is not set then the ID from {@link ch.swisscom.mid.client.config.ClientConfiguration} is used.
3636
*/
3737
private String overrideApId;
38-
38+
3939
/**
4040
* Optional custom AP password that will override the AP password configured via {@link ch.swisscom.mid.client.config.ClientConfiguration}.
4141
* If this is not set then the password from {@link ch.swisscom.mid.client.config.ClientConfiguration} is used.
@@ -152,22 +152,22 @@ public void validateYourself() {
152152
dataNotEmpty(majorVersion, "The major version cannot be null or empty (see DefaultConfiguration for default values)");
153153
dataNotEmpty(minorVersion, "The minor version cannot be null or empty (see DefaultConfiguration for default values)");
154154
dataNotEmpty(additionalServices, "Invalid signature request configuration. " +
155-
"At least the UserLang additional service needs to be configured (call setUserLanguage).");
155+
"At least the UserLang additional service needs to be configured (call setUserLanguage).");
156156
dataNotNull(dataToBeSigned, "The data to be signed cannot be null (call setDataToBeSigned)");
157157
dataToBeSigned.validateYourself();
158158
dataNotNull(mobileUser, "The target mobile user cannot be null");
159159
mobileUser.validateYourself();
160160
dataNotEmpty(signatureProfile, "The signature profile cannot be null or empty. See " +
161-
SignatureProfiles.class.getSimpleName() +
162-
" for a list of possible profiles to choose from");
161+
SignatureProfiles.class.getSimpleName() +
162+
" for a list of possible profiles to choose from");
163163
dataTrue(userResponseTimeOutInSeconds >= DefaultConfiguration.SIGNATURE_MINIMUM_TIME_OUT_IN_SECONDS,
164-
"The user response timeout cannot be lower than " +
165-
DefaultConfiguration.SIGNATURE_MINIMUM_TIME_OUT_IN_SECONDS +
166-
" seconds");
164+
"The user response timeout cannot be lower than " +
165+
DefaultConfiguration.SIGNATURE_MINIMUM_TIME_OUT_IN_SECONDS +
166+
" seconds");
167167
dataTrue(userResponseTimeOutInSeconds <= DefaultConfiguration.SIGNATURE_MAXIMUM_TIME_OUT_IN_SECONDS,
168-
"The user response timeout cannot be higher than " +
169-
DefaultConfiguration.SIGNATURE_MAXIMUM_TIME_OUT_IN_SECONDS +
170-
" seconds");
168+
"The user response timeout cannot be higher than " +
169+
DefaultConfiguration.SIGNATURE_MAXIMUM_TIME_OUT_IN_SECONDS +
170+
" seconds");
171171
}
172172

173173
// ----------------------------------------------------------------------------------------------------
@@ -177,14 +177,14 @@ public void validateYourself() {
177177
@Override
178178
public String toString() {
179179
return "SignatureRequest{" +
180-
"majorVersion='" + majorVersion + '\'' +
181-
", minorVersion='" + minorVersion + '\'' +
182-
", additionalServices=" + additionalServices +
183-
", dataToBeSigned=" + dataToBeSigned +
184-
", mobileUser=" + mobileUser +
185-
", userResponseTimeOutInSeconds=" + userResponseTimeOutInSeconds +
186-
", signatureProfile='" + signatureProfile + '\'' +
187-
", trafficObserver=" + trafficObserver +
188-
'}';
180+
"majorVersion='" + majorVersion + '\'' +
181+
", minorVersion='" + minorVersion + '\'' +
182+
", additionalServices=" + additionalServices +
183+
", dataToBeSigned=" + dataToBeSigned +
184+
", mobileUser=" + mobileUser +
185+
", userResponseTimeOutInSeconds=" + userResponseTimeOutInSeconds +
186+
", signatureProfile='" + signatureProfile + '\'' +
187+
", trafficObserver=" + trafficObserver +
188+
'}';
189189
}
190190
}

mid-java-client-core/src/main/java/ch/swisscom/mid/client/model/AdditionalService.java renamed to mid-java-client-core/src/main/java/ch/swisscom/mid/client/model/service/AdditionalService.java

Lines changed: 65 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,65 @@
1-
/*
2-
* Copyright 2021 Swisscom (Schweiz) AG
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
package ch.swisscom.mid.client.model;
17-
18-
/**
19-
* Base class for requesting additional services via requests to the Mobile ID service. You can either make an instance of this class
20-
* and set the URI by yourself, or use one of the provided subclasses. There is also a corresponding {@link AdditionalServiceResponse}
21-
* that contains, as expected, the data that is returned as part of the requested additional service payload.
22-
*
23-
* @see UserLangAdditionalService
24-
* @see SignatureValidationAdditionalService
25-
* @see GeofencingAdditionalService
26-
*/
27-
public class AdditionalService {
28-
29-
private final String uri;
30-
31-
public AdditionalService(String uri) {
32-
this.uri = uri;
33-
}
34-
35-
public String getUri() {
36-
return uri;
37-
}
38-
39-
@Override
40-
public String toString() {
41-
return "AdditionalService{" +
42-
"uri='" + uri + '\'' +
43-
'}';
44-
}
45-
}
1+
/*
2+
*
3+
* * Copyright 2021-2026 Swisscom (Schweiz) AG
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * http://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
/*
20+
* Copyright 2021 Swisscom (Schweiz) AG
21+
*
22+
* Licensed under the Apache License, Version 2.0 (the "License");
23+
* you may not use this file except in compliance with the License.
24+
* You may obtain a copy of the License at
25+
*
26+
* http://www.apache.org/licenses/LICENSE-2.0
27+
*
28+
* Unless required by applicable law or agreed to in writing, software
29+
* distributed under the License is distributed on an "AS IS" BASIS,
30+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31+
* See the License for the specific language governing permissions and
32+
* limitations under the License.
33+
*/
34+
package ch.swisscom.mid.client.model.service;
35+
36+
import ch.swisscom.mid.client.model.AdditionalServiceResponse;
37+
38+
/**
39+
* Base class for requesting additional services via requests to the Mobile ID service. You can either make an instance of this class
40+
* and set the URI by yourself, or use one of the provided subclasses. There is also a corresponding {@link AdditionalServiceResponse}
41+
* that contains, as expected, the data that is returned as part of the requested additional service payload.
42+
*
43+
* @see UserLangAdditionalService
44+
* @see SignatureValidationAdditionalService
45+
* @see GeofencingAdditionalService
46+
*/
47+
public class AdditionalService {
48+
49+
private final String uri;
50+
51+
public AdditionalService(String uri) {
52+
this.uri = uri;
53+
}
54+
55+
public String getUri() {
56+
return uri;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return "AdditionalService{" +
62+
"uri='" + uri + '\'' +
63+
'}';
64+
}
65+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
*
3+
* * Copyright 2021-2026 Swisscom (Schweiz) AG
4+
* *
5+
* * Licensed under the Apache License, Version 2.0 (the "License");
6+
* * you may not use this file except in compliance with the License.
7+
* * You may obtain a copy of the License at
8+
* *
9+
* * http://www.apache.org/licenses/LICENSE-2.0
10+
* *
11+
* * Unless required by applicable law or agreed to in writing, software
12+
* * distributed under the License is distributed on an "AS IS" BASIS,
13+
* * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* * See the License for the specific language governing permissions and
15+
* * limitations under the License.
16+
*
17+
*/
18+
19+
/*
20+
* Copyright 2021 Swisscom (Schweiz) AG
21+
*
22+
* Licensed under the Apache License, Version 2.0 (the "License");
23+
* you may not use this file except in compliance with the License.
24+
* You may obtain a copy of the License at
25+
*
26+
* http://www.apache.org/licenses/LICENSE-2.0
27+
*
28+
* Unless required by applicable law or agreed to in writing, software
29+
* distributed under the License is distributed on an "AS IS" BASIS,
30+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31+
* See the License for the specific language governing permissions and
32+
* limitations under the License.
33+
*/
34+
package ch.swisscom.mid.client.model.service;
35+
36+
import ch.swisscom.mid.client.config.DefaultConfiguration;
37+
import ch.swisscom.mid.client.model.App2App;
38+
39+
public class App2AppAdditionalService extends AdditionalService {
40+
41+
private App2App app2app;
42+
43+
public App2AppAdditionalService() {
44+
super(DefaultConfiguration.ADDITIONAL_SERVICE_APP2APP);
45+
46+
}
47+
48+
public App2AppAdditionalService(String redirectUri) {
49+
super(DefaultConfiguration.ADDITIONAL_SERVICE_APP2APP);
50+
this.app2app = new App2App();
51+
this.app2app.setRedirectUri(redirectUri);
52+
53+
}
54+
55+
public App2App getApp2app() {
56+
return app2app;
57+
}
58+
59+
public void setApp2app(App2App app2app) {
60+
this.app2app = app2app;
61+
}
62+
}

0 commit comments

Comments
 (0)