List of usage examples for org.springframework.security.cas.web CasAuthenticationFilter CAS_STATEFUL_IDENTIFIER
String CAS_STATEFUL_IDENTIFIER
To view the source code for org.springframework.security.cas.web CasAuthenticationFilter CAS_STATEFUL_IDENTIFIER.
Click Source Link
From source file:it.scoppelletti.programmerpower.web.security.SsoAuthenticationService.java
/** * Autenticazione SSO./* w w w . j ava 2 s.c om*/ * * @param req Richiesta. * @param resp Risposta. * @return Token autenticato. Se il SSO non avviene, restituisce * {@code null}. */ private Authentication singleSignOn(HttpServletRequest req, HttpServletResponse resp) { String tgt, ticket; HttpSession session; Authentication result; AbstractAuthenticationToken authRequest; tgt = getTicketGrantingTicket(req, resp); if (Strings.isNullOrEmpty(tgt)) { return null; } try { ticket = myCasClient.newServiceTicket(tgt); } catch (IOException ex) { myCasClient.removeTicketGrantingTicket(req, resp); throw new AuthenticationServiceException("Single Sing-On failed.", ex); } session = req.getSession(true); myLogger.debug("New ticket {} for session {}.", ticket, session.getId()); authRequest = new UsernamePasswordAuthenticationToken(CasAuthenticationFilter.CAS_STATEFUL_IDENTIFIER, ticket); authRequest.setDetails(myAuthDetailsSource.buildDetails(req)); result = myAuthManager.authenticate(authRequest); if (result == null) { return null; } myCasClient.addAuthenticatedSession(ticket, session); return result; }
From source file:org.fao.geonet.kernel.security.ecas.ECasAuthenticationProvider.java
public Authentication authenticate(Authentication authentication) throws AuthenticationException { if (!supports(authentication.getClass())) { return null; }//from w w w. jav a2 s . co m if (authentication instanceof UsernamePasswordAuthenticationToken && (!CasAuthenticationFilter.CAS_STATEFUL_IDENTIFIER .equals(authentication.getPrincipal().toString()) && !CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER .equals(authentication.getPrincipal().toString()))) { // UsernamePasswordAuthenticationToken not CAS related return null; } // If an existing CasAuthenticationToken, just check we created it if (authentication instanceof CasAuthenticationToken) { if (this.key.hashCode() == ((CasAuthenticationToken) authentication).getKeyHash()) { return authentication; } else { throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.incorrectKey", "The presented CasAuthenticationToken does not contain the expected key")); } } // Ensure credentials are presented if ((authentication.getCredentials() == null) || "".equals(authentication.getCredentials())) { throw new BadCredentialsException(messages.getMessage("CasAuthenticationProvider.noServiceTicket", "Failed to provide a CAS service ticket to validate")); } boolean stateless = false; if (authentication instanceof UsernamePasswordAuthenticationToken && CasAuthenticationFilter.CAS_STATELESS_IDENTIFIER.equals(authentication.getPrincipal())) { stateless = true; } CasAuthenticationToken result = null; if (stateless) { // Try to obtain from cache result = statelessTicketCache.getByTicketId(authentication.getCredentials().toString()); } if (result == null) { result = this.authenticateNow(authentication); result.setDetails(authentication.getDetails()); } if (stateless) { // Add to cache statelessTicketCache.putTicketInCache(result); } return result; }