|
Odpoviem si sám, aspoň do archívu konferencie: 1. Vytvorím si vlastnú implementáciu AuthenticationProvider kde implementujem metódu authenticate(). public class MyAuthenticationProvider implements AuthenticationProvider { /** */ public Authentication authenticate(Authentication authentication) throws AuthenticationException { ...Doplniť autentifikáciu pomocou mojej service... authentication.setAuthenticated(true); return authentication; } /** */ public boolean supports(Class authentication) { return (MyAuthenticationToken.class.isAssignableFrom(authentication)); } } 2. Vytvorím si vlastnú implementáciu AbstractAuthenticationToken kde prepíšem metódu getAuthorities() - keďže default sa vždy vytvorí RoleVoter, ten práve pracuje s rolami z tejto metódy. public class MyAuthenticationToken extends AbstractAuthenticationToken { @Override public GrantedAuthority[] getAuthorities() { ... Zistiť si role pomocou mojej service ako String[]... ... vrátiť role obalené do GrantedAuthority[]... } } 3. Do applicationContext-security.xml nastavím môjho provider-a: <bean id="myAuthenticationProvider" class="sk.nieco.MyAuthenticationProvider"> <security:custom-authentication-provider /> </bean> 4. Do aplikácie sa prihlásim kódom: ... Authentication authentication = new MyAuthenticationToken(name, password, mac); SecurityContextHolder.getContext().setAuthentication(authentication); ... 5. Ak sa použije tag <security:remember-me />, treba nadefinovať nejakú UserDetailsService. Aké jednoduché :-) Rastislav "Bedo" Siekel Ing. Rastislav Siekel Prosoft s.r.o., Kuzmányho 8, 010 01 Žilina, Slovakia E-mail : <[email protected]> Tel : 041/562 54 91 Fax : 041/562 54 97 Mobil : 0905 34 00 20 Rastislav Siekel wrote: Ahojte, |
- spring security - vlastny uzivatelia Rastislav Siekel
- Re: spring security - vlastny uzivatelia Karel Tejnora
- Re: spring security - vlastny uzivatelia Rastislav Siekel
