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


Java RequiresRoles类代码示例

本文整理汇总了Java中org.apache.shiro.authz.annotation.RequiresRoles的典型用法代码示例。如果您正苦于以下问题:Java RequiresRoles类的具体用法?Java RequiresRoles怎么用?Java RequiresRoles使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RequiresRoles类属于org.apache.shiro.authz.annotation包,在下文中一共展示了RequiresRoles类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: edit

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
/**
 * 编辑用户
 *
 * @param userVo
 * @return
 */
@RequiresRoles("admin")
@PostMapping("/edit")
@ResponseBody
public Object edit(@Valid UserVo userVo) {
    List<User> list = userService.selectByLoginName(userVo);
    if (list != null && !list.isEmpty()) {
        return renderError("登录名已存在!");
    }
    // 更新密码
    if (StringUtils.isNotBlank(userVo.getPassword())) {
        User user = userService.selectById(userVo.getId());
        String salt = user.getSalt();
        String pwd = passwordHash.toHex(userVo.getPassword(), salt);
        userVo.setPassword(pwd);
    }
    userService.updateByVo(userVo);
    return renderSuccess("修改成功!");
}
 
开发者ID:TomChen001,项目名称:xmanager,代码行数:25,代码来源:UserController.java

示例2: assertAuthorized

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
/**
 * Ensures that the calling <code>Subject</code> has the Annotation's specified roles, and if not, throws an
 * <code>AuthorizingException</code> indicating that access is denied.
 *
 * @param a the RequiresRoles annotation to use to check for one or more roles
 * @throws org.apache.shiro.authz.AuthorizationException
 *          if the calling <code>Subject</code> does not have the role(s) necessary to
 *          proceed.
 */
public void assertAuthorized(Annotation a) throws AuthorizationException {
    if (!(a instanceof RequiresRoles)) return;

    RequiresRoles rrAnnotation = (RequiresRoles) a;
    String[] roles = rrAnnotation.value();

    if (roles.length == 1) {
        getSubject().checkRole(roles[0]);
        return;
    }
    if (Logical.AND.equals(rrAnnotation.logical())) {
        getSubject().checkRoles(Arrays.asList(roles));
        return;
    }
    if (Logical.OR.equals(rrAnnotation.logical())) {
        // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
        boolean hasAtLeastOneRole = false;
        for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true;
        // Cause the exception if none of the role match, note that the exception message will be a bit misleading
        if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]);
    }
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:32,代码来源:RoleAnnotationHandler.java

示例3: intercept

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@Override
public Object intercept(AnnotationInterceptChain chain, Response response, Request request, RequiresRoles requiresRoles) throws Throwable {
    String[] roles = requiresRoles.value();
    Subject subject = SecurityUtils.getSubject();
    if (roles.length == 1) {
        subject.checkRole(roles[0]);
        return chain.intercept();
    }
    if (Logical.AND.equals(requiresRoles.logical())) {
        subject.checkRoles(Arrays.asList(roles));
        return chain.intercept();
    }
    if (Logical.OR.equals(requiresRoles.logical())) {
        // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
        boolean hasAtLeastOneRole = false;
        for (String role : roles) if (subject.hasRole(role)) hasAtLeastOneRole = true;
        // Cause the exception if none of the role match, note that the exception message will be a bit misleading
        if (!hasAtLeastOneRole) subject.checkRole(roles[0]);
    }
    return chain.intercept();
}
 
开发者ID:Teddy-Zhu,项目名称:SilentGo,代码行数:22,代码来源:RequiresRolesAnnotationResolver.java

示例4: assertAuthorized

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@Override
   public void assertAuthorized() throws AuthorizationException {
	//if (!(annotation instanceof RequiresRoles)) return;
       RequiresRoles rrAnnotation = (RequiresRoles) annotation;
       String[] roles = rrAnnotation.value();

       if (roles.length == 1) {
           getSubject().checkRole(roles[0]);
           return;
       }
       if (Logical.AND.equals(rrAnnotation.logical())) {
           getSubject().checkRoles(Arrays.asList(roles));
           return;
       }
       if (Logical.OR.equals(rrAnnotation.logical())) {
           // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
           boolean hasAtLeastOneRole = false;
           for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true;
           // Cause the exception if none of the role match, note that the exception message will be a bit misleading
           if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]);
       }
}
 
