本文整理汇总了Java中org.apache.shiro.authz.annotation.RequiresUser类的典型用法代码示例。如果您正苦于以下问题:Java RequiresUser类的具体用法?Java RequiresUser怎么用?Java RequiresUser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RequiresUser类属于org.apache.shiro.authz.annotation包,在下文中一共展示了RequiresUser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: treeData
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@RequiresUser
@ResponseBody
@RequestMapping(value = "treeData")
public List<Map<String, Object>> treeData(String module, @RequestParam(required=false) String extId, HttpServletResponse response) {
response.setContentType("application/json; charset=UTF-8");
List<Map<String, Object>> mapList = Lists.newArrayList();
List<Category> list = categoryService.findByUser(true, module);
for (int i=0; i<list.size(); i++){
Category e = list.get(i);
if (extId == null || (extId!=null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",")==-1)){
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("pId", e.getParent()!=null?e.getParent().getId():0);
map.put("name", e.getName());
map.put("module", e.getModule());
mapList.add(map);
}
}
return mapList;
}
示例2: treeData
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
/**
* 分类树JSON
*/
@RequiresUser
@ResponseBody
@RequestMapping(value = "/treeData")
public List<Map<String, Object>> treeData(@RequestParam(required=false) String extId, HttpServletResponse response) {
response.setContentType("application/json; charset=UTF-8");
List<Map<String, Object>> mapList = Lists.newArrayList();
List<ShopCategory> list = categoryService.findFirstList();
for (int i=0; i<list.size(); i++){
ShopCategory e = list.get(i);
if (extId == null || (extId != null && !extId.equals(e.getId()) && e.getParentIds().indexOf(","+extId+",") == -1)){
Map<String, Object> map = Maps.newHashMap();
map.put("id", e.getId());
map.put("pId", e.getParent() != null ? e.getParent().getId() : 0);
map.put("name", e.getName());
mapList.add(map);
}
}
return mapList;
}
示例3: scanAnnotation
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的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());
}
}
}
示例4: scanAnnotation
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的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());
}
}
}
示例5: logout
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@GET
@Path("/logout")
@ApiOperation(value = "Logs out the user")
@ApiResponses({
@ApiResponse(code = 200, message = "if the user was logged out")
})
@RequiresUser
public Response logout() {
Subject subject = SecurityUtils.getSubject();
LOGGER.info("Log out user '{}'", subject.getPrincipal());
subject.logout();
return Response
.status(OK)
.build();
}
示例6: editProfileSelf
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@RequiresUser
@ResponseBody
@RequestMapping(value = "editProfileSelf", method = {RequestMethod.POST}, produces = {MediaType.TEXT_PLAIN_VALUE})
public String editProfileSelf(@RequestParam(value = "description", required = true) final String description,
@RequestParam(value = "timezone", required = true) final String timezone) throws Exception {
//
final String curUsername = SecurityUtils2.getUsername();
Optional<User> u = userService.getByUsername(curUsername);
if (u.isPresent() == false) {
throw new Exception(String.format("USER NOT FOUND [%s]", curUsername));
}
//
User u2 = u.get();
u2.setDescription(description);
u2.setTimezone(timezone);
userService.update(u2);
timeZoneService.evictUserTimeZoneCache(curUsername);
//
return "OK. UPDATED.";
}
示例7: editPage
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@RequiresUser
@RequestMapping(value = "/edit/{title:.+}", method = {RequestMethod.GET})
public ModelAndView editPage(@PathVariable("title") final String title
, @RequestParam(value = "origVersion", defaultValue = "", required = false) final String origVersion
, ModelMap m) throws PageAclException {
Optional<Page> p = pageService.getPageByTitle(title);
if (p.isPresent()) {
Page p2 = p.get();
m.put("page", p2);
m.put("title", p2.getTitle());
// check-acl
pageAclService.checkWritable(p2);
} else {
m.put("page", null);
m.put("title", title);
// check-acl
pageAclService.checkWritable(null);
}
//
m.put("origVersion", origVersion);
return new ModelAndView("page/edit", m);
}
示例8: intercept
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@Override
public Object intercept(AnnotationInterceptChain chain, Response response, Request request, RequiresUser annotation) throws Throwable {
if (SecurityUtils.getSubject().getPrincipal() == null) {
throw new UnauthenticatedException("Attempting to perform a user-only operation. The current Subject is " +
"not a user (they haven't been authenticated or remembered from a previous login). " +
"Access denied.");
}
return chain.intercept();
}
示例9: get
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@RequiresUser
public StatusXO get() {
StatusXO result = new StatusXO();
result.setVersion(applicationVersion.getVersion());
result.setEdition(applicationVersion.getEdition());
return result;
}
示例10: createHandler
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的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);
}
示例11: configure
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的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()));
}
示例12: interceptShiroSecurity
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的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();
}
示例13: changePasswordSelf
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@RequiresUser
@ResponseBody
@RequestMapping(value = "changePasswordSelf", method = {RequestMethod.POST}, produces = {MediaType.TEXT_PLAIN_VALUE})
public String changePasswordSelf(
@RequestParam(value = "curPassword", required = true) final String curPassword,
@RequestParam(value = "newPassword1", required = true) final String newPassword1,
@RequestParam(value = "newPassword2", required = true) final String newPassword2)
throws Exception {
//
final String curUsername = SecurityUtils2.getUsername();
//
if (false == ObjectUtils.equals(newPassword1, newPassword2)) {
throw new AuthorizationException("new-password-1 and new-password-2 mismatch.");
}
//
UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(curUsername, curPassword);
AuthenticationInfo a = securityManager.authenticate(usernamePasswordToken);
if (null == a) {
throw new AuthenticationException("invalid current-password!");
}
//
Optional<User> u = userService.getByUsername(curUsername);
if (u.isPresent() == false) {
throw new Exception(String.format("USER NOT FOUND [%s]", curUsername));
}
userService.setPassword(u.get(), newPassword1);
//
return "OK. CHANGED.";
}
示例14: editProfileSelfForm
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@RequiresUser
@RequestMapping(value = "editProfileSelfForm")
public ModelAndView editProfileSelfForm(ModelMap m) throws Exception {
m.put("TIMEZONE_IDS", timeZoneService.sortedTimeZoneIds());
//
final String curUsername = SecurityUtils2.getUsername();
Optional<User> u = userService.getByUsername(curUsername);
if (false == u.isPresent()) {
throw new Exception(String.format("USER NOT FOUND [%s]", curUsername));
}
//
m.put("user", u.get());
//
return new ModelAndView("user/editProfileSelfForm", m);
}
示例15: saveUpload
import org.apache.shiro.authz.annotation.RequiresUser; //导入依赖的package包/类
@RequiresUser
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveUpload(@RequestParam(value = "file", required = true) MultipartFile file,
@RequestParam(value = "privateFile", required = false, defaultValue = "false") final boolean privateFile,
@RequestParam(value = "description", required = false, defaultValue = "") final String description,
RedirectAttributesModelMap redirectAttributesModelMap) throws Exception {
//
final String creator = SecurityUtils2.getUsername();
//
if (file.isEmpty()) {
throw new Exception("PLEASE SELECT A FILE.");
} else {
Closer closer = Closer.create();
try {
final String mime = file.getContentType();
final String name = file.getOriginalFilename();
//
InputStream in = file.getInputStream();
closer.register(in);
//
Optional<FileEntry> fe = fileStoreService.save(name, mime, creator, privateFile, description, in);
if (fe.isPresent() == false) {
throw new Exception("FILE SAVE FAILED?!");
}
// flashmap-alert.
flashAlerts.add(redirectAttributesModelMap, new FlashAlerts.FlashAlert(BootstrapAlertTypes.INFO, "File Saved."));
//
return String.format("redirect:./info/%s", fe.get().getId());
} finally {
closer.close();
}
}
}