Changes for page CAS Java klient

Last modified by Petr Abrahamczik on 16.04.2024 10:22

From version 20.1
edited by Petr Abrahamczik
on 16.04.2024 10:22
Change comment: There is no comment for this version
To version 13.2
edited by Petr Abrahamczik
on 07.02.2019 13:44
Change comment: There is no comment for this version

Summary

Details

Page properties
Content
... ... @@ -1,20 +1,21 @@
1 1  V ukázkovém příkladu je popsán základní způsob konfigurace webové aplikace v Javě pomocí [[Java Apereo CAS Client>>https://github.com/apereo/java-cas-client]]. Aplikace je schopna získat přihlášeného uživatele pomocí CAS v3 protokolu.
2 2  
3 -1. Do webové aplikace je potřeba přidat knihovny klienta https://mvnrepository.com/artifact/org.apereo.cas.client/cas-client-core buď přímo a nebo pomocí nějakého buildovacího nástroje např. Maven.(((
3 +1. Do webové aplikace je potřeba přidat knihovny klienta https://mvnrepository.com/artifact/org.jasig.cas.client/cas-client-core buď přímo a nebo pomocí nějakého buildovacího nástroje např. Maven.(((
4 4  {{code language="xml"}}
5 5  <dependency>
6 - <groupId>org.apereo.cas.client</groupId>
7 - <artifactId>cas-client-core</artifactId>
8 - <version>4.0.4</version>
6 + <groupId>org.jasig.cas.client</groupId>
7 + <artifactId>cas-client-core</artifactId>
8 + <version>3.5.1</version>
9 9  </dependency>
10 10  {{/code}}
11 11  )))
12 -1. Nakonfigurovat ##web.xml##. V uvedené konfiguraci je nutné nahradit adresu klienta ##https:~/~/klient.vsb.cz## adresou našeho serveru. V mapování filtru ##CAS Authentication Filter## je možné uvést místo ##/*## kontext do chráněné zóny aplikace např. ##/private/*## . (((
12 +1. Nakonfigurovat ##web.xml##. V uvedené konfiguraci je nutné nahradit adresu klienta https://klient.vsb.cz s URL našeho serveru. V mapování filtru ##CAS Authentication Filter## je možné uvést místo ##/*## kontext do chráněné zóny aplikace např.(((
13 +/private/*
13 13  
14 14  {{code language="xml"}}
15 15  <filter>
16 16   <filter-name>CAS Single Sign Out Filter</filter-name>
17 - <filter-class>org.apereo.cas.client.session.SingleSignOutFilter</filter-class>
18 + <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
18 18   <init-param>
19 19   <param-name>casServerUrlPrefix</param-name>
20 20   <param-value>https://www.sso.vsb.cz</param-value>
... ... @@ -23,7 +23,7 @@
23 23  
24 24  <filter>
25 25   <filter-name>CAS Authentication Filter</filter-name>
26 - <filter-class>org.apereo.cas.client.authentication.AuthenticationFilter</filter-class>
27 + <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
27 27   <init-param>
28 28   <param-name>casServerUrlPrefix</param-name>
29 29   <param-value>https://www.sso.vsb.cz</param-value>
... ... @@ -36,7 +36,7 @@
36 36  
37 37  <filter>
38 38   <filter-name>CAS Validation Filter</filter-name>
39 - <filter-class>org.apereo.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter</filter-class>
40 + <filter-class>org.jasig.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter</filter-class>
40 40   <init-param>
41 41   <param-name>casServerUrlPrefix</param-name>
42 42   <param-value>https://www.sso.vsb.cz</param-value>
... ... @@ -49,12 +49,12 @@
49 49  
50 50  <filter>
51 51   <filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
52 - <filter-class>org.apereo.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
53 + <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
53 53  </filter>
54 54  
55 55  <filter>
56 56   <filter-name>CAS Assertion Thread Local Filter</filter-name>
57 - <filter-class>org.apereo.cas.client.util.AssertionThreadLocalFilter</filter-class>
58 + <filter-class>org.jasig.cas.client.util.AssertionThreadLocalFilter</filter-class>
58 58  </filter>
59 59  
60 60  <filter-mapping>
... ... @@ -80,32 +80,96 @@
80 80  <filter-mapping>
81 81   <filter-name>CAS Assertion Thread Local Filter</filter-name>
82 82   <url-pattern>/*</url-pattern>
83 -</filter-mapping>
84 +</filter-mapping>
84 84  
85 85  <listener>
86 - <listener-class>org.apereo.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
87 + <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
87 87  </listener>
88 88  {{/code}}
90 +
91 +(% class="box" %)
92 +(((
93 +(% class="code" %)
94 +(((
95 +(% style="color:#008000; font-weight:bold" %)##**<filter>**##(%%)
96 +(% style="color:#008000; font-weight:bold" %)##**<filter-name>**##(%%)##CAS Single Sign Out Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
97 +(% style="color:#008000; font-weight:bold" %)**<filter-class>**(%%)org.jasig.cas.client.session.SingleSignOutFilter(% style="color:#008000; font-weight:bold" %)**</filter-class>**(%%)
98 +(% style="color:#008000; font-weight:bold" %)**<init-param>**(%%)
99 + (% style="color:#008000; font-weight:bold" %)**<param-name>**(%%)casServerUrlPrefix(% style="color:#008000; font-weight:bold" %)**</param-name>**(%%)
100 + (% style="color:#008000; font-weight:bold" %)**<param-value>**(%%)https:~/~/www.sso.vsb.cz(% style="color:#008000; font-weight:bold" %)**</param-value>**(%%)
101 +(% style="color:#008000; font-weight:bold" %)**</init-param>**(%%)
102 +(% style="color:#008000; font-weight:bold" %)**</filter>**(%%)
103 +\\(% style="color:#008000; font-weight:bold" %)**<filter>**(%%)
104 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS Authentication Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
105 +(% style="color:#008000; font-weight:bold" %)**<filter-class>**(%%)org.jasig.cas.client.authentication.AuthenticationFilter(% style="color:#008000; font-weight:bold" %)**</filter-class>**(%%)
106 +(% style="color:#008000; font-weight:bold" %)**<init-param>**(%%)
107 + (% style="color:#008000; font-weight:bold" %)**<param-name>**(%%)casServerUrlPrefix(% style="color:#008000; font-weight:bold" %)**</param-name>**(%%)
108 + (% style="color:#008000; font-weight:bold" %)**<param-value>**(%%)https:~/~/www.sso.vsb.cz(% style="color:#008000; font-weight:bold" %)**</param-value>**(%%)
109 +(% style="color:#008000; font-weight:bold" %)**</init-param>**(%%)
110 +(% style="color:#008000; font-weight:bold" %)**<init-param>**(%%)
111 + (% style="color:#008000; font-weight:bold" %)**<param-name>**(%%)serverName(% style="color:#008000; font-weight:bold" %)**</param-name>**(%%)
112 + (% style="color:#008000; font-weight:bold" %)**<param-value>**(%%)https:~/~/klient.vsb.cz(% style="color:#008000; font-weight:bold" %)**</param-value>**(%%)
113 +(% style="color:#008000; font-weight:bold" %)**</init-param>**(%%)
114 +(% style="color:#008000; font-weight:bold" %)**</filter>**(%%)
115 +
116 +(% style="color:#008000; font-weight:bold" %)**<filter>**(%%)
117 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS Validation Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
118 +(% style="color:#008000; font-weight:bold" %)**<filter-class>**(%%)org.jasig.cas.client.validation.Cas30ProxyReceivingTicketValidationFilter(% style="color:#008000; font-weight:bold" %)**</filter-class>**(%%)
119 +(% style="color:#008000; font-weight:bold" %)**<init-param>**(%%)
120 + (% style="color:#008000; font-weight:bold" %)**<param-name>**(%%)casServerUrlPrefix(% style="color:#008000; font-weight:bold" %)**</param-name>**(%%)
121 + (% style="color:#008000; font-weight:bold" %)**<param-value>**(%%)https:~/~/www.sso.vsb.cz(% style="color:#008000; font-weight:bold" %)**</param-value>**(%%)
122 +(% style="color:#008000; font-weight:bold" %)**</init-param>**(%%)
123 +(% style="color:#008000; font-weight:bold" %)**<init-param>**(%%)
124 + (% style="color:#008000; font-weight:bold" %)**<param-name>**(%%)serverName(% style="color:#008000; font-weight:bold" %)**</param-name>**(%%)
125 + (% style="color:#008000; font-weight:bold" %)**<param-value>**(%%)https:~/~/klient.vsb.cz(% style="color:#008000; font-weight:bold" %)**</param-value>**(%%)
126 +(% style="color:#008000; font-weight:bold" %)**</init-param>**(%%)
127 +(% style="color:#008000; font-weight:bold" %)**</filter>**(%%)
128 +\\(% style="color:#008000; font-weight:bold" %)**<filter>**(%%)
129 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS HttpServletRequest Wrapper Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
130 +(% style="color:#008000; font-weight:bold" %)**<filter-class>**(%%)org.jasig.cas.client.util.HttpServletRequestWrapperFilter(% style="color:#008000; font-weight:bold" %)**</filter-class>**(%%)
131 +(% style="color:#008000; font-weight:bold" %)**</filter>**(%%)
132 +\\(% style="color:#008000; font-weight:bold" %)**<filter>**(%%)
133 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS Assertion Thread Local Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
134 +(% style="color:#008000; font-weight:bold" %)**<filter-class>**(%%)org.jasig.cas.client.util.AssertionThreadLocalFilter(% style="color:#008000; font-weight:bold" %)**</filter-class>**(%%)
135 +(% style="color:#008000; font-weight:bold" %)**</filter>**(%%)
136 +\\(% style="color:#008000; font-weight:bold" %)**<filter-mapping>**(%%)
137 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS Single Sign Out Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
138 +(% style="color:#008000; font-weight:bold" %)**<url-pattern>**(%%)/*(% style="color:#008000; font-weight:bold" %)**</url-pattern>**(%%)
139 +(% style="color:#008000; font-weight:bold" %)**</filter-mapping>**(%%)
140 +\\(% style="color:#008000; font-weight:bold" %)**<filter-mapping>**(%%)
141 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS Authentication Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
142 +(% style="color:#008000; font-weight:bold" %)**<url-pattern>**(%%)/*(% style="color:#008000; font-weight:bold" %)**</url-pattern>**(%%)
143 +(% style="color:#008000; font-weight:bold" %)**</filter-mapping>**(%%)
144 +
145 +(% style="color:#008000; font-weight:bold" %)**<filter-mapping>**(%%)
146 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS Validation Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
147 +(% style="color:#008000; font-weight:bold" %)**<url-pattern>**(%%)/*(% style="color:#008000; font-weight:bold" %)**</url-pattern>**(%%)
148 +(% style="color:#008000; font-weight:bold" %)**</filter-mapping>**(%%)
149 +
150 +(% style="color:#008000; font-weight:bold" %)**<filter-mapping>**(%%)
151 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS HttpServletRequest Wrapper Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
152 +(% style="color:#008000; font-weight:bold" %)**<url-pattern>**(%%)/*(% style="color:#008000; font-weight:bold" %)**</url-pattern>**(%%)
153 +(% style="color:#008000; font-weight:bold" %)**</filter-mapping>**(%%)
154 +\\(% style="color:#008000; font-weight:bold" %)**<filter-mapping>**(%%)
155 +(% style="color:#008000; font-weight:bold" %)**<filter-name>**(%%)CAS Assertion Thread Local Filter(% style="color:#008000; font-weight:bold" %)**</filter-name>**(%%)
156 +(% style="color:#008000; font-weight:bold" %)**<url-pattern>**(%%)/*(% style="color:#008000; font-weight:bold" %)**</url-pattern>**(%%)
157 +(% style="color:#008000; font-weight:bold" %)**</filter-mapping>**(%%)
158 +\\(% style="color:#008000; font-weight:bold" %)**<listener>**(%%)
159 +(% style="color:#008000; font-weight:bold" %)**<listener-class>**(%%)org.jasig.cas.client.session.SingleSignOutHttpSessionListener(% style="color:#008000; font-weight:bold" %)**</listener-class>**(%%)
160 +(% style="color:#008000; font-weight:bold" %)**</listener>**(%%)##
89 89  )))
90 -1. Přihlášenou osobu v aplikaci lze pak jednoduše zjistit pomoci(((
91 -{{code language="java"}}
92 -request.getRemoteUser();
93 -{{/code}}
94 94  )))
95 -1. Připadné atributy osoby(((
96 -{{code language="java"}}
97 -import org.apereo.cas.client.authentication.AttributePrincipal;
98 -
99 -AttributePrincipal principal = (AttributePrincipal)request.getUserPrincipal();
100 -Map attributes = principal.getAttributes();
101 -{{/code}}
102 102  )))
103 103  1. Pro odhlášení uživatele z CAS je potřeba přistoupit na url ##https:~/~/www.sso.vsb.cz/logout##.(((
104 104   Před odhlášením z CAS je vhodné zrušit session v aplikaci klienta (zaleží to však na konkrétním klientu).
105 105  
106 - Pokud po odhlášení z CAS nechceme aby uživatel zůstal na odhlašovací stránce CASu, můžeme k odhlašovací url přidat parametr ##service##, který
167 + Pokud po odhlášení z CAS nechceme aby uživatel zůstal na odhlašovací stránce CASu, můžeme k odhlašovací url přidat parametr 'service', který
107 107   obsahuje url (nejlépe zakódovanou pomocí URL kódování) na kterou se má po odhlášení přesměrovat. Url musí obsahovat adresu, která je pro službu povolena.
108 108  
109 109   např. ##https:~/~/www.sso.vsb.cz/logout?service=https%3A%2F%2Fklient.vsb.cz##
110 110  )))
111 -
172 +1. Přihlášenou osobu v aplikaci lze pak jednoduše zjistit pomoci(((
173 +{{code language="java"}}
174 +request.getRemoteUser();
175 +{{/code}}
176 +)))