1 package org.apache.archiva.redback.integration.taglib.jsp;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.archiva.redback.authorization.AuthorizationException;
23 import org.apache.archiva.redback.system.SecuritySession;
24 import org.apache.archiva.redback.system.SecuritySystem;
25 import org.apache.archiva.redback.system.SecuritySystemConstants;
26 import org.springframework.context.ApplicationContext;
27 import org.springframework.web.context.support.WebApplicationContextUtils;
29 import javax.servlet.jsp.JspTagException;
30 import javax.servlet.jsp.jstl.core.ConditionalTagSupport;
35 * @author Jesse McConnell <jesse@codehaus.org>
38 public class IfAuthorizedTag
39 extends ConditionalTagSupport
41 private String permission;
43 private String resource;
45 public void setPermission( String permission )
47 this.permission = permission;
50 public void setResource( String resource )
52 this.resource = resource;
55 protected boolean condition()
56 throws JspTagException
58 ApplicationContext applicationContext =
59 WebApplicationContextUtils.getRequiredWebApplicationContext( pageContext.getServletContext() );
61 Boolean authzStatusBool = (Boolean) pageContext.getAttribute( "redbackCache" + permission + resource );
64 //long execTime = System.currentTimeMillis();
66 if ( authzStatusBool == null )
68 SecuritySession securitySession =
69 (SecuritySession) pageContext.getSession().getAttribute( SecuritySystemConstants.SECURITY_SESSION_KEY );
73 SecuritySystem securitySystem = applicationContext.getBean( "securitySystem", SecuritySystem.class );
74 if ( securitySystem == null )
76 throw new JspTagException( "unable to locate security system" );
79 authzStatus = securitySystem.isAuthorized( securitySession, permission, resource );
80 pageContext.setAttribute( "redbackCache" + permission + resource, Boolean.valueOf( authzStatus ) );
82 catch ( AuthorizationException ae )
84 throw new JspTagException( "error with authorization", ae );
87 //System.out.println( "[PERF] " + "redbackCache" + permission + resource + " Time: " + (System.currentTimeMillis() - execTime) );
91 authzStatus = authzStatusBool.booleanValue();
92 //System.out.println( "[PERF][Cached] " + "redbackCache" + permission + resource + " Time: " + (System.currentTimeMillis() - execTime) );
95 pageContext.setAttribute( "ifAuthorizedTag", Boolean.valueOf( authzStatus ) );