1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 2017 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====================================================
21 ******************************************************************************/
22 package org.onap.aaf.auth.gui;
24 import java.io.IOException;
25 import java.security.Principal;
27 import javax.servlet.Filter;
28 import javax.servlet.FilterChain;
29 import javax.servlet.FilterConfig;
30 import javax.servlet.ServletException;
31 import javax.servlet.ServletRequest;
32 import javax.servlet.ServletResponse;
33 import javax.servlet.http.HttpServletRequest;
35 import org.onap.aaf.auth.env.AuthzTrans;
36 import org.onap.aaf.auth.org.OrganizationException;
37 import org.onap.aaf.auth.org.Organization.Identity;
38 import org.onap.aaf.auth.rserv.TransFilter;
39 import org.onap.aaf.cadi.CadiException;
40 import org.onap.aaf.cadi.principal.TaggedPrincipal;
42 public class OrgLookupFilter implements Filter {
45 public void init(FilterConfig arg0) throws ServletException {
49 public void doFilter(ServletRequest req, ServletResponse resp, FilterChain fc) throws IOException, ServletException {
50 final AuthzTrans trans = (AuthzTrans) req.getAttribute(TransFilter.TRANS_TAG);
51 if (req instanceof HttpServletRequest) {
52 Principal p = ((HttpServletRequest)req).getUserPrincipal();
53 if (p instanceof TaggedPrincipal) {
54 ((TaggedPrincipal)p).setTagLookup(new TaggedPrincipal.TagLookup() {
56 public String lookup() throws CadiException {
59 id = trans.org().getIdentity(trans, p.getName());
60 if (id!=null && id.isFound()) {
61 return id.firstName();
63 } catch (OrganizationException e) {
64 throw new CadiException(e);
70 fc.doFilter(req, resp);
77 public void destroy() {