AT&T 2.0.19 Code drop, stage 4
[aaf/authz.git] / authz-service / src / main / java / org / onap / aaf / authz / cadi / DirectAAFUserPass.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.authz.cadi;\r
24 \r
25 import static org.onap.aaf.authz.layer.Result.OK;\r
26 \r
27 import java.util.Date;\r
28 \r
29 import org.onap.aaf.authz.env.AuthzEnv;\r
30 import org.onap.aaf.authz.env.AuthzTrans;\r
31 import org.onap.aaf.authz.layer.Result;\r
32 import org.onap.aaf.dao.DAOException;\r
33 import org.onap.aaf.dao.aaf.hl.Question;\r
34 \r
35 import org.onap.aaf.cadi.CredVal;\r
36 \r
37 /**\r
38  * DirectAAFUserPass is intended to provide password Validation directly from Cassandra Database, and is only\r
39  * intended for use in AAF itself.  The normal "AAF Taf" objects are, of course, clients.\r
40  * \r
41  *\r
42  */\r
43 public class DirectAAFUserPass implements CredVal {\r
44                 private final AuthzEnv env;\r
45         private final Question question;\r
46         \r
47         public DirectAAFUserPass(AuthzEnv env, Question question, String appPass) {\r
48                 this.env = env;\r
49                 this.question = question;\r
50         }\r
51         \r
52         @Override\r
53         public boolean validate(String user, Type type, byte[] pass) {\r
54                 try {\r
55                         AuthzTrans trans = env.newTransNoAvg();\r
56                         Result<Date> result = question.doesUserCredMatch(trans, user, pass);\r
57                         trans.logAuditTrail(env.info());\r
58                         switch(result.status) {\r
59                                 case OK:\r
60                                         return true;\r
61                                 default:\r
62                                         \r
63                                         env.warn().log(user, "failed Password Validation:",result.errorString());\r
64                         }\r
65                 } catch (DAOException e) {\r
66                         System.out.println(" exception in DirectAAFUserPass class ");\r
67                         e.printStackTrace();\r
68                         env.error().log(e,"Cannot validate User/Pass from Cassandra");\r
69                 }\r
70                 return false;\r
71         }\r
72 \r
73 \r
74 }\r