开发者ID:gumutianqi,项目名称:jfinal-plus,代码行数:23,代码来源:RoleAuthzHandler.java

示例5: scanAnnotation

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的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

示例6: assertAuthorized

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@Override
public void assertAuthorized() throws AuthorizationException {
    //if (!(annotation instanceof RequiresRoles)) return;
    RequiresRoles rrAnnotation = (RequiresRoles) annotation;
    String[] roles = rrAnnotation.value();

    if (roles.length == 1) {
        getSubject().checkRole(roles[0]);
        return;
    }
    if (Logical.AND.equals(rrAnnotation.logical())) {
        getSubject().checkRoles(Arrays.asList(roles));
        return;
    }
    if (Logical.OR.equals(rrAnnotation.logical())) {
        // Avoid processing exceptions unnecessarily - "delay" throwing the exception by calling hasRole first
        boolean hasAtLeastOneRole = false;
        for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true;
        // Cause the exception if none of the role match, note that the exception message will be a bit misleading
        if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]);
    }
}
 
开发者ID:GojaFramework,项目名称:goja,代码行数:23,代码来源:RoleAuthzHandler.java

示例7: scanAnnotation

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的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

示例8: updateApplication

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@PUT
@RequiresRoles("agate-administrator")
public Response updateApplication(@PathParam("id")String id, Agate.ApplicationDto dto) {
  Application application = applicationService.getApplication(id);
  application.setDescription(dto.getDescription());
  application.setRedirectURI(dto.getRedirectURI());
  application.setScopes(Lists.newArrayList());
  dto.getScopesList().forEach(s -> application.addScope(s.getName(), s.getDescription()));

  if (dto.hasKey()) {
    application.setKey(applicationService.hashKey(dto.getKey()));
  }

  applicationService.save(application);

  return Response.noContent().build();
}
 
开发者ID:obiba,项目名称:agate,代码行数:18,代码来源:ApplicationResource.java

示例9: getEncryptionKeyCertificate

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@GET
@Path("/keystore/{name}/{alias}")
@Timed
@RequiresRoles(Roles.MICA_ADMIN)
public Response getEncryptionKeyCertificate(@PathParam("name") String name, @PathParam("alias") String alias)
  throws IOException, KeyStoreException {

  if(!Sets.newHashSet(KeyStoreService.SYSTEM_KEY_STORE, OpalService.OPAL_KEYSTORE).contains(name)) {
    return Response.status(Response.Status.BAD_REQUEST).build();
  }

  if(keyStoreService.getKeyStore(name).aliasExists(alias)) {
    return Response.ok(keyStoreService.getPEMCertificate(name, alias), MediaType.TEXT_PLAIN_TYPE)
      .header("Content-disposition", String.format("attachment; filename=%s-%s-certificate.pem", name, alias))
      .build();
  }

  return Response.status(Response.Status.NOT_FOUND).build();
}
 
开发者ID:obiba,项目名称:mica2,代码行数:20,代码来源:MicaConfigResource.java

示例10: createUser

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@RequiresAuthentication
@RequiresRoles("ADMIN")
@WrapException
@Override
public User createUser(final UserCreationModel user) {
    user.setRole(Role.DEVELOPER);
    UserEntity userEntity = converter.map(user);
    final String password = user.getPassword();
    if (password != null) {
        userEntity.setHashedPassword(PasswordsHashCalculator.calculatePasswordHash(password));
    }
    updateToken(userEntity);
    userEntity = userDAO.persist(userEntity);
    userDAO.flush();
    return converter.map(userEntity, configBean);
}
 
开发者ID:noveogroup,项目名称:clap,代码行数:17,代码来源:UserServiceImpl.java

