List of usage examples for org.springframework.security.web.authentication.rememberme RememberMeAuthenticationException RememberMeAuthenticationException
public RememberMeAuthenticationException(String msg)
From source file:com.sshdemo.common.security.web.authentication.rememberme.JPATokenBasedRememberMeService.java
@Override protected UserDetails processAutoLoginCookie(String[] cookieTokens, HttpServletRequest request, HttpServletResponse response) {//from w w w .j av a2 s . c o m if (bindingIP) { String ip = getUserIPAddress(request); final String presentedSeries = cookieTokens[0]; IPPersistentRememberMeToken token = (IPPersistentRememberMeToken) tokenRepository .getTokenForSeries(presentedSeries); if (token == null) { // No series match, so we can't authenticate using this cookie throw new RememberMeAuthenticationException( "No persistent token found for series id: " + presentedSeries); } if (!ip.equals(token.getIpAddress())) { throw new InvalidCookieException( "Cookie IP Address did not contain a matching IP (contained '" + ip + "')"); } } return super.processAutoLoginCookie(cookieTokens, request, response); }
From source file:it.scoppelletti.programmerpower.web.security.SsoRememberMeServices.java
/** * Valida l’autenticazione persistente. * /*from w w w .j a va 2 s. c o m*/ * @param cookieTokens Componenti del cookie per l’autenticazione * persistente. * @param req Richiesta. * @param resp Risposta. * @return Utente autenticato. */ @Override protected UserDetails processAutoLoginCookie(String[] cookieTokens, HttpServletRequest req, HttpServletResponse resp) { boolean newTGT; String tgt, ticket; UserDetails user; HttpSession session; AuthenticationException authEx; if (Strings.isNullOrEmpty(myUserName)) { throw new PropertyNotSetException(toString(), "userName"); } if (Strings.isNullOrEmpty(myPwd)) { throw new PropertyNotSetException(toString(), "password"); } if (myCasClient == null) { throw new PropertyNotSetException(toString(), "casClient"); } user = super.processAutoLoginCookie(cookieTokens, req, resp); tgt = getTicketGrantingTicket(req, resp); newTGT = Strings.isNullOrEmpty(tgt); try { if (newTGT) { tgt = myCasClient.newTicketGrantingTicket(myUserName, new SecureString(myPwd)); } ticket = myCasClient.newServiceTicket(tgt); } catch (Exception ex) { authEx = new RememberMeAuthenticationException(ApplicationException.toString(ex)); authEx.initCause(ex); throw authEx; } session = req.getSession(true); myLogger.debug("New ticket {} for session {}.", ticket, session.getId()); if (newTGT) { tgt = tgt.concat(SsoRememberMeServices.TICKET_SUFFIX); myCasClient.addTicketGrantingTicket(req, resp, tgt); } myCasClient.addAuthenticatedSession(ticket, session); return user; }
From source file:org.bibsonomy.webapp.util.spring.security.rememberMeServices.OpenIDRememberMeServices.java
@Override protected UserDetails processAutoLoginCookie(final String[] cookieTokens, final HttpServletRequest request, final HttpServletResponse response) throws RememberMeAuthenticationException, UsernameNotFoundException { if (cookieTokens.length != 4) { throw new InvalidCookieException( "Cookie token did not contain 4 tokens, but contained '" + Arrays.asList(cookieTokens) + "'"); }//from w ww . j a v a2s . com final long tokenExpiryTime = this.getExpiryTime(cookieTokens[2]); /* * if user is not logged in, redirect user to his open id provider * extract open id and user name */ final String username = cookieTokens[1]; final String claimedIdentity = cookieTokens[0]; /* * note: AbstractRememberMeServices#autoLogin checks if the user was deleted */ final UserDetails userDetails = this.getUserDetailsService().loadUserByUsername(username); /* * extract open ID from the database user */ if (!present(userDetails) || !(userDetails instanceof UserAdapter)) { throw new AuthenticationServiceException("User or ID could not be found in database."); } final String databaseIdentity = ((UserAdapter) userDetails).getUser().getOpenID(); /* * check token signature */ final String expectedTokenSignature = this .makeTokenSignature(new String[] { Long.toString(tokenExpiryTime), username, databaseIdentity }); final String signature = cookieTokens[3]; if (!expectedTokenSignature.equals(signature)) { throw new InvalidCookieException("Cookie token[3] contained signature '" + signature + "' but expected '" + expectedTokenSignature + "'"); } /* * build the url for the open id */ final String returnToUrl = this.buildReturnToUrl(request); final String realm = this.lookupRealm(returnToUrl); String openIdUrl = null; try { openIdUrl = this.consumer.beginConsumption(request, claimedIdentity, returnToUrl, realm); if (log.isDebugEnabled()) { log.debug("return_to is '" + returnToUrl + "', realm is '" + realm + "'"); log.debug("Redirecting to " + openIdUrl); } /* * save request in cache */ this.requestCache.saveRequest(request, response); response.sendRedirect(openIdUrl); } catch (final IOException ex) { log.warn("could not set redirect url " + openIdUrl, ex); } catch (final OpenIDConsumerException e) { log.debug("Failed to consume claimedIdentity: " + claimedIdentity, e); throw new AuthenticationServiceException( "Unable to process claimed identity '" + claimedIdentity + "'"); } // throw an exception to redirect the user throw new RememberMeAuthenticationException("redirect was sent"); }