Форум программистов, компьютерный форум, киберфорум
Java EE (J2EE)
Войти
Регистрация
Восстановить пароль
Карта форума Темы раздела Блоги Сообщество Поиск Заказать работу  
 
Вежливость-главное оружие
233 / 234 / 86
Регистрация: 19.02.2013
Сообщений: 1,446
1

Rest authentication: Как сделать, чтобы url для получения token был свободен?

13.02.2016, 19:36. Показов 539. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Здравствуйте!

Пишу authentication для rest приложения. Использую Spring Security 4. Сейчас застрял на том, что не могу нормально настроить security. Вот, что имеется сейчас:

applicationContext.xml
Кликните здесь для просмотра всего текста

XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:sec="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans [url]http://www.springframework.org/schema/beans/spring-beans-4.0.xsd[/url]
          [url]http://www.springframework.org/schema/security[/url] http://www.springframework.org/schema/security/spring-security.xsd">
 
    <import resource="classpath*:securityServicesContext.xml"/>
    <import resource="classpath*:businessServicesContext.xml"/>
 
    <sec:http pattern="/rest/**" create-session="stateless" auto-config="false" entry-point-ref="unauthorizedEntryPoint">
        <sec:expression-handler ref="webSecurityExpressionHandler"/>
        <sec:custom-filter ref="customTokenAuthenticationFilter" position="FORM_LOGIN_FILTER"/>
        <sec:intercept-url pattern="/rest/login" access="permitAll"/>
        <sec:intercept-url pattern="/**" access="hasRole('USER')"/>
        <sec:csrf disabled="true"/>
    </sec:http>
 
    <sec:authentication-manager id="authenticationManager">
        <sec:authentication-provider ref="daoAuthenticationProvider"/>
    </sec:authentication-manager>
 
    <bean id="unauthorizedEntryPoint" class="com.itechart.security.web.security.UnauthorizedEntryPoint"/>
 
    <bean id="customTokenAuthenticationFilter"
          class="com.itechart.security.web.security.CustomTokenAuthenticationFilter">
        <constructor-arg name="defaultFilterProcessesUrl" value="/rest/**"/>
        <constructor-arg name="authenticationManager" ref="authenticationManager"/>
        <constructor-arg name="authenticationSuccessHandler">
            <bean class="com.itechart.security.web.security.TokenSimpleUrlAuthenticationSuccessHandler"/>
        </constructor-arg>
    </bean>
 
</beans>


web.xml
Кликните здесь для просмотра всего текста

XML
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
 
    <display-name>Security Web Application</display-name>
 
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
 
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
 
    <servlet>
        <servlet-name>dispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/dispatcherServlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>dispatcherServlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
 
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
 
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
 
    <resource-ref>
        <res-ref-name>jdbc/SecuritySampleDB</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
        <res-auth>Container</res-auth>
    </resource-ref>
 
    <welcome-file-list>
        <welcome-file>/app/index.html</welcome-file>
    </welcome-file-list>
 
</web-app>


Получается, что когда я отправляю username&password на /rest/login, то попадаю в CustomTokenAuthenticationFilter, а мне это не нужно, так как по этому url я должен поучить token и все. А все остальные urls должны фильтроваться как положено.

Как это сделать?

Заранее спс!
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
13.02.2016, 19:36
Ответы с готовыми решениями:

Как сделать чтобы Label был сверху картинки и был прозрачен?
Как сделать чтобы label был сверху картинки и он был прозрачен?

Как сделать, чтобы открывающийся файл Word был только для чтения?
Всем привет.У меня в программе открывается файл word, открываю его вот так Dim myProcess As New...

как сделать таблицу в исходнике, чтобы она выводилась на экран? вот код. нужно, чтобы в одной колонке был Х ,
Код в С #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; int main() { float...

Как выполнить запрос на получения url для загрузки картинки
как выполнить запрос на получения url для загрузки картинки в одноклассниках?? можете привести...

0
13.02.2016, 19:36
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
13.02.2016, 19:36
Помогаю со студенческими работами здесь

Правильный REST URL для эндпоинта
Есть эндпоинт который в данный момент распологается по адресу /force-update. Он делает апдейт с...

Правильный REST URL для эндпоинта
Предположим есть два микросервиса. В обоих микросервисах есть две одинаковые сущности, предположим...

Как сделать чтобы был вывод n с клавиатуры?
Вообщем как сделать чтобы был еще вывод n. Отдельно еще скрин скинул :-using System; namespace...

Как сделать чтобы iframe был по центру
Как сделать чтобы iframe был по центру страницы?? Был отцентрован &lt;h2&gt;Местоположение на карте...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru