/*- * ============LICENSE_START======================================================= * ONAP CLAMP * ================================================================================ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights * reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END============================================ * =================================================================== * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.clamp.clds.config; import java.security.Principal; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; /** * Overwrite the key method isUserInRole and getUserPrincipal, to adapt to the Clamp default user verification */ public class ClampUserWrap extends HttpServletRequestWrapper { private String user; private List roles = null; private HttpServletRequest realRequest; /** * Standard Wrapper constructor for Delegate pattern * @param request */ public ClampUserWrap(HttpServletRequest request, String userName, List roles){ super(request); this.user = userName; this.roles = roles; this.realRequest = request; } @Override public boolean isUserInRole(String role) { if (roles == null) { return this.realRequest.isUserInRole(role); } return roles.contains(role); } @Override public Principal getUserPrincipal() { if (this.user == null) { return realRequest.getUserPrincipal(); } // make an anonymous implementation to just return our user return new Principal() { @Override public String getName() { return user; } }; } }