Change: add OPEN-O seed code for VF-C
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / main / java / org / openo / nfvo / vnfmadapter / service / process / AuthMgr.java
1 /*
2  * Copyright 2016 Huawei Technologies Co., Ltd.
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
17 package org.openo.nfvo.vnfmadapter.service.process;
18
19 import org.openo.nfvo.vnfmadapter.service.constant.Constant;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22
23 import net.sf.json.JSONException;
24 import net.sf.json.JSONObject;
25
26 /**
27  * Provide function for authInfo.
28  * <br/>
29  *
30  * @author
31  * @version NFVO 0.5 Aug 24, 2016
32  */
33 public class AuthMgr {
34
35     private static final Logger LOG = LoggerFactory.getLogger(AuthMgr.class);
36
37     /**
38      * Provide function for add authInfo.
39      * <br/>
40      *
41      * @param params
42      * @return
43      * @since NFVO 0.5
44      */
45     public JSONObject authToken(JSONObject params) {
46         JSONObject restJson = new JSONObject();
47         restJson.put(Constant.RETCODE, Constant.REST_FAIL);
48         try {
49             String userName = params.getString("userName");
50
51             restJson = getStatusResult(userName);
52         } catch(JSONException e) {
53             LOG.error("function=login, msg=Params error occurs, e={}.", e);
54             restJson.put("data", "JSONException");
55             return restJson;
56         }
57         return restJson;
58     }
59
60     private JSONObject getStatusResult(String userName) {
61         JSONObject restJson = new JSONObject();
62         JSONObject authResult = new JSONObject();
63         JSONObject addInfo = new JSONObject();
64         authResult.put("accessSession", "1234");
65         authResult.put("roaRand", "RoaRand");
66         authResult.put("expires", 1800);
67         addInfo.put("expires", 10);
68         addInfo.put("passwdStatus", "expiring");
69         authResult.put("additionalInfo", addInfo);
70         restJson.put("retCode", Constant.REST_SUCCESS);
71         restJson.put("data", authResult);
72         return restJson;
73     }
74 }