2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
22 package org.onap.aaf.auth.direct;
24 import static org.onap.aaf.auth.layer.Result.OK;
26 import java.util.Date;
28 import javax.servlet.http.HttpServletRequest;
30 import org.onap.aaf.auth.dao.DAOException;
31 import org.onap.aaf.auth.dao.hl.Question;
32 import org.onap.aaf.auth.env.AuthzEnv;
33 import org.onap.aaf.auth.env.AuthzTrans;
34 import org.onap.aaf.auth.layer.Result;
35 import org.onap.aaf.cadi.CredVal;
38 * DirectAAFUserPass is intended to provide password Validation directly from Cassandra Database, and is only
39 * intended for use in AAF itself. The normal "AAF Taf" objects are, of course, clients.
44 public class DirectAAFUserPass implements CredVal {
45 private final AuthzEnv env;
46 private final Question question;
48 public DirectAAFUserPass(AuthzEnv env, Question question) {
50 this.question = question;
54 public boolean validate(String user, Type type, byte[] pass, Object state) {
55 if(user==null || type==null || pass==null) {
61 boolean transfer = false;
63 if (state instanceof AuthzTrans) {
64 trans = (AuthzTrans)state;
66 trans = env.newTransNoAvg();
67 if (state instanceof HttpServletRequest) {
68 trans.set((HttpServletRequest)state,null);
73 trans = env.newTransNoAvg();
75 Result<Date> result = question.doesUserCredMatch(trans, user, pass);
77 ((HttpServletRequest)state).setAttribute("CRED_TAG", trans.getTag());
79 trans.logAuditTrail(env.debug());
80 switch(result.status) {
84 String ip = trans.ip()==null?"":trans.ip();
85 env.audit().printf("user=%s,tag=%s,ip=%s,msg=\"failed password validation: %s\"",user,trans.getTag(),ip,result.errorString());
87 } catch (DAOException e) {
88 env.error().log(e,"Cannot validate user/pass from cassandra");