-
Jul 13th, 2012, 10:43 PM
#1
Spring User Role authentication
I am new to spring security i have a task where i need to load user role depending upon the site url after the user logs i don't want to have it in the contsec.xml can anyone tell me the other way
public class SpringSecurity {
public static void doSpringAuthenticate(String userNameOrEmail, String password) {
doSpringAuthenticate(userNameOrEmail, password, true);
}
public static void doSpringAuthenticate(String userNameOrEmail, String password, boolean eagerSavingContext) {
org.springframework.security.authentication.Authen ticationManager authenticationManager = ContextUtil.getAuthenticationManager();
Authentication authenticate = authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(userNameOrEmai l, password));
if (authenticate.isAuthenticated()) {
SecurityContextHolder.getContext().setAuthenticati on(authenticate);
if (eagerSavingContext) {
ExternalContext context = FacesContext.getCurrentInstance().getExternalConte xt();
HttpServletRequest request = (HttpServletRequest) context.getRequest();
HttpServletResponse response = (HttpServletResponse) context.getResponse();
ContextUtil.getSecurityContextRepository().saveCon text(SecurityContextHolder.getContext(), request, response);
}
}
}
Last edited by tinku12345; Jul 14th, 2012 at 08:23 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules