当前位置: 首页>>代码示例>>Java>>正文


Java RequiresGuest类代码示例

本文整理汇总了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());
		}
	}
}
 
开发者ID:jayqqaa12,项目名称:jbase,代码行数:28,代码来源:ShiroPlugin.java

示例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());
        }
    }
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:24,代码来源:ShiroPlugin.java

示例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();
}
 
开发者ID:Teddy-Zhu,项目名称:SilentGo,代码行数:10,代码来源:RequiresGuestAnnotationResolver.java

示例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);
}
 
开发者ID:silb,项目名称:shiro-jersey,代码行数:10,代码来源:AuthorizationFilter.java

示例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()));
}
 
开发者ID:pabiagioli,项目名称:secure-rest-webapp-archetype,代码行数:14,代码来源:ShiroAnnotationsModule.java

示例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();
}
 
开发者ID:noveogroup,项目名称:clap,代码行数:33,代码来源:ShiroSecuredInterceptor.java

示例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();
}
 
开发者ID:kalixia,项目名称:Grapi,代码行数:11,代码来源:ShiroGenerator.java

示例8: simple

import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
@RequiresGuest
public String simple(final String name) {
    return "hi " + name;
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.shiro,代码行数:5,代码来源:ShiroInterceptorTest.java

示例9: guestEcho

import org.apache.shiro.authz.annotation.RequiresGuest; //导入依赖的package包/类
@Path("/")
@GET
@RequiresGuest
public String guestEcho() {
    return "guest";
}
 
开发者ID:kalixia,项目名称:Grapi,代码行数:7,代码来源:SecuredEchoResource.java

示例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 &quot;guest&quot;.
 */
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.");
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:18,代码来源:GuestAnnotationHandler.java

示例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);
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:10,代码来源:GuestAnnotationHandler.java


注:本文中的org.apache.shiro.authz.annotation.RequiresGuest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。