Hi all,
This thread is my alternative to moving a Flex thread on accessing UserDetails. Truthfully, I think I've got it working right, I'm just looking for confirmation from the community:
My security-config.xml file:
My ldaplogin.jsp page:Code:<http auto-config="true"> <intercept-url pattern="/index.html" filters="none" /> <intercept-url pattern="/favicon.ico" filters="none" /> <intercept-url pattern="/main.css" filters="none" /> <intercept-url pattern="/jspErrorPage.jsp" filters="none" /> <!-- For error handling --> <intercept-url pattern="/ldaplogin.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY" /> <intercept-url pattern="/app-flex/**" access="ROLE_USER" /> <!-- FIXME: Be sure to remove these as they may expose sensitive info --> <intercept-url pattern="/Hidden.jsp" access="ROLE_ADMIN" /> <!-- For Spring Security debugging only --> <intercept-url pattern="/variables.jsp" filters="none" /> <!-- For Tomcat/Java debugging only --> <form-login login-page="/ldaplogin.jsp" default-target-url="/app-flex/Main.html" always-use-default-target="true"/> </http>
This all seems to be in working order:Code:if(cookieAuthentication == true){ // The cookies that I have here include things like userid, first name, last name and the privileges they have sc = (SecurityContextImpl)SecurityContextHolder.getContext(); /* sc instance of: org.springframework.security.authentication.AnonymousAuthenticationToken Principal: anonymousUser; Authenticated: true; Granted Authorities: ROLE_ANONYMOUS */ if (sc != null){ // Just using this for debuggin auth = SecurityContextHolder.getContext().getAuthentication(); } // Instantiate a new Authentication object in the Security Context // per the user details that already exist in the cookies upat = new UsernamePasswordAuthenticationToken(ldaploginuserid,"password",AuthorityUtils.createAuthorityList("ROLE_USER","ROLE_ADMIN")); // Wondering if there's a best-practice way to do this in JSP SecurityContextHolder.getContext().setAuthentication(upat); log.info(upat.toString()); // For info only response.sendRedirect(referrer); // Where referrer is "flex-Main.html" return; // Flex will then use the SecurityHelper to change the View and allow method invocation }
- I can make a call to a remote object (SecurityHelper) from the Flex client and get the Authentication of the principal (UserDetails)
- I can secure my interfaces via annotations like @Secured("ROLE_ADMIN")
Though, my security-config.xml file still has this in it (I've been converting the samples to fit my implementation needs):
Do I need to create my own AuthenticationManager or AuthenticationProvider if my JSP seems to fit my need?Code:<authentication-manager> <authentication-provider> <user-service> <user name="john" password="john" authorities="ROLE_USER" /> <user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN, APP_ADMIN" /> <user name="guest" password="guest" authorities="ROLE_GUEST" /> </user-service> </authentication-provider> </authentication-manager>
Thanks community!
- Brian


Reply With Quote
