2015-12-15 207 views
0

任何人都可以请演示如何迁移keycloak和弹簧安全。我已经按照步骤http://keycloak.github.io/docs/userguide/keycloak-server/html/ch08.html#spring-security-adapter。但它的功效。我需要写我自己的提供者吗?Keycloak和弹簧安全

我原来的弹簧security.xml文件

<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:util="http://www.springframework.org/schema/util" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
         http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
         http://www.springframework.org/schema/context 
         http://www.springframework.org/schema/context/spring-context-4.0.xsd 
         http://www.springframework.org/schema/util 
         http://www.springframework.org/schema/util/spring-util.xsd 
         http://www.springframework.org/schema/security 
         http://www.springframework.org/schema/security/spring-security-3.2.xsd" 
     > 

    <http use-expressions="true"> 
     <intercept-url pattern="/index" access="isAuthenticated()" /> 
     <intercept-url pattern="/tasks" access="isAuthenticated()" /> 
     <intercept-url pattern="/dashboard" access="isAuthenticated()" /> 
     <intercept-url pattern="/resetPassword" access="isAuthenticated()" /> 
     <intercept-url pattern="/settings/**" access="isAuthenticated()" /> 
     <intercept-url pattern="/" access="isAuthenticated()" /> 
     <intercept-url pattern="/sam/**" access="hasRole('mym_security_permission-002')" /> 
     <intercept-url pattern="/admin/**" access="hasRole('mym_security_permission-005')" /> 
     <intercept-url pattern="/committee/**" access="isAuthenticated()" /> 
     <intercept-url pattern="/member/**" access="isAuthenticated()" /> 
     <intercept-url pattern="/attachment/download/**" access="isAuthenticated()" /> 

     <!-- access denied page --> 
     <access-denied-handler error-page="/403" /> 

     <form-login 
      login-page="/login" 
      login-processing-url="/perform_login" 
      authentication-failure-url="/login?error" 
      authentication-success-handler-ref="customAuthenticationSuccessHandler" 
      username-parameter="username" 
      password-parameter="password" 
      always-use-default-target="true" 
     /> 
     <!--success-handler-ref="customLogoutSuccessHandler" --> 
     <logout 
      logout-url="/perform_logout" 
      delete-cookies="true" 
      invalidate-session="true" 

     /> 
     <!-- enable csrf protection --> 
     <csrf/> 

     <session-management> 
      <concurrency-control max-sessions="1" /> 
     </session-management> 
    </http> 

    <authentication-manager alias="authenticationManager" erase-credentials="false"> 
     <authentication-provider ref="customAuthenticationProvider" /> 
    </authentication-manager> 

</beans:beans> 

我改变这个XML到XML,通过keycloak用户指南中提供。我把keycloak.json放入了web-inf。

当我在keycloak上进行配置后。我尝试访问我的网页,然后像下面的错误页面会出现:

对不起......

无效参数:REDIRECT_URI

返回URL:http://localhost:8080/auth/realms/Meeting/protocol/openid-connect/auth?response_type=code&client_id=mym-apps&redirect_uri=http%3A%2F%2Flocalhost%3A8080%2FApp%2Fsso%2Flogin&state=0%2Fd21c7ae9-b041-43e5-8135-8150e9895ee5&login=true

+0

那你没有按照相应的步骤或正在使用不同的框架,你使用Spring启动? –

+0

我遵循这一步100%。目前我使用spring mvc + spring安全。 – FlyingTurtle

+0

如果你这样做,它会工作,所以你一定会错过一些东西。还有什么不工作,发布一些代码和配置。请阅读http://stackoverflow.com/help/how-to-ask并使用该信息来改善您的问题。 –

回答