Client client = clientList.size() == 1 ? clientList.get(0) : clients.findClient(ctx);
protected Client getClient(JaxrsWebContext context) { try { return clients.findClient(context); } catch (TechnicalException e) { logger.debug("Error while getting the client from the context", e); return null; } }
protected Client getClient(Session session) { String clientName = session.getAttribute(Clients.DEFAULT_CLIENT_NAME_PARAMETER); if (Strings.isNullOrEmpty(clientName)) { return null; } return clients.findClient(clientName); }
@RequestMapping("/loginForm") public String loginForm(final Map<String, Object> map) { final FormClient formClient = (FormClient) config.getClients().findClient("FormClient"); map.put("callbackUrl", formClient.getCallbackUrl()); return "form"; }
@RequestMapping("/forceLogin") @ResponseBody public void forceLogin() { final Client client = config.getClients().findClient(webContext.getRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER)); try { client.redirect(webContext); } catch (final HttpAction e) { } }
private static ModelAndView form(final Config config) { final Map map = new HashMap(); final FormClient formClient = config.getClients().findClient(FormClient.class); map.put("callbackUrl", formClient.getCallbackUrl()); return new ModelAndView(map, "loginForm.mustache"); }
.filter(e -> { final String clientName = e.getValue().getClientName(); return (config.getClients().findClient(clientName) instanceof IndirectClient); }) .collect(toMap(e -> e.getKey(), e -> e.getValue()));
private static <C extends Credentials, U extends UserProfile> Promise<Optional<U>> performDirectAuthentication(Context ctx, Class<? extends Client<C, U>> clientType) { return RatpackWebContext.from(ctx, false).flatMap(webContext -> Blocking.get(() -> { Clients clients = ctx.get(Clients.class); Client<C, U> client = clients.findClient(clientType); return userProfileFromCredentials(client, webContext); }) ); }
.filter(e -> { final String clientName = e.getValue().getClientName(); return (config.getClients().findClient(clientName) instanceof IndirectClient); }) .collect(toMap(e -> e.getKey(), e -> e.getValue()));
@Override public void commence(final HttpServletRequest request, final HttpServletResponse response, final AuthenticationException authException) throws IOException, ServletException { if (config != null && CommonHelper.isNotBlank(clientName)) { final J2EContext context = new J2EContext(request, response, config.getSessionStore()); final List<Client> currentClients = new ArrayList<>(); final Client client = config.getClients().findClient(clientName); currentClients.add(client); try { if (startAuthentication(context, currentClients)) { logger.debug("Redirecting to identity provider for login"); saveRequestedUrl(context, currentClients); redirectToIdentityProvider(context, currentClients); } else { unauthorized(context, currentClients); } } catch (final HttpAction e) { logger.debug("extra HTTP action required in Pac4jEntryPoint: {}", e.getCode()); } } else { throw new TechnicalException("The Pac4jEntryPoint has been defined without config, nor clientName: it must be defined in a <security:http> section with the pac4j SecurityFilter or CallbackFilter"); } }
@SuppressWarnings("unchecked") protected AuthenticationInfo internalClientGetAuthenticationInfo(final AuthenticationToken authenticationToken) { final UsernamePasswordAndClientToken clientToken = (UsernamePasswordAndClientToken) authenticationToken; log.debug("clientToken : {}", clientToken); if (clientToken == null) { return null; } final Credentials credentials = (Credentials) clientToken.getCredentials(); log.debug("credentials : {}", credentials); final Client<Credentials, CommonProfile> client = this.clients.findClient(clientToken.getClientName()); log.debug("client : {}", client); final CommonProfile profile = client.getUserProfile(credentials, clientToken.getContext()); log.debug("profile : {}", profile); if (profile == null) { final String message = "No profile retrieved from authentication using client : " + client + " and credentials : " + credentials; log.info(message); throw new AuthenticationException(message); } // refresh authentication token with user id final String userId = profile.getTypedId(); clientToken.setUserId(userId); // set rememberMe status clientToken.setRememberMe(profile.isRemembered()); return internalClientGetAuthenticationInfo(profile, credentials); }
Client client = clientList.size() == 1 ? clientList.get(0) : clients.findClient(ctx);
@Override protected AuthenticationToken createToken(final ServletRequest request, final ServletResponse response) throws Exception { final J2EContext context = new J2EContext(WebUtils.toHttp(request), WebUtils.toHttp(response), new ShiroSessionStore()); final Client<Credentials, UserProfile> client = getClients().findClient(context); CommonHelper.assertNotNull("client", client); CommonHelper.assertTrue(client instanceof IndirectClient, "only indirect clients are allowed on the callback url"); log.debug("client : {}", client); Credentials credentials = null; try { credentials = client.getCredentials(context); log.debug("credentials : {}", credentials); } catch (Exception e) { log.info("用户取消登录或第三方回调错误"); } return credentials != null ? new UsernamePasswordAndClientToken(client.getName(), credentials, context) : null; }
private static ModelAndView forceLogin(final Config config, final Request request, final Response response) { final SparkWebContext context = new SparkWebContext(request, response); final String clientName = context.getRequestParameter(Pac4jConstants.DEFAULT_CLIENT_NAME_PARAMETER); final Client client = config.getClients().findClient(clientName); HttpAction action; try { action = client.redirect(context); } catch (final HttpAction e) { action = e; } config.getHttpActionAdapter().adapt(action.getCode(), context); return null; } }
public Result callback() { final PlayWebContext context = new PlayWebContext(ctx(), config.getSessionStore()); CommonHelper.assertNotNull("config", config); CommonHelper.assertNotNull("config.httpActionAdapter", config.getHttpActionAdapter()); final Clients clients = config.getClients(); CommonHelper.assertNotNull("clients", clients); final Client client = clients.findClient(context); logger.debug("client: {}", client); CommonHelper.assertNotNull("client", client); CommonHelper.assertTrue(client instanceof IndirectClient, "only indirect clients are allowed on the callback url"); final Credentials credentials; try { credentials = client.getCredentials(context); } catch (final RequiresHttpAction e) { return (Result) config.getHttpActionAdapter().adapt(e.getCode(), context); } logger.debug("credentials: {}", credentials); final UserProfile profile = client.getUserProfile(credentials, context); logger.debug("profile: {}", profile); saveUserProfile(context, profile); return redirectToOriginallyRequestedUrl(context); }
private static void initiateAuthentication(Context ctx, Class<? extends Client<?, ?>> clientType) { Request request = ctx.getRequest(); Clients clients = ctx.get(Clients.class); Client<?, ?> client = clients.findClient(clientType); RatpackWebContext.from(ctx, false).then(webContext -> { webContext.getSession().set(Pac4jSessionKeys.REQUESTED_URL, request.getUri()); try { client.redirect(webContext, true); } catch (Exception e) { if (e instanceof RequiresHttpAction) { webContext.sendResponse((RequiresHttpAction) e); return; } else { ctx.error(new TechnicalException("Failed to redirect", e)); } } webContext.sendResponse(); }); }
SessionData sessionData = webContext.getSession(); return createClients(ctx, pathBinding).map(clients -> clients.findClient(webContext) ).map( Types::<Client<Credentials, UserProfile>>cast
SecurityHandlerOptions options = new SecurityHandlerOptions().withClients("SAML2Client"); clients.findClient("SAML2Client");
get("/saml2", SparkPac4jDemo::protectedIndex, templateEngine); get("/saml2-metadata", (rq, rs) -> { SAML2Client samlclient = config.getClients().findClient(SAML2Client.class); samlclient.init(); return samlclient.getServiceProviderMetadataResolver().getMetadata();