手淫是什么意思| 为什么说黑鱼是鬼| 做梦梦到吵架是什么意思| 什么目寸光成语| hcc是什么意思| 十月初是什么星座| 老虎拉车的歇后语是什么| 为什么会长汗疱疹| 草字头的字和什么有关| 胰腺炎是什么引起的| 西瓜跟什么不能一起吃| 徐州菜属于什么菜系| 早上口苦是什么原因| 女人来月经有血块是什么原因| 条件致病菌是什么意思| 吃什么能让阴茎更硬| 做梦梦见火是什么意思| 肚子胀不排便什么原因| 腰扭伤用什么药最好| 口腔白斑是什么病| 嗓子吞咽疼痛吃什么药| 儿童风寒感冒吃什么药| 直肠癌是什么症状| 1970年是什么命| 书字五行属什么| ket是什么意思| 便秘吃什么中成药| 怀孕初期吃什么好| 儿童支原体感染吃什么药| 什么是辣木籽| 猴年马月什么意思| 一什么二什么| 推迟月经用什么药| 八嘎呀路是什么意思| 便秘吃什么药快速排便| 坐镇是什么意思| 美林是什么药| 男人梦见猫是什么意思| 什么泡茶好喝| hc什么意思| 脑供血不足会导致什么后果| 农历9月28日是什么星座| 什么是暗网| 尿糖是什么意思| 镶牙与种牙有什么区别| 结膜炎什么症状| 孩子反复发烧是什么原因| 花胶是鱼的什么部位| 肝在五行中属什么| 脂肪肝有什么危害| 王加呈念什么| 发呆表情是什么意思| 梦见白蛇是什么预兆| 95年猪是什么命| 尿里有潜血是什么原因| 老年人脚肿是什么原因引起的| 福不唐捐什么意思| taco是什么| 为什么手麻| 什么的遗产| 倍他乐克是什么药| 一笑了之是什么意思| 达字五行属什么| 双重性格是什么意思| 维生素e有什么功效| 拖鞋什么材质的好| 吃什么可以降血压| 什么颜色衣服显皮肤白| 骟是什么意思| 小便分叉是什么症状| 三七植物长什么样子| 足三里在什么位置图片| 甲状腺结节3类什么意思| 拿什么证明分居两年| 什么食物含蛋白高| 电气火灾用什么灭火器| 孕妇贫血有什么症状| 负罪感什么意思| 左眼皮老是跳是什么原因| 尿ph值高是什么意思| 结甲是什么病| 全身冰凉是什么原因| 梦见小孩是什么意思| 扭捏是什么意思| 糜烂型脚气用什么药| 腺样体肥大是什么症状| 世界第一长河是什么河| 卵巢早衰吃什么药| 每天早上起床头晕是什么原因| hp检查是什么意思| 呕吐挂什么科| 全身浮肿是什么原因| 焦虑症是什么症状| 什么药可以降尿酸| 下腹坠胀是什么原因| 牙髓炎是什么| 花裙子配什么上衣好看| 血燥吃什么药| 11月29是什么星座| 阴道清洁度三度什么意思| 孕妇吐得厉害有什么办法解决| 田野是什么意思| 9月10日是什么节| 兴渠是什么菜| 马铃薯什么时候传入中国| 最近老做噩梦是什么原因| 宫腔镜手术是什么原因才要做| 医生为什么喜欢开地塞米松| 中气下陷吃什么药| 脸黄是什么原因造成的| 道是什么| 包皮垢是什么| 西瓜禁忌和什么一起吃| 长生殿讲的是什么故事| 吃驼奶粉有什么好处| 什么牛排最好吃| 什么是脂肪肝| 人为什么会得甲母痣| 怀孕都有什么症状| 百衲衣是什么意思| 早餐吃什么减肥| 白袜子是什么意思| 梦见玫瑰花是什么预兆| 自媒体是什么| 金风玉露是什么意思| 男性阴虱用什么药最好| 台风什么时候到福建| 心什么什么什么| 什么的流淌| 神经元特异性烯醇化酶是什么意思| 5个月宝宝可以吃什么水果| 1954年属什么| 美籍华裔是什么意思| 天花是什么| 梦见下雨是什么征兆| 判缓刑是什么意思| 什么病不能吃核桃| 小肠与什么相表里| 什么是干咳| 千娇百媚是什么意思| 咖喱饭需要什么材料| 掐是什么意思| 柴鱼是什么鱼| 肠炎能吃什么水果| 生理期什么意思| 荷尔蒙是什么| 水厄痣是什么意思| b族维生素是什么意思| 双脚踝浮肿是什么原因| 散光是什么原因造成的| 种牙好还是镶牙好区别是什么| 喝酒精的后果是什么| 好运是什么生肖| 柠檬和什么一起泡减肥| 外耳道耵聍什么意思| 蚊子怕什么颜色| 脚心发热是什么原因| 肾虚去医院挂什么科| 天津立冬吃什么| 子午相冲是什么意思| 什么是烂尾楼| 桂字五行属什么| 溺水是什么意思| 脚踩按摩垫有什么好处| 出轨是什么意思| 感冒有什么症状| 催丹香是什么意思| 血压高吃什么降压药| 晚上睡觉脚抽筋是什么原因| 硫酸亚铁是什么颜色| 乳酸杆菌大量是什么意思| 鸡尾酒是什么意思| 飞机用什么燃油| 左肺下叶纤维灶是什么意思| 灵什么意思| 昙花是什么意思| 南瓜和什么不能一起吃| 12月12号什么星座| 朱砂有什么用| 旗舰店是什么意思| 来源朋友验证消息是什么意思| 大人有大量是什么意思| 丙申五行属什么| 减肥晚餐吃什么| 孕囊是什么样的图片| 弥漫性肝病是什么意思| 月经不正常吃什么药| 高尿酸血症是什么意思| 谢字五行属什么| 阴性阳性什么意思| 1年是什么朝代| 刷酸是什么意思| 纯化水是什么水| 64岁属什么生肖| dem是什么| 血小板压积偏高是什么原因| 好不热闹是什么意思| 儿童肺炎吃什么药| 青花鱼是什么鱼| guess什么牌子| 冒节子是什么东西| ipa啤酒什么意思| 美女的阴暗是什么样的| 超纤皮是什么| 什么血型最招蚊子咬| 晨勃是什么| 唇炎去医院挂什么科| 1947属什么生肖| neo什么意思| 体质指数是什么意思| 摄取是什么意思| 洋溢着什么样的笑容| ch是什么意思| 看淋巴挂什么科室| 老年人吃饭老是噎着是什么原因| 牛蒡根泡水喝有什么好处| 引火归元是什么意思| 毛细血管扩张是什么原因引起的| 头孢是治什么的| 大姨妈来的少是什么原因| 鸟为什么会飞| 月经期能吃什么水果| 月加厷念什么| 严重失眠有什么方法| 嫡孙是什么意思| 耐药菌感染什么意思| 为什么会得盆腔炎| 葡萄糖高是什么意思| 如期而至是什么意思| 女人吃什么养颜又美白| 眉毛里面长痘痘是什么原因| 病毒由什么组成| mj什么意思| 秋老虎是什么意思| 麻雀喜欢吃什么| 牙痛吃什么药最有效| 什么药和酒一起吃必死| 双相是什么| 伊索寓言有什么故事| 散粉和粉饼有什么区别| 胃气胃胀吃什么药最好| 线差是什么意思| 手脚发热吃什么药| 空明什么意思| 王不留行是什么| 中指戴戒指代表什么| 黄瓜敷脸有什么功效与作用| 94年什么生肖| 喝老陈皮水有什么好处| 什么水果最好吃| 药剂师是干什么的| 白茶什么样的好| 一什么花瓣| npv是什么病毒| 宝宝发烧吃什么药| 女性得乙肝有什么症状| 阳阴阳是什么卦| 什么是溺水| 小河边有什么| 宰相和丞相有什么区别| 梦见流水是什么征兆| 属兔适合佩戴什么饰品| 血小板数目偏高是什么意思| 男性更年期吃什么药| 百度
DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Attention Kubernetes users! DZone is researching how K8s usage is evolving in 2025 — tell us the good, the bad, + the frustrating.

