[AAF-21] Initial code import
[aaf/authz.git] / authz-service / src / main / java / com / att / authz / cadi / DirectAAFUserPass.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.att.authz.cadi;\r
25 \r
26 import static com.att.authz.layer.Result.OK;\r
27 \r
28 import java.util.Date;\r
29 \r
30 import com.att.authz.env.AuthzEnv;\r
31 import com.att.authz.env.AuthzTrans;\r
32 import com.att.authz.layer.Result;\r
33 import com.att.cadi.CredVal;\r
34 import com.att.dao.DAOException;\r
35 import com.att.dao.aaf.hl.Question;\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