hc
2023-02-13 e440ec23c5a540cdd3f7464e8779219be6fd3d95
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
 * Copyright 2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * You may not use this file except in compliance with the License. A copy of the License is located the "LICENSE.txt"
 * file accompanying this source. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the specific language governing permissions and limitations
 * under the License.
 */
package com.rockchip.alexa.jacky.info;
 
import com.rockchip.alexa.jacky.app.AuthConstants;
 
import org.apache.commons.lang3.StringUtils;
 
import java.util.ArrayList;
import java.util.List;
 
public class DeviceProvisioningInfo {
    private String productId;
    private String dsn;
    private String sessionId;
    private String codeVerifier;
    private String codeChallenge;
    private String codeChallengeMethod;
 
    public DeviceProvisioningInfo(String productId, String dsn, String sessionId, String codeChallenge, String codeChallengeMethod, String codeVerifier) {
        List<String> missingParameters = new ArrayList<String>();
        if (StringUtils.isBlank(productId)) {
            missingParameters.add(AuthConstants.PRODUCT_ID);
        }
 
        if (StringUtils.isBlank(dsn)) {
            missingParameters.add(AuthConstants.DSN);
        }
 
        if (StringUtils.isBlank(sessionId)) {
            missingParameters.add(AuthConstants.SESSION_ID);
        }
 
        if (StringUtils.isBlank(codeChallenge)) {
            missingParameters.add(AuthConstants.CODE_CHALLENGE);
        }
 
        if (StringUtils.isBlank(codeChallengeMethod)) {
            missingParameters.add(AuthConstants.CODE_CHALLENGE_METHOD);
        }
 
        if (missingParameters.size() != 0) {
            throw new MissingParametersException(missingParameters);
        }
 
        this.productId = productId;
        this.dsn = dsn;
        this.sessionId = sessionId;
        this.codeChallenge = codeChallenge;
        this.codeChallengeMethod = codeChallengeMethod;
        this.codeVerifier = codeVerifier;
    }
 
    public String getProductId() {
        return productId;
    }
 
    public String getDsn() {
        return dsn;
    }
 
    public String getSessionId() {
        return sessionId;
    }
 
    public String getCodeChallenge() {
        return codeChallenge;
    }
 
    public String getCodeChallengeMethod() {
        return codeChallengeMethod;
    }
 
    public void setSessionId(String sessionId) {
        this.sessionId = sessionId;
    }
 
    public void setDsn(String dsn) {
        this.dsn = dsn;
    }
 
    public void setProductId(String productId) {
        this.productId = productId;
    }
 
    public void setCodeChallenge(String codeChallenge) {
        this.codeChallenge = codeChallenge;
    }
 
    public void setCodeChallengeMethod(String codeChallengeMethod) {
        this.codeChallengeMethod = codeChallengeMethod;
    }
 
    public String getCodeVerifier() {
        return codeVerifier;
    }
 
    public void setCodeVerifier(String codeVerifier) {
        this.codeVerifier = codeVerifier;
    }
 
    public static class MissingParametersException extends IllegalArgumentException {
        private static final long serialVersionUID = 1L;
        private final List<String> missingParameters;
 
        public MissingParametersException(List<String> missingParameters) {
            super();
            this.missingParameters = missingParameters;
        }
 
        @Override
        public String getMessage() {
            return "The following parameters were missing or empty strings: "
                    + StringUtils.join(missingParameters.toArray(), ", ");
        }
 
        public List<String> getMissingParameters() {
            return missingParameters;
        }
    }
}