spring security + oauth2 + Reactjs + zuul proxy -
i working oauth2 , spring security , using zuul proxy. have login button in client web app. when user click on request should redirect authentication server authentication. it's not redirecting request authentication server. sharing code, kindly give solution.
1. client web application code
@springbootapplication @enablezuulproxy @enableoauth2sso public class oauthuiapplication { public static void main(string[] args) { springapplication.run(oauthuiapplication.class, args); } @configuration protected static class securityconfiguration extends websecurityconfigureradapter { @override public void configure(httpsecurity http) throws exception { http.logout().and().antmatcher("/**").authorizerequests() .antmatchers("/index.html", "/home.html", "/", "/login").permitall() .anyrequest().authenticated().and().csrf() .csrftokenrepository(csrftokenrepository()).and() .addfilterafter(csrfheaderfilter(), csrffilter.class); } private filter csrfheaderfilter() { return new onceperrequestfilter() { @override protected void dofilterinternal(httpservletrequest request, httpservletresponse response, filterchain filterchain) throws servletexception, ioexception { csrftoken csrf = (csrftoken) request.getattribute(csrftoken.class .getname()); if (csrf != null) { cookie cookie = webutils.getcookie(request, "xsrf-token"); string token = csrf.gettoken(); if (cookie == null || token != null && !token.equals(cookie.getvalue())) { cookie = new cookie("xsrf-token", token); cookie.setpath("/"); response.addcookie(cookie); } } filterchain.dofilter(request, response); } }; } private csrftokenrepository csrftokenrepository() { httpsessioncsrftokenrepository repository = new httpsessioncsrftokenrepository(); repository.setheadername("x-csrf-token"); return repository; } } @bean public simplefilter simplefilter() { return new simplefilter(); } }
2. application.yml file
debug: zuul: routes: resource: path: /resource/** # proxying resource server 'resource' url: http://localhost:9000/resource # requests starts /resource/ routed url user: path: /user/** # proxying user end point on authorization server url: http://localhost:9999/uaa/user # requests starts /user/ routed url security: user: password: none oauth2: sso: login-path: /login client: accesstokenuri: http://localhost:9999/uaa/oauth/token # token endpoint userauthorizationuri: http://localhost:9999/uaa/oauth/authorize # authrization end point clientid: acme # client id clientsecret: acmesecret # client secret id resource: jwt: keyvalue: | -----begin public key----- miibijanbgkqhkig9w0baqefaaocaq8amiibcgkcaqeagnbn+wu3i6karb6gylg40ckbiwmtvepykggvhxow74t19odyo2vrqyy9oaj/cvnlszgtoyaujtecjl8ww7f7njzpxmpfviqbx/zeieoovd7doqk3p5rbtlsv5a8tjtfqyw/th4yemzy/xkxjhh+kmyhmkpo+/tp3egmcmdjgh+lwa6yhdgci4ztlqjyy73gx0pedtpwvmo6g1+mw8x6ctry3awbzyulgt+i82xv+snqerif4uzo6cp2ixpcnmff1k4dqnrz/v98hnslclfmkchenfkyg1cwgd+ocjo+kbucimqmeqbffw908oyfkxl7yw0kekkysxpa4ndu978yxewidaqab -----end public key----- logging: level: org.springframework.security: debug 3.
Comments
Post a Comment