当前位置: 首页>>代码示例>>Java>>正文


Java CommonUtils类代码示例

本文整理汇总了Java中org.jasig.cas.client.util.CommonUtils的典型用法代码示例。如果您正苦于以下问题:Java CommonUtils类的具体用法?Java CommonUtils怎么用?Java CommonUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CommonUtils类属于org.jasig.cas.client.util包,在下文中一共展示了CommonUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleFederationRequest

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
/**
 * Handle federation request.
 *
 * @param response the response
 * @param request  the request
 * @return the model and view
 * @throws Exception the exception
 */
@GetMapping(path = WSFederationConstants.ENDPOINT_FEDERATION_REQUEST_CALLBACK)
protected ModelAndView handleFederationRequest(final HttpServletResponse response, final HttpServletRequest request) throws Exception {
    final WSFederationRequest fedRequest = WSFederationRequest.of(request);
    LOGGER.debug("Received callback profile request [{}]", request.getRequestURI());
    final WSFederationRegisteredService service = findAndValidateFederationRequestForRegisteredService(response, request, fedRequest);
    LOGGER.debug("Located matching service [{}]", service);

    final String ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
    if (StringUtils.isBlank(ticket)) {
        LOGGER.error("Can not validate the request because no [{}] is provided via the request", CasProtocolConstants.PARAMETER_TICKET);
        return new ModelAndView(CasWebflowConstants.VIEW_ID_ERROR, new HashMap<>(), HttpStatus.FORBIDDEN);
    }

    final Assertion assertion = validateRequestAndBuildCasAssertion(response, request, fedRequest);
    SecurityToken securityToken = getSecurityTokenFromRequest(request);
    if (securityToken == null) {
        LOGGER.debug("No security token is yet available. Invoking security token service to issue token");
        securityToken = validateSecurityTokenInAssertion(assertion, request, response);
    }
    addSecurityTokenTicketToRegistry(request, securityToken);
    final String rpToken = produceRelyingPartyToken(response, request, fedRequest, securityToken, assertion);
    return postResponseBackToRelyingParty(rpToken, fedRequest);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:32,代码来源:WSFederationValidateRequestCallbackController.java

示例2: issueAuthenticationRequestRedirect

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
/**
 * Redirect request for authentication.
 *
 * @param pair     the pair
 * @param request  the request
 * @param response the response
 * @throws Exception the exception
 */
protected void issueAuthenticationRequestRedirect(final Pair<? extends SignableSAMLObject, MessageContext> pair,
                                                  final HttpServletRequest request,
                                                  final HttpServletResponse response) throws Exception {
    final AuthnRequest authnRequest = AuthnRequest.class.cast(pair.getLeft());
    final String serviceUrl = constructServiceUrl(request, response, pair);
    LOGGER.debug("Created service url [{}]", serviceUrl);

    final String initialUrl = CommonUtils.constructRedirectUrl(this.loginUrl,
            CasProtocolConstants.PARAMETER_SERVICE, serviceUrl, authnRequest.isForceAuthn(),
            authnRequest.isPassive());

    final String urlToRedirectTo = buildRedirectUrlByRequestedAuthnContext(initialUrl, authnRequest, request);

    LOGGER.debug("Redirecting SAML authN request to [{}]", urlToRedirectTo);
    final AuthenticationRedirectStrategy authenticationRedirectStrategy = new DefaultAuthenticationRedirectStrategy();
    authenticationRedirectStrategy.redirect(request, response, urlToRedirectTo);

}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:27,代码来源:AbstractSamlProfileHandlerController.java

示例3: handleCallbackProfileRequest

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
/**
 * Handle callback profile request.
 *
 * @param response the response
 * @param request  the request
 * @throws Exception the exception
 */
@GetMapping(path = SamlIdPConstants.ENDPOINT_SAML2_SSO_PROFILE_POST_CALLBACK)
protected void handleCallbackProfileRequest(final HttpServletResponse response, final HttpServletRequest request) throws Exception {

    LOGGER.info("Received SAML callback profile request [{}]", request.getRequestURI());
    final AuthnRequest authnRequest = retrieveSamlAuthenticationRequestFromHttpRequest(request);
    if (authnRequest == null) {
        LOGGER.error("Can not validate the request because the original Authn request can not be found.");
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    final String ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
    if (StringUtils.isBlank(ticket)) {
        LOGGER.error("Can not validate the request because no [{}] is provided via the request", CasProtocolConstants.PARAMETER_TICKET);
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    final Pair<AuthnRequest, MessageContext> authenticationContext = buildAuthenticationContextPair(request, authnRequest);
    final Assertion assertion = validateRequestAndBuildCasAssertion(response, request, authenticationContext);
    buildSamlResponse(response, request, authenticationContext, assertion, SAMLConstants.SAML2_POST_BINDING_URI);
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:30,代码来源:SSOPostProfileCallbackHandlerController.java

示例4: validateRequestAndBuildCasAssertion

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
private Assertion validateRequestAndBuildCasAssertion(final HttpServletResponse response,
                                                      final HttpServletRequest request,
                                                      final Pair<AuthnRequest, MessageContext> pair) throws Exception {
    final AuthnRequest authnRequest = pair.getKey();
    final String ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
    final Cas30ServiceTicketValidator validator = new Cas30ServiceTicketValidator(this.serverPrefix);

    final HttpsURLConnectionFactory factory = new HttpsURLConnectionFactory();
    factory.setHostnameVerifier(this.hostnameVerifier);
    validator.setURLConnectionFactory(factory);
    
    validator.setRenew(authnRequest.isForceAuthn());
    final String serviceUrl = constructServiceUrl(request, response, pair);
    LOGGER.debug("Created service url for validation: [{}]", serviceUrl);
    final Assertion assertion = validator.validate(ticket, serviceUrl);
    logCasValidationAssertion(assertion);
    return assertion;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:SSOPostProfileCallbackHandlerController.java

示例5: internalInit

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
@Override
protected void internalInit(final WebContext context) {
    super.internalInit(context);

    CommonHelper.assertNotNull("configuration", configuration);
    configuration.setCallbackUrlResolver(this.getCallbackUrlResolver());
    configuration.init(context);

    setRedirectActionBuilder(ctx -> {
        final String loginUrl = configuration.getCallbackUrlResolver().compute(configuration.getLoginUrl(), ctx);
        final String redirectionUrl = CommonUtils.constructRedirectUrl(loginUrl, CasConfiguration.SERVICE_PARAMETER,
                computeFinalCallbackUrl(ctx), configuration.isRenew(), configuration.isGateway());
        logger.debug("redirectionUrl: {}", redirectionUrl);
        return RedirectAction.redirect(redirectionUrl);
    });
    setCredentialsExtractor(new TicketAndLogoutRequestExtractor(configuration, getName()));
    setAuthenticator(new CasAuthenticator(configuration, callbackUrl));
    addAuthorizationGenerator(new DefaultCasAuthorizationGenerator<>());
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:20,代码来源:CasClient.java

示例6: computeRedirectionToServerIfNecessary

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
private void computeRedirectionToServerIfNecessary(final WebContext context) throws HttpAction {
    final String relayStateValue = context.getRequestParameter(CasConfiguration.RELAY_STATE_PARAMETER);
    // if we have a state value -> redirect to the CAS server to continue the logout process
    if (CommonUtils.isNotBlank(relayStateValue)) {
        final StringBuilder buffer = new StringBuilder();
        buffer.append(configuration.getPrefixUrl());
        if (!configuration.getPrefixUrl().endsWith("/")) {
            buffer.append("/");
        }
        buffer.append("logout?_eventId=next&");
        buffer.append(CasConfiguration.RELAY_STATE_PARAMETER);
        buffer.append("=");
        buffer.append(CommonUtils.urlEncode(relayStateValue));
        final String redirectUrl = buffer.toString();
        logger.debug("Redirection url to the CAS server: {}", redirectUrl);
        throw HttpAction.redirect("Force redirect to CAS server for front channel logout", context, redirectUrl);
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:19,代码来源:TicketAndLogoutRequestExtractor.java

示例7: doGet

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
/**
 * @TODO: We have the opportunity to give back more to Shib than just the PRINCIPAL_NAME_KEY. Identify additional information
 * we can return as well as the best way to know when to do this.
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException,
        IOException {
    String ticket = CommonUtils.safeGetParameter(request, artifactParameterName);
    Object authnType = request.getSession().getAttribute(AUTHN_TYPE);
    Assertion assertion = null;
    try {
        ticketValidator.setRenew(null != authnType && authnType.toString().contains("&renew=true"));
        assertion = ticketValidator.validate(ticket, constructServiceUrl(request, response));
    } catch (final TicketValidationException e) {
        logger.error("Unable to validate login attempt.", e);
        boolean wasPassiveAttempt = null != authnType && authnType.toString().contains("&gateway=true");
        // If it was a passive attempt, send back the indicator that the responding provider cannot authenticate 
        // the principal passively, as has been requested. Otherwise, send the generic authn failed code.
        request.setAttribute(LoginHandler.AUTHENTICATION_ERROR_KEY, wasPassiveAttempt ? StatusCode.NO_PASSIVE_URI
                : StatusCode.AUTHN_FAILED_URI);
        AuthenticationEngine.returnToAuthenticationEngine(request, response);
        return;
    }
    for (CasToShibTranslator casToShibTranslator : translators) {
        casToShibTranslator.doTranslation(request, response, assertion);
    }
    AuthenticationEngine.returnToAuthenticationEngine(request, response);
}
 
开发者ID:Unicon,项目名称:shib-cas-authn2,代码行数:30,代码来源:CasCallbackServlet.java

示例8: doGet

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // NOTE: The CasAuthenticationToken can also be obtained using SecurityContextHolder.getContext().getAuthentication()
    final CasAuthenticationToken token = (CasAuthenticationToken) request.getUserPrincipal();
    // proxyTicket could be reused to make calls to to the CAS service even if the target url differs
    final String proxyTicket = token.getAssertion().getPrincipal().getProxyTicketFor(targetUrl);

    // Make a remote call to ourself. This is a bit silly, but it works well to demonstrate how to use proxy tickets.
    final String serviceUrl = targetUrl+"?ticket="+URLEncoder.encode(proxyTicket, "UTF-8");
    String proxyResponse = CommonUtils.getResponseFromServer(serviceUrl, "UTF-8");

    // modify the response and write it out to inform the user that it was obtained using a proxy ticket.
    proxyResponse = proxyResponse.replaceFirst("Secure Page", "Secure Page using a Proxy Ticket");
    proxyResponse = proxyResponse.replaceFirst("<p>",
            "<p>This page is rendered by "+getClass().getSimpleName()+" by making a remote call to the Secure Page using a proxy ticket ("+proxyTicket+") and inserts this message. ");
    final PrintWriter writer = response.getWriter();
    writer.write(proxyResponse);
}
 
开发者ID:lanen,项目名称:mint4j,代码行数:20,代码来源:ProxyTicketSampleServlet.java

示例9: constructServiceUrl

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
/**
 * Construct service url string.
 *
 * @param request  the request
 * @param response the response
 * @param pair     the pair
 * @return the string
 * @throws SamlException the saml exception
 */
protected String constructServiceUrl(final HttpServletRequest request,
                                     final HttpServletResponse response,
                                     final Pair<? extends SignableSAMLObject, MessageContext> pair) throws SamlException {
    final AuthnRequest authnRequest = AuthnRequest.class.cast(pair.getLeft());
    final MessageContext messageContext = pair.getRight();

    try (StringWriter writer = SamlUtils.transformSamlObject(this.configBean, authnRequest)) {
        final URLBuilder builder = new URLBuilder(this.callbackService.getId());
        builder.getQueryParams().add(
                new net.shibboleth.utilities.java.support.collection.Pair<>(SamlProtocolConstants.PARAMETER_ENTITY_ID,
                        SamlIdPUtils.getIssuerFromSamlRequest(authnRequest)));

        final String samlRequest = EncodingUtils.encodeBase64(writer.toString().getBytes(StandardCharsets.UTF_8));
        builder.getQueryParams().add(
                new net.shibboleth.utilities.java.support.collection.Pair<>(SamlProtocolConstants.PARAMETER_SAML_REQUEST,
                        samlRequest));
        builder.getQueryParams().add(
                new net.shibboleth.utilities.java.support.collection.Pair<>(SamlProtocolConstants.PARAMETER_SAML_RELAY_STATE,
                        SAMLBindingSupport.getRelayState(messageContext)));
        final String url = builder.buildURL();

        LOGGER.debug("Built service callback url [{}]", url);
        return CommonUtils.constructServiceUrl(request, response,
                url, this.serverName,
                CasProtocolConstants.PARAMETER_SERVICE,
                CasProtocolConstants.PARAMETER_TICKET, false);
    } catch (final Exception e) {
        throw new SamlException(e.getMessage(), e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:40,代码来源:AbstractSamlProfileHandlerController.java

示例10: validateRequestAndBuildCasAssertion

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
private Assertion validateRequestAndBuildCasAssertion(final HttpServletResponse response,
                                                      final HttpServletRequest request,
                                                      final WSFederationRequest fedRequest) throws Exception {
    final String ticket = CommonUtils.safeGetParameter(request, CasProtocolConstants.PARAMETER_TICKET);
    final Cas30ServiceTicketValidator validator = new Cas30ServiceTicketValidator(casProperties.getServer().getPrefix());
    final String serviceUrl = constructServiceUrl(request, response, fedRequest);
    LOGGER.debug("Created service url for validation: [{}]", serviceUrl);
    final Assertion assertion = validator.validate(ticket, serviceUrl);
    LOGGER.debug("Located CAS assertion [{}]", assertion);
    return assertion;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:12,代码来源:WSFederationValidateRequestCallbackController.java

示例11: redirectToIdentityProvider

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
private void redirectToIdentityProvider(final WSFederationRequest fedRequest, final HttpServletResponse response,
                                        final HttpServletRequest request, final WSFederationRegisteredService service) {
    try {
        final String serviceUrl = constructServiceUrl(request, response, fedRequest);
        LOGGER.debug("Created service url [{}] mapped to [{}]", serviceUrl, service);
        final boolean renew = shouldRenewAuthentication(fedRequest, request);
        final String initialUrl = CommonUtils.constructRedirectUrl(casProperties.getServer().getLoginUrl(),
                CasProtocolConstants.PARAMETER_SERVICE, serviceUrl, renew, false);
        LOGGER.debug("Redirecting authN request to [{}]", initialUrl);
        final AuthenticationRedirectStrategy authenticationRedirectStrategy = new DefaultAuthenticationRedirectStrategy();
        authenticationRedirectStrategy.redirect(request, response, initialUrl);
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:16,代码来源:WSFederationValidateRequestController.java

示例12: build

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
@Override
public RedirectAction build(final CasClient casClient, final WebContext context) {
    try {
        final CasConfiguration casConfiguration = casClient.getConfiguration();
        final String redirectionUrl = CommonUtils.constructRedirectUrl(casConfiguration.getLoginUrl(),
                CasProtocolConstants.PARAMETER_SERVICE,
                casClient.computeFinalCallbackUrl(context),
                casConfiguration.isRenew(), casConfiguration.isGateway());
        LOGGER.debug("Final redirect url is [{}]", redirectionUrl);
        return RedirectAction.redirect(redirectionUrl);
    } catch (final Exception e) {
        throw new IllegalArgumentException(e);
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:15,代码来源:OAuth20DefaultCasClientRedirectActionBuilder.java

示例13: retrieveCredentials

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
@Override
protected TokenCredentials retrieveCredentials(final WebContext context) throws HttpAction {
    init(context);
    try {
        String currentUrl = context.getFullRequestURL();
        String loginUrl = configuration.getLoginUrl();
        final CallbackUrlResolver callbackUrlResolver = configuration.getCallbackUrlResolver();
        if (callbackUrlResolver != null) {
            currentUrl = callbackUrlResolver.compute(currentUrl, context);
            loginUrl = callbackUrlResolver.compute(loginUrl, context);
        }

        final TokenCredentials credentials = getCredentialsExtractor().extract(context);
        if (credentials == null) {
            // redirect to the login page
            final String redirectionUrl = CommonUtils.constructRedirectUrl(loginUrl, CasConfiguration.SERVICE_PARAMETER,
                    currentUrl, configuration.isRenew(), false);
            logger.debug("redirectionUrl: {}", redirectionUrl);
            throw HttpAction.redirect("no ticket -> force redirect to login page", context, redirectionUrl);
        }

        // clean url from ticket parameter
        currentUrl = CommonHelper.substringBefore(currentUrl, "?" + CasConfiguration.TICKET_PARAMETER + "=");
        currentUrl = CommonHelper.substringBefore(currentUrl, "&" + CasConfiguration.TICKET_PARAMETER + "=");
        final CasAuthenticator casAuthenticator = new CasAuthenticator(configuration, currentUrl);
        casAuthenticator.init(context);
        casAuthenticator.validate(credentials, context);

        return credentials;
    } catch (CredentialsException e) {
        logger.error("Failed to retrieve or validate CAS credentials", e);
        return null;
    }
}
 
开发者ID:yaochi,项目名称:pac4j-plus,代码行数:35,代码来源:DirectCasClient.java

示例14: onAuthentication

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
public void onAuthentication(Authentication authentication, HttpServletRequest request,
                             HttpServletResponse response) {
    super.onAuthentication(authentication, request, response);

    HttpSession newSession = request.getSession();
    String token = CommonUtils.safeGetParameter(request, this.artifactParameterName, this.safeParameters);
    logger.debug("Recording the new session after the previous one was destroyed to prevent session fixation " +
            "(token " + token + ").");
    if ((token != null) && (!token.trim().isEmpty())) {
        this.sessionMappingStorage.addSessionById(token, newSession);
    }
}
 
开发者ID:helicalinsight,项目名称:helicalinsight,代码行数:13,代码来源:CasSessionFixationProtectionStrategy.java

示例15: constructServiceUrl

import org.jasig.cas.client.util.CommonUtils; //导入依赖的package包/类
/**
 * Use the CAS CommonUtils to build the CAS Service URL.
 */
protected String constructServiceUrl(final HttpServletRequest request, final HttpServletResponse response) {
    String serviceUrl = CommonUtils.constructServiceUrl(request, response, null, serverName, serviceParameterName, artifactParameterName, true);

    if ("embed".equalsIgnoreCase(entityIdLocation)) {
        serviceUrl += (new EntityIdParameterBuilder().getParameterString(request, false));
    }

    return serviceUrl;
}
 
开发者ID:Unicon,项目名称:shib-cas-authn3,代码行数:13,代码来源:ShibcasAuthServlet.java


注:本文中的org.jasig.cas.client.util.CommonUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。