- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 SingleSignOn(SSO)中,当应用程序加载时,我从我的办公室网络获取 jwt 不记名 token ,基本上我已经在其余 Web 服务中编写了代码,以从不同的 Web 服务获取不记名 token 。
我想要的是:我想在 Spring 确保其他一些端点的安全?我怎样才能做到这一点!
我不想提供登录名和密码表单来重新登录。因为我已经在调用网络服务来获取用户信息和不记名 token 。这意味着我已经登录,并且可以打印用户信息。
我有带有 userId 的用户角色表,我只想将表中可用的角色应用于登录的用户 ID。
我们该怎么做?
我发现了这个,但我希望这不会要求再次重新输入用户名和密码 https://www.ekiras.com/2016/04/authenticate-user-with-custom-user-details-service-in-spring-security.html
https://stackoverflow.com/a/11314388/1684778类似我的问题 https://stackoverflow.com/a/12057327/1684778
最佳答案
这里有很多事情需要考虑
用户身份验证:验证用户凭据后,我们将用户标记为已通过身份验证,并将其注册到 SecurityContext
您必须使用AuthenticationProvider
来验证收到的 token 。
例如:
public class SSOAuthenticationProvider implements AuthenticationProvider {
public Authentication authenticate(Authentication authentication) {
// verified the authentication token
authentication.setAuthenticated(true);
// make the database call, get roles for the user
authentication.setAuthorities(<authorities - discussed below>);
SecurityContextHolder.getContext().setAuthentication(authentication);
return authentication;
}
}
权限:用户通过身份验证后,我们需要获取用户授予的权限并进行设置。为此,我们需要一个自定义类来代表授予的权限。
public class CustomAuthority implements GrantedAuthority {
private String role;
public CustomAuthority(String role) {
this.role = role;
}
@Override
public String getAuthority() {
return role;
}
}
我们根据从数据库收到的角色创建这些自定义权限实例。因此,在之前的 SSOAuthenticationProvider
中,我们执行以下操作
// make the database call, get roles for the user
List<String> roles = <db call to get roles>
authentication.setAuthorities(Collections.unmodifiableCollection(roles.stream().map(CustomAuthority::new).collect(Collectors.toList()));
SecurityContextHolder.getContext().setAuthentication(authentication);
这会导致当前经过身份验证的用户拥有他们有权担任的所有角色。
唯一待处理的步骤是对每个端点的权限/角色进行硬编码。现在,当用户身份验证过程完成并执行端点验证时,Spring 会查看当前端点所需的权限,并在当前经过身份验证的用户中查找它们。如果存在,则执行端点代码。如果不是,则抛出AccessDeniedException
关于java - Spring : how to apply role to existing JWT token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59207288/
我正在评估在 Azure 中部署 Web 服务的各种选项。目前,Web 服务将仅由前端 UI 使用,该前端 UI 将作为单独的 Web 角色部署在托管 Web 服务的同一云服务中。然而,Web 服务将
我正在尝试在 Azure 中创建一个自定义角色,允许订阅“所有者”执行几乎所有操作,但取消/重命名自己的订阅或移至另一个管理组。 我还希望他们能够向他们想要的人授予正确的访问权限(特别是内置的“贡献者
我是 Ansible 的新手,我已经创建了我的第一个 Ansible 角色剧本,当我尝试运行它时,它抛出了下面的错误,而角色之外的其他模块(如处理程序、模板)工作正常。我仅通过剧本中的角色观察到这个问
我正在使用 Selenium 进行自动化测试。有什么区别 java -jar selenium-server-standalone-2.24.1.jar -role hub 和 java -jar s
根据WAI-ARIA specification两个角色都应该有: 关注第一个可聚焦元素 用户不能离开对话框 应该设置适当的 aria-label 应该用来中断流程,并且应该要求采取一些行动,例如单击
我想设计一个具有以下要求的数据库,但我遇到了问题。 我有 3 种类型的用户:医生、注册用户和管理员。将来我可能会添加其他类型的用户。这些用户类型中的每一种都有不同的配置文件字段。例如,注册用户应该有
我是 jQuery 和网页设计的新手,请原谅我问这个幼稚的问题。 关于latest jQuery mobile website ,他们的例子是: Page content goes here
我正在查看文档: http://pyqt.sourceforge.net/Docs/PyQt4/qtablewidgetitem.html#data 我可以将行 IDList.append(item.
我看到角色出现一些奇怪的异常,我不知道如何解释。角色名RD........ under ,我能期望它是什么?它是我在该特定服务组中的所有服务都在其上运行的底层机器吗? 最佳答案 Application
我正在尝试使用我的 GitHub 设置 CodeDeploy,但发现了一些问题。 我已使用 AWSCodeDeployRole 策略创建了服务角色,如文档中所述。 在我的 Code Deploy 应用
我正在尝试创建一个 Web 服务并将其部署到 Azure 云服务 场景非常简单:通过 http 或 https 向服务发送请求并接收一些数据。 我无法从文档中判断这是否应该在 WebRole 或 Wo
我从 ASP.NET Identity 的声明授权开始,如果我的应用程序中需要“角色”概念,我想阐明处理它们的方式。 注意:我对这个真的很陌生,所以所有的概念都在我脑海中飞舞,请多多关照,对于任何概念
我知道这个问题与一些类似,但我的设置与那些不同。 EF 中具有以下类的正确配置是什么? 这里的问题是 Team有一个可选的 DivisionParticipant ,但是 DivisionPartic
我无法运行 Windows Azure Hello World 示例。它给了我以下错误: “一个或多个角色启动角色失败”。 我将项目放在 D 驱动器的根目录中,以确保路径长度不是问题。我还清除了 Az
我正在尝试向我的 Xcode 添加一个帐户,但我一直收到此错误。另一个 Xcode 上的相同帐户可以完美运行。我有其他帐户运行良好。 错误是(如标题所述) The role information i
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
在 Bash 脚本中,我想删除 Postgres 用户角色。但是 Postgres 不允许我这样做,我得到了 Cannot drop table X because other objects dep
我目前正在设置一个新项目并创建我的登录系统。由于某种原因,它似乎正在搜索角色表?到目前为止,这是我的结构: Controller public function action_index() {
我有三个模型,一个用户,一个个人资料和一个角色,我试图通过个人资料角色附加到用户强>. # user.rb class User :profiles has_many :users end 我正
我想使用 Spring Security JSP 标签库根据角色有条件地显示一些内容。但是在 Spring Security 3.1.x 中只检查一个角色。 我可以使用,但 ifAllGranted
我是一名优秀的程序员,十分优秀!