Add Notice of aaf/cadi source moving to aaf/authz
[aaf/cadi.git] / client / src / main / java / org / onap / aaf / cadi / http / HBasicAuthSS.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aaf\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 package org.onap.aaf.cadi.http;\r
24 \r
25 import java.io.IOException;\r
26 import java.net.HttpURLConnection;\r
27 \r
28 import javax.net.ssl.HttpsURLConnection;\r
29 \r
30 import org.onap.aaf.cadi.Access;\r
31 import org.onap.aaf.cadi.CadiException;\r
32 import org.onap.aaf.cadi.client.AbsBasicAuth;\r
33 import org.onap.aaf.cadi.config.Config;\r
34 import org.onap.aaf.cadi.config.SecurityInfoC;\r
35 import org.onap.aaf.cadi.principal.BasicPrincipal;\r
36 \r
37 public class HBasicAuthSS extends AbsBasicAuth<HttpURLConnection> {\r
38         public HBasicAuthSS(Access access, SecurityInfoC<HttpURLConnection> si) throws IOException {\r
39                 super(access.getProperty(Config.AAF_MECHID, null),\r
40                                 access.decrypt(access.getProperty(Config.AAF_MECHPASS, null), false),\r
41                                 si);\r
42         }\r
43 \r
44         public HBasicAuthSS(String user, String pass, SecurityInfoC<HttpURLConnection> si) throws IOException {\r
45                 super(user,pass,si);\r
46         }\r
47 \r
48         public HBasicAuthSS(String user, String pass, SecurityInfoC<HttpURLConnection> si, boolean asDefault) throws IOException {\r
49                 super(user,pass,si);\r
50                 if(asDefault) {\r
51                         si.set(this);\r
52                 }\r
53         }\r
54         \r
55         public HBasicAuthSS(BasicPrincipal bp, SecurityInfoC<HttpURLConnection> si) throws IOException {\r
56                 super(bp.getName(),new String(bp.getCred()),si);\r
57         }\r
58         \r
59         public HBasicAuthSS(BasicPrincipal bp, SecurityInfoC<HttpURLConnection> si, boolean asDefault) throws IOException {\r
60                 super(bp.getName(),new String(bp.getCred()),si);\r
61                 if(asDefault) {\r
62                         si.set(this);\r
63                 }\r
64         }\r
65 \r
66         @Override\r
67         public void setSecurity(HttpURLConnection huc) throws CadiException {\r
68                 if(isDenied()) {\r
69                         throw new CadiException(REPEAT_OFFENDER);\r
70                 }\r
71                 huc.addRequestProperty("Authorization" , headValue);\r
72                 if(securityInfo!=null && huc instanceof HttpsURLConnection) {\r
73                         securityInfo.setSocketFactoryOn((HttpsURLConnection)huc);\r
74                 }\r
75         }\r
76 }\r