Getting Started With DevSecOps: This Refcard provides actionable insights for embedding security into your DevOps culture and workflows.

Data Engineering: Not your average "AI is changing everything" report. Dive into tooling, strategy, + systems in scalable data ecosystems.

Java Caching: This Refcard explores core caching concepts and demonstrates how to implement them using Java’s JCache API.

Related

  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • Aggregating REST APIs Calls Using Apache Camel
  • Leveraging Salesforce Using Spring Boot
  • Spring Boot REST API Request Body Validation Example Using a Custom Validator

Trending

  • Immutable Objects Using Record in Java
  • How LangChain Is Powering Next-Gen AI Apps: A Developer’s Guide in 2025
  • How GitHub Copilot Handles Multi-File Context Internally: A Deep Dive for Developers, Researchers, and Tech Leaders
  • What Is Availability? Theory, Problems, Tools, and Best Practices
  1. DZone
  2. Coding
  3. Frameworks
  4. Securing a JSON API REST Service With Spring Boot and Elide

海淀区举办驻区企业及北部地区书法骨干培训班

Learn how to make use of the security layer in Elide to make some decisions about who can perform what operation.

By 
Matthew Casperson user avatar
Matthew Casperson
·
Updated May. 16, 16 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
4.6K Views
百度 一份名为《唐山市钢铁行业2018年非采暖季错峰生产方案(征求意见稿)》的文件显示,唐山市拟在2018年3月16日至11月14日非采暖季期间共244天继续实施错峰限产,总限产任务万吨。

