--- /dev/null
+/*******************************************************************************\r
+ * ============LICENSE_START====================================================\r
+ * * org.onap.aaf\r
+ * * ===========================================================================\r
+ * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
+ * * ===========================================================================\r
+ * * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * * you may not use this file except in compliance with the License.\r
+ * * You may obtain a copy of the License at\r
+ * * \r
+ * * http://www.apache.org/licenses/LICENSE-2.0\r
+ * * \r
+ * * Unless required by applicable law or agreed to in writing, software\r
+ * * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * * See the License for the specific language governing permissions and\r
+ * * limitations under the License.\r
+ * * ============LICENSE_END====================================================\r
+ * *\r
+ * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
+ * *\r
+ ******************************************************************************/\r
+package org.onap.aaf.authz.cadi;\r
+\r
+import java.nio.ByteBuffer;\r
+import java.security.Principal;\r
+import java.security.cert.CertificateException;\r
+import java.security.cert.X509Certificate;\r
+import java.util.List;\r
+\r
+import javax.servlet.http.HttpServletRequest;\r
+\r
+import org.onap.aaf.authz.env.AuthzTrans;\r
+import org.onap.aaf.authz.layer.Result;\r
+import org.onap.aaf.cssa.rserv.TransFilter;\r
+import org.onap.aaf.dao.aaf.cached.CachedCertDAO;\r
+import org.onap.aaf.dao.aaf.cass.CertDAO.Data;\r
+\r
+import org.onap.aaf.cadi.principal.X509Principal;\r
+import org.onap.aaf.cadi.taf.cert.CertIdentity;\r
+import org.onap.aaf.cadi.taf.cert.X509Taf;\r
+\r
+/**\r
+ * Direct view of CertIdentities\r
+ * \r
+ * Warning: this class is difficult to instantiate. The only service that can use it is AAF itself, and is thus \r
+ * entered in the "init" after the CachedCertDAO is created.\r
+ * \r
+ *\r
+ */\r
+public class DirectCertIdentity implements CertIdentity {\r
+ private static CachedCertDAO certDAO;\r
+\r
+ @Override\r
+ public Principal identity(HttpServletRequest req, X509Certificate cert, byte[] _certBytes) throws CertificateException {\r
+ byte[] certBytes = _certBytes;\r
+ if(cert==null && certBytes==null) {\r
+ return null;\r
+ }\r
+ if(certBytes==null) {\r
+ certBytes = cert.getEncoded();\r
+ }\r
+ byte[] fingerprint = X509Taf.getFingerPrint(certBytes);\r
+\r
+ AuthzTrans trans = (AuthzTrans) req.getAttribute(TransFilter.TRANS_TAG);\r
+ \r
+ Result<List<Data>> cresp = certDAO.read(trans, ByteBuffer.wrap(fingerprint));\r
+ if(cresp.isOKhasData()) {\r
+ Data cdata = cresp.value.get(0);\r
+ return new X509Principal(cdata.id,cert,certBytes);\r
+ }\r
+ return null;\r
+ }\r
+\r
+ public static void set(CachedCertDAO ccd) {\r
+ certDAO = ccd;\r
+ }\r
+\r
+}\r