本文整理汇总了Java中org.apache.shiro.authz.annotation.RequiresGuest类的典型用法代码示例。如果您正苦于以下问题:Java RequiresGuest类的具体用法?Java RequiresGuest怎么用?Java RequiresGuest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequiresGuest类属于org.apache.shiro.authz.annotation包,在下文中一共展示了RequiresGuest类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: scanAnnotation
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
/**
* 逐个扫描注解,若是相应的注解则在相应的位置赋值。
* 注解的处理是有顺序的,依次为RequiresRoles,RequiresPermissions,
* RequiresAuthentication,RequiresUser,RequiresGuest
*
* @param authzArray
* @param annotations
*/
private void scanAnnotation(List<AuthzHandler> authzArray,
List<Annotation> annotations) {
if (null == annotations || 0 == annotations.size()) {
return;
}
for (Annotation a : annotations) {
if (a instanceof RequiresRoles) {
authzArray.set(0, new RoleAuthzHandler(a));
} else if (a instanceof RequiresPermissions) {
authzArray.set(1, new PermissionAuthzHandler(a));
} else if (a instanceof RequiresAuthentication) {
authzArray.set(2, AuthenticatedAuthzHandler.me());
} else if (a instanceof RequiresUser) {
authzArray.set(3, UserAuthzHandler.me());
} else if (a instanceof RequiresGuest) {
authzArray.set(4, GuestAuthzHandler.me());
}
}
}
示例2: scanAnnotation
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
/**
* 逐个扫描注解,若是相应的注解则在相应的位置赋值。 注解的处理是有顺序的,依次为RequiresRoles,RequiresPermissions,
* RequiresAuthentication,RequiresUser,RequiresGuest
*/
private void scanAnnotation(List<AuthzHandler> authzArray,
List<Annotation> annotations) {
if (null == annotations || 0 == annotations.size()) {
return;
}
for (Annotation a : annotations) {
if (a instanceof RequiresRoles) {
authzArray.set(0, new RoleAuthzHandler(a));
} else if (a instanceof RequiresPermissions) {
authzArray.set(1, new PermissionAuthzHandler(a));
} else if (a instanceof RequiresAuthentication) {
authzArray.set(2, AuthenticatedAuthzHandler.me());
} else if (a instanceof RequiresUser) {
authzArray.set(3, UserAuthzHandler.me());
} else if (a instanceof RequiresGuest) {
authzArray.set(4, GuestAuthzHandler.me());
}
}
}
示例3: intercept
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
@Override
public Object intercept(AnnotationInterceptChain chain, Response response, Request request, RequiresGuest annotation) throws Throwable {
if (SecurityUtils.getSubject().getPrincipal() != null) {
throw new UnauthenticatedException("Attempting to perform a guest-only operation. The current Subject is " +
"not a guest (they have been authenticated or remembered from a previous login). Access " +
"denied.");
}
return chain.intercept();
}
示例4: createHandler
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
private static AuthorizingAnnotationHandler createHandler(Annotation annotation) {
Class<?> t = annotation.annotationType();
if (RequiresPermissions.class.equals(t)) return new PermissionAnnotationHandler();
else if (RequiresRoles.class.equals(t)) return new RoleAnnotationHandler();
else if (RequiresUser.class.equals(t)) return new UserAnnotationHandler();
else if (RequiresGuest.class.equals(t)) return new GuestAnnotationHandler();
else if (RequiresAuthentication.class.equals(t)) return new AuthenticatedAnnotationHandler();
else throw new IllegalArgumentException("Cannot create a handler for the unknown for annotation " + t);
}
示例5: configure
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
@Override
protected void configure() {
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RequiresRoles.class),
new ShiroMethodInterceptor(new RoleAnnotationMethodInterceptor()));
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RequiresUser.class),
new ShiroMethodInterceptor(new UserAnnotationMethodInterceptor()));
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RequiresPermissions.class),
new ShiroMethodInterceptor(new PermissionAnnotationMethodInterceptor()));
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RequiresGuest.class),
new ShiroMethodInterceptor(new GuestAnnotationMethodInterceptor()));
bindInterceptor(Matchers.any(), Matchers.annotatedWith(RequiresAuthentication.class),
new ShiroMethodInterceptor(new AuthenticatedAnnotationMethodInterceptor()));
}
示例6: interceptShiroSecurity
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
@AroundInvoke
public Object interceptShiroSecurity(InvocationContext context) throws Exception {
Subject subject = SecurityUtils.getSubject();
Class<?> c = context.getTarget().getClass();
Method m = context.getMethod();
if (!subject.isAuthenticated() && hasAnnotation(c, m, RequiresAuthentication.class)) {
throw new UnauthenticatedException("Authentication required");
}
if (subject.getPrincipal() != null && hasAnnotation(c, m, RequiresGuest.class)) {
throw new UnauthenticatedException("Guest required");
}
if (subject.getPrincipal() == null && hasAnnotation(c, m, RequiresUser.class)) {
throw new UnauthenticatedException("User required");
}
RequiresRoles roles = getAnnotation(c, m, RequiresRoles.class);
if (roles != null) {
subject.checkRoles(Arrays.asList(roles.value()));
}
RequiresPermissions permissions = getAnnotation(c, m, RequiresPermissions.class);
if (permissions != null) {
subject.checkPermissions(permissions.value());
}
return context.proceed();
}
示例7: generateShiroCodeForRequiresGuestCheck
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
public static void generateShiroCodeForRequiresGuestCheck(MethodSpec.Builder builder, RequiresGuest ann) throws IOException {
builder
.beginControlFlow("if (subject.getPrincipal() != null)")
.addStatement("throw new $T($S)",
UnauthenticatedException.class,
"Attempting to perform a guest-only operation. "
+ "The current Subject is not a guest (they have been authenticated or remembered from a previous login)."
+ " Access denied.")
.endControlFlow();
}
示例8: simple
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
@RequiresGuest
public String simple(final String name) {
return "hi " + name;
}
示例9: guestEcho
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
@Path("/")
@GET
@RequiresGuest
public String guestEcho() {
return "guest";
}
示例10: assertAuthorized
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
/**
* Ensures that the calling <code>Subject</code> is NOT a <em>user</em>, that is, they do not
* have an {@link org.apache.shiro.subject.Subject#getPrincipal() identity} before continuing. If they are
* a user ({@link org.apache.shiro.subject.Subject#getPrincipal() Subject.getPrincipal()} != null), an
* <code>AuthorizingException</code> will be thrown indicating that execution is not allowed to continue.
*
* @param a the annotation to check for one or more roles
* @throws org.apache.shiro.authz.AuthorizationException
* if the calling <code>Subject</code> is not a "guest".
*/
public void assertAuthorized(Annotation a) throws AuthorizationException {
if (a instanceof RequiresGuest && getSubject().getPrincipal() != null) {
throw new UnauthenticatedException("Attempting to perform a guest-only operation. The current Subject is " +
"not a guest (they have been authenticated or remembered from a previous login). Access " +
"denied.");
}
}
示例11: GuestAnnotationHandler
import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
/**
* Default no-argument constructor that ensures this interceptor looks for
*
* {@link org.apache.shiro.authz.annotation.RequiresGuest RequiresGuest} annotations in a method
* declaration.
*/
public GuestAnnotationHandler() {
super(RequiresGuest.class);
}