小编Sha*_*ank的帖子

使用 AWS Cognito 和 Serverless 实施基于角色的访问控制

我按照本教程https://serverless-stack.com/使用 AWS 服务(S3、Lambda、Cognito、DynamoDB)和带有 ReactJS 的无服务器框架创建了一个无服务器应用程序。本教程使用 AWS Cognito 用户池和身份池进行用户管理和身份验证。本教程中的应用程序是一个“记笔记”应用程序,它在应用程序中没有基于角色的访问控制。

然而,我正在创建的应用程序需要 RBAC,在阅读了它之后,我明白可以使用“用户组”或“联合身份”来实现 RBAC。但是,我仍然无法弄清楚如何在我的应用程序中正确使用它们中的任何一个。

这是我到目前为止在应用程序中所做的

  1. 创建用户池并生成池 ID
  2. 添加了一个 App Client 并生成了 App Client ID
  3. 使用无服务器创建和部署我的 API
  4. 使用 Cognito 作为身份验证提供者以及上面生成的池 ID 和应用程序客户端 ID 对带有身份池的 API 应用访问控制,然后应用具有以下策略的角色

政策

{
    "Version": "2012-10-17",
    "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "mobileanalytics:PutEvents",
        "cognito-sync:*",
        "cognito-identity:*"
      ],
      "Resource": [
        "*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:*"
      ],
      "Resource": [
        "arn:aws:s3:::YOUR_S3_UPLOADS_BUCKET_NAME/${cognito-identity.amazonaws.com:sub}*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "execute-api:Invoke"
      ],
      "Resource": [
        "arn:aws:execute-api:YOUR_API_GATEWAY_REGION:*:YOUR_API_GATEWAY_ID/*"
      ]
    }
  ]
} …
Run Code Online (Sandbox Code Playgroud)

amazon-web-services serverless-framework aws-cognito

7
推荐指数
1
解决办法
5096
查看次数

如何在单个集合中获取 grails 域类的所有持久属性及其约束?

我需要在单个集合中获取有关特定 Grails 域类的所有信息,即持久属性和与它们相关的约束。我怎么做?

java grails grails-orm

5
推荐指数
2
解决办法
1941
查看次数

如何获取AWS中部署的“Lambda”函数的“端点”?

我正在使用无服务器框架开发无服务器应用程序。我使用以下方式部署了我的应用程序

$ serverless deploy
Run Code Online (Sandbox Code Playgroud)

部署后,我得到了我的函数的端点,如下所示

https://ly5webovq4.execute-api.us-east-1.amazonaws.com/prod/notes
Run Code Online (Sandbox Code Playgroud)

我没有记下来。现在我需要它,但找不到它。在哪里可以找到端点?

amazon-web-services aws-lambda aws-api-gateway serverless-framework

5
推荐指数
1
解决办法
548
查看次数

Grails Spring Security插件和dbconsole

我使用grails 2.4.3并安装了官方grails安全插件

compile ":spring-security-core:2.0-RC4"
Run Code Online (Sandbox Code Playgroud)

在安装插件之前,我可以使用url访问数据库控制台页面

http://localhost:8080/tobu/dbconsole
Run Code Online (Sandbox Code Playgroud)

但是,安装插件后,我无法这样做.当我尝试访问上面提到的URl并通过任何用户帐户登录时,我获得了默认登录屏幕,显示"访问被拒绝"页面.我该如何解决这个问题?

grails.project.groupId = appName 

grails.mime.disable.accept.header.userAgents = ['Gecko', 'WebKit', 'Presto', 'Trident']
grails.mime.types = [ // the first one is the default format
all:           '*/*', // 'all' maps to '*' or the first available format in withFormat
atom:          'application/atom+xml',
css:           'text/css',
csv:           'text/csv',
form:          'application/x-www-form-urlencoded',
html:          ['text/html','application/xhtml+xml'],
js:            'text/javascript',
json:          ['application/json', 'text/json'],
multipartForm: 'multipart/form-data',
rss:           'application/rss+xml',
text:          'text/plain',
hal:           ['application/hal+json','application/hal+xml'],
xml:           ['text/xml', 'application/xml']
]

grails.views.default.codec = "html"

grails.controllers.defaultScope = 'singleton'

grails {
views {
    gsp { …
Run Code Online (Sandbox Code Playgroud)

grails spring spring-security grails-plugin

3
推荐指数
1
解决办法
1798
查看次数

如何使用 Spring Boot Server 保持 Android 应用程序无限期登录?

好吧,说实话,这个标题有点误导,但我想不出更好的标题。

我有一个基于 Spring Boot 的服务器和一个 Android 应用程序。用户通过用户名和密码进行身份验证,然后获得 JWT 身份验证令牌,该令牌随后在访问 API 的后续请求中使用。令牌的有效期为一小时,之后用户需要使用其凭据再次登录,这对用户来说很不方便。事实上,仅当用户明确注销应用程序时,我才需要应用程序再次请求凭据。

我认为使用刷新令牌是这个问题的答案,但我不确定如何在当前的代码中实现它?

AuthController的authenticate方法

@PostMapping("/signin")
public ResponseEntity<?> authenticateUser(@Valid @RequestBody LoginRequest loginRequest) {

    Authentication authentication = authenticationManager.authenticate(
            new UsernamePasswordAuthenticationToken(
                    loginRequest.getUsernameOrEmail(),
                    loginRequest.getPassword()
            )
    );

    SecurityContextHolder.getContext().setAuthentication(authentication);

    String jwt = tokenProvider.generateToken(authentication);
    return ResponseEntity.ok(new JwtAuthenticationResponse(jwt));
}
Run Code Online (Sandbox Code Playgroud)

Jwt认证响应

public class JwtAuthenticationResponse {
    private String accessToken;
    private String refreshToken = "Blank";
    private String tokenType = "Bearer";

    //Getters and Setters
}
Run Code Online (Sandbox Code Playgroud)

JwtTokenProvider

@Component
 public class JwtTokenProvider {

private static final Logger logger = LoggerFactory.getLogger(JwtTokenProvider.class);

@Value("${app.jwtSecret}")
private String jwtSecret;

@Value("${app.jwtExpirationInMs}") …
Run Code Online (Sandbox Code Playgroud)

spring android spring-security jwt spring-boot

1
推荐指数
1
解决办法
1872
查看次数