Java Code Examples for org.jasig.cas.services.RegisteredService#getTheme()

The following examples show how to use org.jasig.cas.services.RegisteredService#getTheme() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RegisteredServiceThemeBasedViewResolver.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
/**
 * Uses the viewName and the theme associated with the service.
 * being requested and returns the appropriate view.
 * @param viewName the name of the view to be resolved
 * @return a theme-based UrlBasedView
 * @throws Exception an exception
 */
@Override
protected AbstractUrlBasedView buildView(final String viewName) throws Exception {
    final RequestContext requestContext = RequestContextHolder.getRequestContext();
    final WebApplicationService service = WebUtils.getService(requestContext);
    final RegisteredService registeredService = this.servicesManager.findServiceBy(service);

    final String themeId = service != null && registeredService != null
            && registeredService.getAccessStrategy().isServiceAccessAllowed()
            && StringUtils.hasText(registeredService.getTheme()) ? registeredService.getTheme() : defaultThemeId;

    final String themePrefix = String.format("%s/%s/ui/", pathPrefix, themeId);
    LOGGER.debug("Prefix {} set for service {} with theme {}", themePrefix, service, themeId);

    //Build up the view like the base classes do, but we need to forcefully set the prefix for each request.
    //From UrlBasedViewResolver.buildView
    final InternalResourceView view = (InternalResourceView) BeanUtils.instantiateClass(getViewClass());
    view.setUrl(themePrefix + viewName + getSuffix());
    final String contentType = getContentType();
    if (contentType != null) {
        view.setContentType(contentType);
    }
    view.setRequestContextAttribute(getRequestContextAttribute());
    view.setAttributesMap(getAttributesMap());

    //From InternalResourceViewResolver.buildView
    view.setAlwaysInclude(false);
    view.setExposeContextBeansAsAttributes(false);
    view.setPreventDispatchLoop(true);

    LOGGER.debug("View resolved: {}", view.getUrl());

    return view;
}
 
Example 2
Source File: ServiceThemeResolver.java    From springboot-shiro-cas-mybatis with MIT License 5 votes vote down vote up
@Override
public String resolveThemeName(final HttpServletRequest request) {
    if (this.servicesManager == null) {
        return getDefaultThemeName();
    }
    // retrieve the user agent string from the request
    final String userAgent = request.getHeader("User-Agent");

    if (StringUtils.isBlank(userAgent)) {
        return getDefaultThemeName();
    }

    for (final Map.Entry<Pattern, String> entry : this.overrides.entrySet()) {
        if (entry.getKey().matcher(userAgent).matches()) {
            request.setAttribute("isMobile", "true");
            request.setAttribute("browserType", entry.getValue());
            break;
        }
    }

    final RequestContext context = RequestContextHolder.getRequestContext();
    final Service service = WebUtils.getService(context);
    if (service != null) {
        final RegisteredService rService = this.servicesManager.findServiceBy(service);
        if (rService != null && rService.getAccessStrategy().isServiceAccessAllowed()
                && StringUtils.isNotBlank(rService.getTheme())) {
            LOGGER.debug("Service [{}] is configured to use a custom theme [{}]", rService, rService.getTheme());
            final CasThemeResourceBundleMessageSource messageSource = new CasThemeResourceBundleMessageSource();
            messageSource.setBasename(rService.getTheme());
            if (messageSource.doGetBundle(rService.getTheme(), request.getLocale()) != null) {
                LOGGER.debug("Found custom theme [{}] for service [{}]", rService.getTheme(), rService);
                return rService.getTheme();
            } else {
                LOGGER.warn("Custom theme {} for service {} cannot be located. Falling back to default theme...",
                        rService.getTheme(), rService);
            }
        }
    }
    return getDefaultThemeName();
}
 
Example 3
Source File: ServiceThemeResolver.java    From cas4.0.x-server-wechat with Apache License 2.0 5 votes vote down vote up
@Override
public String resolveThemeName(final HttpServletRequest request) {
    if (this.servicesManager == null) {
        return getDefaultThemeName();
    }

    final Service service = WebUtils.getService(this.argumentExtractors, request);

    final RegisteredService rService = this.servicesManager.findServiceBy(service);

    // retrieve the user agent string from the request
    String userAgent = request.getHeader("User-Agent");

    if (userAgent == null) {
        return getDefaultThemeName();
    }

    for (final Map.Entry<Pattern, String> entry : this.overrides.entrySet()) {
        if (entry.getKey().matcher(userAgent).matches()) {
            request.setAttribute("isMobile", "true");
            request.setAttribute("browserType", entry.getValue());
            break;
        }
    }

    return service != null && rService != null && StringUtils.hasText(rService.getTheme())
            ? rService.getTheme() : getDefaultThemeName();
}
 
Example 4
Source File: ConfigurableUserAgentOverrideThemeResolver.java    From uPortal-start with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the theme for the service. This method's logic is taken from ServiceThemeResolver.
 *
 * @param request
 * @return configured theme for this service
 */
protected String resolveServiceThemeName(HttpServletRequest request) {
    if (this.servicesManager == null) {
        return getDefaultThemeName();
    }

    final Service service = WebUtils.getService(this.argumentExtractors, request);

    final RegisteredService rService = this.servicesManager.findServiceBy(service);

    return service != null && rService != null && StringUtils.hasText(rService.getTheme())
            ? rService.getTheme()
            : getDefaultThemeName();
}