Join the DZone community and get the full member experience.

Join For Free

In a previous article we saw how to create new entities and how to set the relationships between entities by implementing support for Elide’s post() method. But security restrictions prevented us from actually modifying these relationships.

Now that our API has authentication, we can make use of the security layer in Elide to make some decisions about who can perform what operation.

A quick note here that this article is based on Elide 2.0.1, which fixes up some bugs from the version 1 we were using in previous articles. Specifically, you may have noticed that we were getting security errors in previous articles despite setting the security mode to inactive. This issue is now resolved in Elide 2.

Before we can make use of the security features in Elide, we need to enable security for our endpoints. This is done by passing the SecurityMode.SECURITY_ACTIVE value to the Elide methods get() and post().

So let’s take a look at what “allow all” permissions look like with Elide:

package com.matthewcasperson.elidetest.jpa;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.yahoo.elide.annotation.*;
import com.yahoo.elide.security.checks.prefab.Role;

import java.io.Serializable;
import javax.persistence.*;
import java.util.List;


/**
 * The persistent class for the parent database table.
 * 
 */
@ReadPermission(any={Role.ALL.class })
@SharePermission(any={Role.ALL.class })
@CreatePermission(any={Role.ALL.class })
@UpdatePermission(any={Role.ALL.class })
@DeletePermission(any={Role.ALL.class })
@Entity
@Table(name="parent")
@NamedQuery(name="Parent.findAll", query="SELECT p FROM Parent p")
public class Parent implements Serializable {
private static final long serialVersionUID = 1L;

private Integer id;

private String description;

private String name;

private List<Child> children;

public Parent() {
}

@Id
@Column(unique=true, nullable=false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
public Integer getId() {
return this.id;
}

public void setId(int id) {
this.id = id;
}

@Column(length=45)
public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

@Column(length=45)
public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

//bi-directional many-to-one association to Child
@OneToMany(mappedBy="parent")
@JsonManagedReference
public List<Child> getChildren() {
return this.children;
}

public void setChildren(List<Child> childs) {
this.children = childs;
}

public Child addChild(Child child) {
getChildren().add(child);
child.setParent(this);

return child;
}

public Child removeChild(Child child) {
getChildren().remove(child);
child.setParent(null);

return child;
}

}


Permissions in Elide are assigned through the annotations @CreatePermission, @ReadPermission, @UpdatePermission and @DeletePermission, which map to the common CRUD operations that you’ll perform when interacting with any database. These annotations are assigned to the JPA entities. In addition to these four CRUD permission annotations, there is also a @SharePermission annotation which is used to determine if entities can be related to one another.

All these permission annotations take an array of classes assigned to the any or all parameters. As you would expect, all checks assigned to the all parameter must pass for the operation to succeed, while one or more of the checks assigned to the any parameter must pass for the operation to succeed.

The Role.ALL.class is provided by the Elide library to always permit the operation.

With the five annotations above applied to each of the JPA entities, and with each annotation having a Role.ALL.class assigned to the any parameter, we are now free to perform any action supported by the Elide library. Now, when we POST

{
  "data": { "type": "child", "id": "1" }
}


to http://localhost:8080/parent/2/relationships/children, we see that the child with the ID of 1 is assigned to the parent with the ID of 2.

If you want to achieve the reverse, and deny anyone from doing anything with the API, you can use the Role.NONE.class.

@ReadPermission(any={Role.NONE.class })
@SharePermission(any={Role.NONE.class })
@CreatePermission(any={Role.NONE.class })
@UpdatePermission(any={Role.NONE.class })
@DeletePermission(any={Role.NONE.class })


Now, the same POST operation results in the following response:

{
  "errors": [
    "ForbiddenAccessException"
  ]
}


Obviously a blanket “deny all” security policy is quite useless in real life, but by mixing and matching the Role.ALL.class and Role.NONE.class with the various operations provided by Elide, it is possible to customize the access to your entities via your API.

In the next article, we’ll look at creating customized permission checks to provide even more fine-grained access based on user roles.

Download the source code for this article from here.

API Spring Framework JSON REST Web Protocols Spring Boot

Opinions expressed by DZone contributors are their own.

Related

  • Develop a Spring Boot REST API in AWS: PART 4 (CodePipeline / CI/CD)
  • Aggregating REST APIs Calls Using Apache Camel
  • Leveraging Salesforce Using Spring Boot
  • Spring Boot REST API Request Body Validation Example Using a Custom Validator

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

且行且珍惜什么意思 脊柱侧弯是什么原因引起的 外感是什么意思 吃什么可以补血 密胺是什么材质
值神天德是什么意思 黄体破裂是什么症状 泥丸宫在什么位置 皮囊炎用什么药膏 螺旋菌感染有什么危害
6点是什么时辰 气得什么 娇喘是什么 咳嗽有痰吃什么药 礼尚往来什么意思
就是什么意思 A型血为什么是完美血型 九霄云外是什么生肖 家伙是什么意思 胰腺占位是什么意思
专科医院是什么意思hcv8jop4ns6r.cn 下午5点多是什么时辰wuhaiwuya.com 鲜卑人是现在的什么人hcv8jop4ns2r.cn 金陵十三钗是什么意思onlinewuye.com 卟啉症是什么病hcv8jop5ns7r.cn
美国为什么帮以色列hcv8jop3ns3r.cn 狐狸吊坠有什么寓意hcv9jop1ns3r.cn 宫颈糜烂用什么药好得快hcv9jop8ns0r.cn 末梢神经炎吃什么药hcv8jop1ns8r.cn 机是什么生肖hcv8jop0ns5r.cn
手机越狱什么意思hcv8jop0ns2r.cn 7777什么意思hcv9jop0ns5r.cn 每天喝奶茶有什么危害hcv8jop6ns9r.cn 尿结石是什么引起的hcv8jop5ns3r.cn 为什么屁多是什么原因gysmod.com
五音指什么hcv7jop9ns4r.cn plus是什么意思hcv9jop3ns5r.cn 右边腰疼是什么原因hcv9jop4ns5r.cn 食管裂孔疝是什么原因造成的520myf.com 秉承是什么意思hcv7jop7ns1r.cn
百度