Sonar Fixes, Formatting
[aaf/authz.git] / cadi / oauth-enduser / src / main / java / org / onap / aaf / cadi / enduser / ClientFactory.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21 package org.onap.aaf.cadi.enduser;
22
23 import java.io.IOException;
24 import java.net.URISyntaxException;
25 import java.security.GeneralSecurityException;
26
27 import org.onap.aaf.cadi.Access;
28 import org.onap.aaf.cadi.CadiException;
29 import org.onap.aaf.cadi.LocatorException;
30 import org.onap.aaf.cadi.PropAccess;
31 import org.onap.aaf.cadi.config.Config;
32 import org.onap.aaf.cadi.oauth.TokenClientFactory;
33 import org.onap.aaf.misc.env.APIException;
34
35 public class ClientFactory {
36     private final TokenClientFactory tcf;
37     public ClientFactory(final PropAccess access) throws APIException, CadiException {
38         try {
39             tcf = TokenClientFactory.instance(access);
40         } catch (GeneralSecurityException | IOException e) {
41             throw new CadiException(e);
42         }
43     }
44
45     public ClientFactory(String[] args) throws APIException, CadiException {
46         this(new PropAccess(args));
47     }
48
49     public SimpleRESTClient simpleRESTClient(final String endpoint, final String ... scopes) throws URISyntaxException, LocatorException, CadiException, APIException {
50         return new SimpleRESTClient(tcf, Config.AAF_OAUTH2_TOKEN_URL, endpoint, scopes);
51     }
52
53     public Access getAccess() {
54         return tcf.access;
55     }
56 }