001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *      http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.apache.shiro.ee.faces.tags;
015
016import org.apache.shiro.SecurityUtils;
017import org.apache.shiro.subject.Subject;
018
019import javax.faces.component.UIOutput;
020import javax.faces.context.FacesContext;
021import java.io.IOException;
022
023/**
024 * Base class for JSF components.
025 *
026 * <p>OBS: Your subclass is responsible for saving the state of the component.
027 * See {@link org.apache.shiro.ee.faces.tags.PrincipalTag}'s
028 * StateHolder Methods for an example.
029 */
030public abstract class SecureComponent extends UIOutput {
031    protected Subject getSubject() {
032        return SecurityUtils.getSubject();
033    }
034
035    @Override
036    public void encodeEnd(FacesContext ctx) throws IOException {
037        verifyAttributes();
038        doEncodeAll(ctx);
039    }
040
041    protected void verifyAttributes() throws IOException {
042    }
043
044    protected abstract void doEncodeAll(FacesContext ctx) throws IOException;
045}