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