Интеграция OpenSSO и сервера JasperReports

Я пытаюсь интегрировать Jasper Server 4.7.0 и OpenSSO 11.0.

Я выбрал способ использования OpenAM J2EE Agent и Spring Security J2EEPreAuthenticatedFilter.

Когда пользователь пытается получить доступ к домашней странице jasper, агент перенаправляет его на страницу входа в систему OpenAM, а затем, в случае успешной аутентификации, заполняет принципала пользователя в объекте HTTPServletRequest. Spring security J2EEPreAuthencticatedFilter получает принципала и, если он не равен нулю, считывает роли пользователей и предоставляет доступ к запрошенным ресурсам.

Проблема заключается в том, что после успешной аутентификации OpenAm J2EEPreAuthenticatedFilter возвращает значение null, и пользователь не может получить доступ к домашней странице jasperserver.

Почему J2EEPreAuthenticatedFilter не может получить принципала из объекта HttpServletRequest?

Я использую Tomcat 7 для сервера jasper.

Это фильтр агента OpenAm и ограничение безопасности в web.xml:

<filter>
        <filter-name>Agent</filter-name>
        <display-name>Agent</display-name>
        <description>OpenAM Policy Agent Filter</description>
        <filter-class>com.sun.identity.agents.filter.AmAgentFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>Agent</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>INCLUDE</dispatcher>
        <dispatcher>FORWARD</dispatcher>
        <dispatcher>ERROR</dispatcher>
    </filter-mapping>

<security-role>
    <role-name>ROLE_TESTER</role-name>
</security-role>

<security-constraint>
    <web-resource-collection>
        <web-resource-name>Authenticated</web-resource-name>
        <description></description>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>*</role-name>
    </auth-constraint>
</security-constraint>

Затем часть XML-контекста SpringSecurity:

 <bean id="filterChainProxy" class="org.springframework.security.util.FilterChainProxy">
        <property name="filterInvocationDefinitionSource">
            <value>
                CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
                PATTERN_TYPE_APACHE_ANT
                /xmla=httpSessionContextIntegrationFilter,${bean.loggingFilter},${bean.basicProcessingFilter},JIAuthenticationSynchronizer,anonymousProcessingFilter,basicAuthExceptionTranslationFilter,filterInvocationInterceptor
                /services/**=httpSessionContextIntegrationFilter,${bean.loggingFilter},${bean.portletAuthenticationProcessingFilter},${bean.basicProcessingFilter},${bean.passwordExpirationProcessingFilter},JIAuthenticationSynchronizer,anonymousProcessingFilter,wsBasicAuthExceptionTranslationFilter,filterInvocationInterceptor
                /rest/login=httpSessionContextIntegrationFilter,${bean.loggingFilter},encryptionFilter,restLoginAuthenticationFilter,JIAuthenticationSynchronizer,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor
                /rest/**=httpSessionContextIntegrationFilter,${bean.loggingFilter},${bean.portletAuthenticationProcessingFilter},${bean.basicProcessingFilter},${bean.passwordExpirationProcessingFilter},JIAuthenticationSynchronizer,anonymousProcessingFilter,wsBasicAuthExceptionTranslationFilter,filterInvocationInterceptor
                /**=httpSessionContextIntegrationFilter,encryptionFilter,multipartRequestWrapperFilter,webAppSecurityFilter,${bean.loggingFilter},${bean.userPreferencesFilter},j2eePreAuthFilter,${bean.userPreferencesFilter},${bean.basicProcessingFilter},requestParameterAuthenticationFilter,JIAuthenticationSynchronizer,anonymousProcessingFilter,exceptionTranslationFilter,filterInvocationInterceptor,switchUserProcessingFilter,iPadSupportFilter
            </value>
        </property>
    </bean>


        <!--  class="org.springframework.security.ui.preauth.j2ee.J2eePreAuthenticatedProcessingFilter"  -->
        <bean id="j2eePreAuthFilter" class="org.springframework.security.ui.preauth.j2ee.J2eePreAuthenticatedProcessingFilter">
        <property name="authenticationManager" ref="authenticationManager" />
        <property name="authenticationDetailsSource">
            <bean class="org.springframework.security.ui.preauth.j2ee.J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource">
                <property name="mappableRolesRetriever">
                    <bean class="org.springframework.security.ui.preauth.j2ee.WebXmlMappableAttributesRetriever">
                        <property name="webXmlInputStream">
                            <bean factory-bean="webXmlResource" factory-method="getInputStream"/>
                        </property>
                    </bean>
                </property>
                <property name="userRoles2GrantedAuthoritiesMapper">
                    <bean class="org.springframework.security.authoritymapping.SimpleAttributes2GrantedAuthoritiesMapper">
                        <property name="convertAttributeToUpperCase" value="true"/>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

    <bean id="preAuthenticatedProcessingFilterEntryPoint" class="org.springframework.security.ui.preauth.PreAuthenticatedProcessingFilterEntryPoint"/>

    <bean id="preAuthenticatedUserDetailsService" class="org.springframework.security.providers.preauth.PreAuthenticatedGrantedAuthoritiesUserDetailsService" />

    <bean id="webXmlResource" class="org.springframework.web.context.support.ServletContextResource">
        <constructor-arg ref="servletContext" />
        <constructor-arg value="/WEB-INF/web.xml" />
    </bean>

    <bean id="servletContext" class="org.springframework.web.context.support.ServletContextFactoryBean" />

И этот идентификатор является исходным кодом J2EEPreAuthenticatedFilter:

public class J2eePreAuthenticatedProcessingFilter extends AbstractPreAuthenticatedProcessingFilter {
    /**
     * Return the J2EE user name.
     */
    protected Object getPreAuthenticatedPrincipal(HttpServletRequest httpRequest) {
        Object principal = httpRequest.getUserPrincipal() == null ? null : httpRequest.getUserPrincipal().getName();
        if (logger.isDebugEnabled()) {
            logger.debug("PreAuthenticated J2EE principal: " + principal);
        }
        return principal;
    }

    /**
     * For J2EE container-based authentication there is no generic way to
     * retrieve the credentials, as such this method returns a fixed dummy
     * value.
     */
    protected Object getPreAuthenticatedCredentials(HttpServletRequest httpRequest) {
        return "N/A";
    }

    public int getOrder() {
        return 0;
    }
}

person user3243205    schedule 21.08.2014    source источник
comment
Одной настройки фильтра агента недостаточно для включения декларативной безопасности вашего веб-приложения. Вам также следует настроить необходимые ограничения безопасности в файле web.xml.   -  person Peter Major    schedule 21.08.2014
comment
Привет Питер! В моем web.xml есть ограничение безопасности. Добавляю в первое сообщение. Пользователь, имеющий доступ к jasper, имеет роль ROLE_TESTER.   -  person user3243205    schedule 22.08.2014


Ответы (1)


Я решаю проблему, просто добавляя следующий код в файл web.xml:

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.html</form-login-page>
        <form-error-page>/accessdenied.html</form-error-page>
    </form-login-config>
</login-config>

И удалите следующий код из web.xml:

<security-constraint>
   <web-resource-collection>
        <web-resource-name>JasperServerWebApp</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>NONE</transport-guarantee>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
person user3243205    schedule 02.09.2014