示例11: download

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@GET
@Path("{id}/download")
@RequiresRoles(UserRole.ROLE_ADMIN)
@Produces(MediaType.TEXT_PLAIN)
public Response download(@PathParam("id") long id) {
	Course course = courseDao.findById(id);
	Builder<String> setBuilder = ImmutableSet.builder();
	if (course.getProjects().isEmpty()) {
		return Response.status(Status.NO_CONTENT).entity("This course doesn't have any projects").build();
	} else {
		for (Project project : course.getProjects()) {
			if (project.getSourceCodeUrl() == null) {
				LOG.warn("This project doesnt have a source code URL: {}", project);
			} else {
				setBuilder.add(project.getSourceCodeUrl());
			}
		}
		Set<String> sourceCodeurls = setBuilder.build();
		return Response.ok(repoDownloader.prepareDownload(sourceCodeurls)).build();
	}
}
 
开发者ID:devhub-tud,项目名称:devhub-prototype,代码行数:22,代码来源:CoursesResources.java

示例12: list

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@RequiresRoles(GroupService.ADMIN_ROLE)
@RequestMapping(value = "list")
public ModelAndView list(ModelMap m,
                         @ModelAttribute("listParam") ListParam listParam) {
    //
    m.put("groups", list(listParam));
    Pagination p = new Pagination(groupService.count(listParam.getSearchTermAsOptional()),
            listParam.getOffset(), listParam.getLimit());
    m.put("groupsPagination", p);
    //
    GroupListPaginationToLinkFunction pf = new GroupListPaginationToLinkFunction();
    pf.setPagination(p);
    pf.setSearchTerm(listParam.getSearchTermAsOptional());
    m.put("groupsPaginationToLinkFunction", pf);
    //
    return new ModelAndView("admin/group/list", m);
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:18,代码来源:GroupAdminController.java

示例13: list

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@RequiresRoles(GroupService.ADMIN_ROLE)
@RequestMapping(value = "list")
public ModelAndView list(ModelMap m,
                         @ModelAttribute("userAdminListParam") UserAdminListParam listParam) {
    //
    List<User> l = userService.list(
            Optional.<String>absent(), Optional.<String>absent(),
            listParam.getOffset(), listParam.getLimit());
    m.put("users", l);
    //
    long c = userService.count(Optional.<String>absent(), Optional.<String>absent());
    Pagination p = new Pagination(c, listParam.getOffset(), listParam.getLimit());
    m.put("usersPagination", p);
    //
    UserListPaginationToLinkFunction pf = new UserListPaginationToLinkFunction();
    pf.setSearchTerm(listParam.getSearchTermAsOptional());
    pf.setGroupName(listParam.getGroupNameAsOptional());
    pf.setPagination(p);
    m.put("usersPaginationToLinkFunction", pf);
    //
    return new ModelAndView("admin/user/list", m);
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:23,代码来源:UserAdminController.java

示例14: form

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@RequiresRoles(GroupService.ADMIN_ROLE)
@RequestMapping(value = "form")
public ModelAndView form(ModelMap m,
                         @RequestParam(value = "username", required = false, defaultValue = "") final String username) {
    //
    if (false == Strings.isNullOrEmpty(username)) {
        Optional<User> u = userService.getByUsername(username);
        if (u.isPresent()) {
            m.put("user", u.get());
        }
    } else {
        m.put("user", new User());
    }
    //
    m.put("TIMEZONE_IDS", timeZoneService.sortedTimeZoneIds());
    m.put("EVERYONE_GROUP", GroupService.EVERYONE_ROLE);
    //
    m.put("groups", groupService.list(Optional.<String>absent(), 0, Integer.MAX_VALUE));
    //
    return new ModelAndView("admin/user/form", m);
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:22,代码来源:UserAdminController.java

示例15: changePassword

import org.apache.shiro.authz.annotation.RequiresRoles; //导入依赖的package包/类
@RequiresRoles(GroupService.ADMIN_ROLE)
@ResponseBody
@RequestMapping(value = "changePassword/{username}", produces = {MediaType.TEXT_PLAIN_VALUE})
public String changePassword(@PathVariable("username") final String username,
                             @RequestParam(value = "newPassword", required = true) final String newPassword) throws Exception {
    //
    Optional<User> u = userService.getByUsername(username);
    if (false == u.isPresent()) {
        throw new Exception(String.format("USER NOT FOUND [%s]", username));
    }
    //
    User u2 = u.get();
    userService.setPassword(u2, newPassword);
    //
    return "OK. CHANGED.";
}
 
开发者ID:ageldama,项目名称:glados-wiki,代码行数:17,代码来源:UserAdminController.java


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