private Authenticator getAuthenticator() throws AuthenticationException { Authenticator authenticator = authenticatorInstance.isUnsatisfied() ? idmAuthenticatorInstance.get() : authenticatorInstance.get(); if (authenticator == null) { throw new AuthenticationException("No Authenticator has been configured."); } return authenticator; }
/** * <p>Writes the <code>issuedToken</code> to the {@link javax.servlet.http.HttpServletResponse}.</p> * * @param issuedToken * @param request * @param response */ protected void writeToken(String issuedToken, HttpServletRequest request, HttpServletResponse response) { try { response.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = response.getWriter(); writer.print("{\"authctoken\":\"" + issuedToken + "\"}"); writer.flush(); } catch (Exception e) { throw new AuthenticationException("Could not write token to response.", e); } }
private Authenticator getAuthenticator() throws AuthenticationException { Authenticator authenticator = authenticatorInstance.isUnsatisfied() ? idmAuthenticatorInstance.get() : authenticatorInstance.get(); if (authenticator == null) { throw new AuthenticationException("No Authenticator has been configured."); } return authenticator; }
/** * <p>Writes the <code>issuedToken</code> to the {@link javax.servlet.http.HttpServletResponse}.</p> * * @param issuedToken * @param request * @param response */ protected void writeToken(String issuedToken, HttpServletRequest request, HttpServletResponse response) { try { response.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = response.getWriter(); writer.print("{\"authctoken\":\"" + issuedToken + "\"}"); writer.flush(); } catch (Exception e) { throw new AuthenticationException("Could not write token to response.", e); } }
/** * <p>Writes the <code>issuedToken</code> to the {@link javax.servlet.http.HttpServletResponse}.</p> * * @param issuedToken * @param request * @param response */ protected void writeToken(String issuedToken, HttpServletRequest request, HttpServletResponse response) { try { response.setStatus(HttpServletResponse.SC_OK); PrintWriter writer = response.getWriter(); writer.print("{\"authctoken\":\"" + issuedToken + "\"}"); writer.flush(); } catch (Exception e) { throw new AuthenticationException("Could not write token to response.", e); } }
private Authenticator getAuthenticator() throws AuthenticationException { Authenticator authenticator = authenticatorInstance.isUnsatisfied() ? idmAuthenticatorInstance.get() : authenticatorInstance.get(); if (authenticator == null) { throw new AuthenticationException("No Authenticator has been configured."); } return authenticator; }
protected Consumer getTokenConsumer() { if (this.tokenConsumer.isAmbiguous()) { throw new AuthenticationException("You must provide exactly one " + Consumer.class.getName() + " implementation."); } if (!this.tokenConsumer.isUnsatisfied()) { return this.tokenConsumer.get(); } return null; }
protected Provider getTokenProvider() { if (this.tokenProvider.isAmbiguous()) { throw new AuthenticationException("You must provide exactly one " + Provider.class.getName() + " implementation."); } if (!this.tokenProvider.isUnsatisfied()) { return this.tokenProvider.get(); } return null; }
protected Provider getTokenProvider() { if (this.tokenProvider.isAmbiguous()) { throw new AuthenticationException("You must provide exactly one " + Provider.class.getName() + " implementation."); } if (!this.tokenProvider.isUnsatisfied()) { return this.tokenProvider.get(); } return null; }
protected Consumer getTokenConsumer() { if (this.tokenConsumer.isAmbiguous()) { throw new AuthenticationException("You must provide exactly one " + Consumer.class.getName() + " implementation."); } if (!this.tokenConsumer.isUnsatisfied()) { return this.tokenConsumer.get(); } return null; }
protected Provider getTokenProvider() { if (this.tokenProvider.isAmbiguous()) { throw new AuthenticationException("You must provide exactly one " + Provider.class.getName() + " implementation."); } if (!this.tokenProvider.isUnsatisfied()) { return this.tokenProvider.get(); } return null; }
protected Consumer getTokenConsumer() { if (this.tokenConsumer.isAmbiguous()) { throw new AuthenticationException("You must provide exactly one " + Consumer.class.getName() + " implementation."); } if (!this.tokenConsumer.isUnsatisfied()) { return this.tokenConsumer.get(); } return null; }
/** * <p>Issues a token for a previously authenticated {@link org.picketlink.idm.model.Account} using the * configured {@link org.picketlink.idm.credential.Token.Provider}.</p> * * @param request * @param response */ protected String issueToken(HttpServletRequest request, HttpServletResponse response) { Provider tokenProvider = getTokenProvider(); if (tokenProvider == null) { throw new AuthenticationException("No " + Provider.class.getName() + " was found."); } return tokenProvider.issue(getIdentity().getAccount()).getToken(); }
/** * <p>Issues a token for a previously authenticated {@link org.picketlink.idm.model.Account} using the * configured {@link org.picketlink.idm.credential.Token.Provider}.</p> * * @param request * @param response */ protected String issueToken(HttpServletRequest request, HttpServletResponse response) { Provider tokenProvider = getTokenProvider(); if (tokenProvider == null) { throw new AuthenticationException("No " + Provider.class.getName() + " was found."); } return tokenProvider.issue(getIdentity().getAccount()).getToken(); }
/** * <p>Issues a token for a previously authenticated {@link org.picketlink.idm.model.Account} using the * configured {@link org.picketlink.idm.credential.Token.Provider}.</p> * * @param request * @param response */ protected String issueToken(HttpServletRequest request, HttpServletResponse response) { Provider tokenProvider = getTokenProvider(); if (tokenProvider == null) { throw new AuthenticationException("No " + Provider.class.getName() + " was found."); } return tokenProvider.issue(getIdentity().getAccount()).getToken(); }
/** * <p>Creates a {@link org.picketlink.idm.credential.TokenCredential} using the token previously extracted from the request.</p> * * <p>Subclasses can override this method to customize how the credential is created. Defaults to an instance of {@link org.picketlink.idm.credential.TokenCredential}.</p> * * @param extractedToken The token previously extracted from the request. * @return */ protected TokenCredential createCredential(String extractedToken) { Token token; Provider tokenProvider = getTokenProvider(); if (tokenProvider != null) { token = create(getTokenProvider().getTokenType().getName(), extractedToken); } else { Consumer tokenConsumer = getTokenConsumer(); if (tokenConsumer == null) { throw new AuthenticationException("You must provide a " + Provider.class.getName() + " or " + Consumer.class.getName() + "."); } token = create(getTokenConsumer().getTokenType().getName(), extractedToken); } return new TokenCredential(token); }
/** * <p>Creates a {@link org.picketlink.idm.credential.TokenCredential} using the token previously extracted from the request.</p> * * <p>Subclasses can override this method to customize how the credential is created. Defaults to an instance of {@link org.picketlink.idm.credential.TokenCredential}.</p> * * @param extractedToken The token previously extracted from the request. * @return */ protected TokenCredential createCredential(String extractedToken) { Token token; Provider tokenProvider = getTokenProvider(); if (tokenProvider != null) { token = create(getTokenProvider().getTokenType().getName(), extractedToken); } else { Consumer tokenConsumer = getTokenConsumer(); if (tokenConsumer == null) { throw new AuthenticationException("You must provide a " + Provider.class.getName() + " or " + Consumer.class.getName() + "."); } token = create(getTokenConsumer().getTokenType().getName(), extractedToken); } return new TokenCredential(token); }
/** * <p>Creates a {@link org.picketlink.idm.credential.TokenCredential} using the token previously extracted from the request.</p> * * <p>Subclasses can override this method to customize how the credential is created. Defaults to an instance of {@link org.picketlink.idm.credential.TokenCredential}.</p> * * @param extractedToken The token previously extracted from the request. * @return */ protected TokenCredential createCredential(String extractedToken) { Token token; Provider tokenProvider = getTokenProvider(); if (tokenProvider != null) { token = create(getTokenProvider().getTokenType().getName(), extractedToken); } else { Consumer tokenConsumer = getTokenConsumer(); if (tokenConsumer == null) { throw new AuthenticationException("You must provide a " + Provider.class.getName() + " or " + Consumer.class.getName() + "."); } token = create(getTokenConsumer().getTokenType().getName(), extractedToken); } return new TokenCredential(token); }
@Override public void authenticate() { if(httpServletRequest == null){ throw new IllegalStateException("http request not available"); } if(httpServletResponse == null){ throw new IllegalStateException("http response not available"); } if(configuration == null){ throw new IllegalStateException("configuration not available"); } InteractionState interactionState; Userinfo userInfo = null; try { interactionState = getGoogleProcessor().processOAuthInteraction(httpServletRequest, httpServletResponse); } catch (Exception e) { // Cleanup state of OAuth interaction if error occured httpServletRequest.getSession().removeAttribute(GoogleConstants.ATTRIBUTE_AUTH_STATE); throw new AuthenticationException("Google+ login failed due to error", e); } // Authentication is finished. Let's obtain user info if (interactionState.getState().equals(InteractionState.State.FINISH)) { GoogleAccessTokenContext accessTokenContext = interactionState.getAccessTokenContext(); userInfo = getGoogleProcessor().obtainUserInfo(accessTokenContext); // Establish security context setStatus(AuthenticationStatus.SUCCESS); setAccount(new User(userInfo.getEmail())); } }
protected Account authenticate() throws AuthenticationException { Account validatedAccount = null; if (authenticating) { authenticating = false; //X TODO discuss it throw new IllegalStateException("Authentication already in progress."); } try { authenticating = true; eventBridge.fireEvent(new PreAuthenticateEvent()); Authenticator authenticator = getAuthenticator(); if (AUTHENTICATION_LOGGER.isDebugEnabled()) { AUTHENTICATION_LOGGER.debugf("Authentication is going to be performed by authenticator [%s]", authenticator); } authenticator.authenticate(); if (authenticator.getStatus() == null) { throw new AuthenticationException("Authenticator must return a valid authentication status"); } if (authenticator.getStatus() == Authenticator.AuthenticationStatus.SUCCESS) { validatedAccount = authenticator.getAccount(); postAuthenticate(authenticator); } } catch (AuthenticationException e) { throw e; } catch (Throwable ex) { throw new AuthenticationException("Authentication failed.", ex); } finally { authenticating = false; } return validatedAccount; }