316254 Implement @DeclareRoles
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1953 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
5c53c9ac55
commit
64e78003fb
|
@ -22,6 +22,7 @@ jetty-7.1.4-SNAPSHOT
|
|||
+ 315925 Improved context xml configuration handling
|
||||
+ 315995 Incorrect package name in system classes list
|
||||
+ 316119 Fixed maxIdleTime for SocketEndPoint
|
||||
+ 316254 Implement @DeclareRoles
|
||||
+ JETTY-547 Delay close after shutdown until request read
|
||||
+ JETTY-1231 Support context request log handler
|
||||
|
||||
|
|
|
@ -56,6 +56,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
parser.registerAnnotationHandler("javax.annotation.PostConstruct", new PostConstructAnnotationHandler(context));
|
||||
parser.registerAnnotationHandler("javax.annotation.PreDestroy", new PreDestroyAnnotationHandler(context));
|
||||
parser.registerAnnotationHandler("javax.annotation.security.RunAs", new RunAsAnnotationHandler(context));
|
||||
parser.registerAnnotationHandler("javax.annotation.security.DeclareRoles", new DeclareRolesAnnotationHandler(context));
|
||||
|
||||
ClassInheritanceHandler classHandler = new ClassInheritanceHandler();
|
||||
parser.registerClassHandler(classHandler);
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2010 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
|
||||
package org.eclipse.jetty.annotations;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.AnnotationHandler;
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.ListValue;
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.SimpleValue;
|
||||
import org.eclipse.jetty.annotations.AnnotationParser.Value;
|
||||
import org.eclipse.jetty.security.ConstraintSecurityHandler;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
public class DeclareRolesAnnotationHandler implements AnnotationHandler
|
||||
{
|
||||
protected WebAppContext _wac;
|
||||
|
||||
public DeclareRolesAnnotationHandler (WebAppContext wac)
|
||||
{
|
||||
_wac = wac;
|
||||
}
|
||||
|
||||
/**
|
||||
* A DeclareRoles annotation is equivalent to a <security-role> in web.xml.
|
||||
*
|
||||
* @see org.eclipse.jetty.annotations.AnnotationParser.AnnotationHandler#handleClass(java.lang.String, int, int, java.lang.String, java.lang.String, java.lang.String[], java.lang.String, java.util.List)
|
||||
*/
|
||||
public void handleClass(String className, int version, int access, String signature, String superName, String[] interfaces, String annotation,
|
||||
List<Value> values)
|
||||
{
|
||||
//Add the role names to the list of roles for the webapp
|
||||
Set<String> roles = new HashSet<String>();
|
||||
|
||||
try
|
||||
{
|
||||
Set<String> existing = ((ConstraintSecurityHandler)_wac.getSecurityHandler()).getRoles();
|
||||
roles.addAll(existing);
|
||||
|
||||
if (values != null && values.size() == 1)
|
||||
{
|
||||
Value v = values.get(0);
|
||||
if (v instanceof SimpleValue)
|
||||
{
|
||||
roles.add((String)((SimpleValue)v).getValue());
|
||||
}
|
||||
else if (v instanceof ListValue)
|
||||
{
|
||||
for (Value vv:((ListValue)v).getList())
|
||||
{
|
||||
roles.add((String)((SimpleValue)vv).getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleField(String className, String fieldName, int access, String fieldType, String signature, Object value, String annotation,
|
||||
List<Value> values)
|
||||
{
|
||||
Log.warn ("@DeclareRoles annotation not applicable for field: "+className+"."+fieldName);
|
||||
}
|
||||
|
||||
public void handleMethod(String className, String methodName, int access, String desc, String signature, String[] exceptions, String annotation,
|
||||
List<Value> values)
|
||||
{
|
||||
Log.warn ("@DeclareRoles annotation not applicable for method: "+className+"."+methodName);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue