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) {
58 if(state instanceof AuthzTrans) {
59 trans = (AuthzTrans)state;
61 trans = env.newTransNoAvg();
62 if(state instanceof HttpServletRequest) {
63 trans.set((HttpServletRequest)state);
67 trans = env.newTransNoAvg();
69 Result<Date> result = question.doesUserCredMatch(trans, user, pass);
70 trans.logAuditTrail(env.info());
71 switch(result.status) {
75 String ip = trans.ip()==null?"":(", ip="+trans.ip());
76 env.warn().log(user, "failed password validation" + ip + ':',result.errorString());
78 } catch (DAOException e) {
79 env.error().log(e,"Cannot validate user/pass from cassandra");