0
votes

Can anyone please show me how to migrate keycloak and spring security. I already follow step in http://keycloak.github.io/docs/userguide/keycloak-server/html/ch08.html#spring-security-adapter. but it dint work. Do i need to write my own provider?

my original spring-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>

i change this xml to xml that provided by keycloak user guide. And i put keycloak.json in web-inf.

After i make the configuration on keycloak. i try to access my page then error page like below will appear:

We're sorry ...

Invalid parameter: redirect_uri

return 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

2
Then you didn't follow the steps accordingly or are using different frameworks, are you using Spring boot? - M. Deinum
i follow that step 100%. Currently i use spring mvc + spring security. - FlyingTurtle
If you did it would work, so you must be missing something. Also what isn't working, post some code and configuration. Please read stackoverflow.com/help/how-to-ask and use that information to improve your question. - M. Deinum
i already edited my question. above excatly my spring-security.xml but then i change it to .xml config exactly like on that link. - FlyingTurtle
And please clarify what isn't working? Also your url-mappings are wrong... /admin/** also matches /admin/setup/** so basically the latter is useless the same for the other mappings. Mappings are consulted in the order they are specified they aren't ordered or a best match. Also you only added your original one, what is interesting is the modified one as that is the one you want to get working. - M. Deinum

2 Answers

0
votes

i already resolved this problem. I just fix my “valid redirect URIs” to http://localhost:8080/app/* and /app/*

0
votes

please add web orgins in keycloak client