小编Dan*_*ehn的帖子

Spring Keycloak:获取用户标识

我已经开发了一个Spring Boot Web服务,并使用Keycloak进行访问管理。该网站将一些用户数据存储在数据库中。我尝试将这些数据与登录的用户连接。

目前,我将用户名和数据一起存储。但是我喜欢存储用户ID而不是用户名。我怎样才能做到这一点?

我尝试通过此方法获取SecurityContext:

@Bean
@Scope(scopeName = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
public KeycloakSecurityContext getKeycloakSecurityContext() {
    return ((KeycloakPrincipal<KeycloakSecurityContext>) getRequest().getUserPrincipal()).getKeycloakSecurityContext();
}
Run Code Online (Sandbox Code Playgroud)

但是我得到一个错误:

There was an unexpected error (type=Internal Server Error, status=500).
Error creating bean with name 'scopedTarget.getKeycloakSecurityContext'
defined in com.SiteApplication: Bean instantiation via factory method
failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.keycloak.KeycloakSecurityContext]: Factory method
'getKeycloakSecurityContext' threw exception; nested exception is
java.lang.ClassCastException:
org.keycloak.adapters.springsecurity.token.KeycloakAuthenticationToken
cannot be cast to org.keycloak.KeycloakPrincipal
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?缺什么?

谢谢!

java spring spring-boot keycloak

6
推荐指数
2
解决办法
7079
查看次数

Laravel&Dingo:具有Facebook / Google登录名的安全API

我已使用Dingo框架在Laravel中开发了一个API。现在,我想通过Facebook和/或Google登录(例如,使用OAuth)保护API访问权限

有教程或类似的东西吗?我不知道如何将安全的API访问集成到我的api中。

谢谢!

facebook oauth laravel dingo-api

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

在 Spring Boot 中禁用 CSRF / CORS:Spring security 5.7 和 SAML

我正在使用带有最新稳定版本的 Spring Boot 和 Sprign Security 的 Spring Boot 应用程序。我正在使用 SAML2 对 ADFS IDP 进行身份验证。这对于所有 GET 请求都适用。现在我需要使用 PUT 和 POST,因此我想禁用 csrf。

通过这段简单的代码,我尝试禁用 csrf:

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().and().cors().disable();
    }

}
Run Code Online (Sandbox Code Playgroud)

但是,执行此操作时,完整的 SAML 身份验证会丢失,并且不会执行单点登录等操作。我通过配置使用 SAML2:

spring:
  security:
    saml2:
      relyingparty:
        registration:
          DemoApp: 
            entity-id: urn:id:demo-app
            identityprovider:
              entity-id: "http://adfs.local/adfs/services/trust"
              metadata-uri: "https://adfs.local/FederationMetadata/2007-06/FederationMetadata.xml"     
              singlesignon:
                url: "https://adfs.local/adfs/ls"
                sign-request: true
Run Code Online (Sandbox Code Playgroud)

如何禁用 csrf 并保持 SAML2 正常工作?

spring spring-security spring-boot

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

debian 上的 mono:找不到文件“/srv/www/proj/bin\roslyn\csc.exe”

我尝试将用 Visual Studio 编写的 ASP NET 4.5 网站部署到 Mono 服务器。

System.IO.FileNotFoundException 找不到文件“/srv/www/proj/bin\roslyn\csc.exe”。

描述:HTTP 500。处理请求时出错。

System.IO.FileNotFoundException
Could not find file "/srv/www/proj/bin\roslyn\csc.exe".

Description: HTTP 500.Error processing request.

Details: Non-web exception. Exception origin (name of application or object): mscorlib.
Exception stack trace:
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) <0x41aaab70 + 0x006e7> in     <filename unknown>:0 
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) <0x41bba470 + 0x00053> in <filename unknown>:0 
  at (wrapper remoting-invoke-with-check) …
Run Code Online (Sandbox Code Playgroud)

c# linux asp.net mono

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