You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by gi...@apache.org on 2021/05/18 21:34:56 UTC
[directory-site] branch asf-site updated: Updated site from master
(22d6d23ae2f8c9abc15ebe34754e916be479f54e)
This is an automated email from the ASF dual-hosted git repository.
git-site-role pushed a commit to branch asf-site
in repository https://gitbox.apache.org/repos/asf/directory-site.git
The following commit(s) were added to refs/heads/asf-site by this push:
new 9846af2 Updated site from master (22d6d23ae2f8c9abc15ebe34754e916be479f54e)
9846af2 is described below
commit 9846af2daa501e76c901ee1c72672f690ca8b53a
Author: jenkins <bu...@apache.org>
AuthorDate: Tue May 18 21:34:52 2021 +0000
Updated site from master (22d6d23ae2f8c9abc15ebe34754e916be479f54e)
---
content/fortress/testimonials.html | 560 ++++++++++++++++++-------------------
content/sitemap.xml | 4 +-
2 files changed, 276 insertions(+), 288 deletions(-)
diff --git a/content/fortress/testimonials.html b/content/fortress/testimonials.html
index e4b9890..ea097e3 100644
--- a/content/fortress/testimonials.html
+++ b/content/fortress/testimonials.html
@@ -158,299 +158,289 @@
<h3 id="server-side-development">Server side development:</h3>
<h4 id="1-the-authentication-handler">1. The Authentication Handler</h4>
<p>The interesting part for this solution is how to maintain both the <a href="https://www.apereo.org/projects/cas">Apereo CAS</a> and Apache Fortress sessions. Luckily, <strong>CAS</strong> is using a token for maintaining their session and that token is also designed to have some extended attributes included with it. Using this knowledge, we can modify the profile given by <strong>CAS</strong> Server to the client. Let’s have a look what I’ve done with combining the <a hre [...]
-<pre><code>:::Java
-
-/*
- * Copyright 2017 to PT. Global Digital Niaga(Blibli.com)
- *
- * Licensed under the Apache License, Version 2.0; you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.gdn.iam.cas;
-
-import java.io.StringWriter;
-import java.security.GeneralSecurityException;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-
-import org.apache.directory.fortress.core.AccessMgr;
-import org.apache.directory.fortress.core.model.Session;
-import org.apache.directory.fortress.core.model.User;
-import org.jasig.cas.authentication.HandlerResult;
-import org.jasig.cas.authentication.PreventedException;
-import org.jasig.cas.authentication.UsernamePasswordCredential;
-import org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class IamAuthenticationHandler extends AbstractUsernamePasswordAuthenticationHandler {
-
- private static final Logger LOG = LoggerFactory.getLogger(IamAuthenticationHandler.class);
-
- private AccessMgr accessManager;
- private JAXBContext jaxbContext;
- private Marshaller marshaller;
-
- public IamAuthenticationHandler() {
- try {
- jaxbContext = JAXBContext.newInstance(Session.class);
- marshaller = jaxbContext.createMarshaller();
- } catch (JAXBException e) {
- LOG.error("cannot bind Session with jaxb context", e);
- }
- }
-
- @Override
- protected HandlerResult authenticateUsernamePasswordInternal(
- UsernamePasswordCredential usernamePasswordCredential)
- throws GeneralSecurityException, PreventedException {
- String username = usernamePasswordCredential.getUsername();
- String password = usernamePasswordCredential.getPassword();
- Session iamSession = null;
- String iamXmlSession = null;
- try {
- LOG.trace("trying to authenticate username : {}, password : {}",
- new Object[] {username, password});
- iamSession = accessManager.createSession(new User(username, password.toCharArray()), false);
- LOG.trace("iam session : {}", iamSession);
- if (iamSession != null) {
- StringWriter writer = new StringWriter();
- marshaller.marshal(iamSession, writer);
- iamXmlSession = writer.toString();
- LOG.trace("iam xml session : {}", iamXmlSession);
- Map<String, Object> attributes = new HashMap<>();
- attributes.put("iamSession", iamXmlSession);
- return createHandlerResult(usernamePasswordCredential,
- principalFactory.createPrincipal(username, attributes), null);
- }
- } catch (org.apache.directory.fortress.core.SecurityException e) {
- String errorMessage = "IAM authentication failed for [" + username + "]";
- LOG.trace(errorMessage);
- throw new GeneralSecurityException(errorMessage);
- } catch (JAXBException e) {
- String errorMessage = "cannot marshalling session with value : " + iamSession == null ? "null"
- : iamSession.toString();
- LOG.trace(errorMessage);
- throw new GeneralSecurityException(errorMessage);
- }
- LOG.trace("returning default handler");
- return createHandlerResult(usernamePasswordCredential,
- principalFactory.createPrincipal(username), null);
- }
-
- public AccessMgr getAccessManager() {
- return accessManager;
- }
-
- public void setAccessManager(AccessMgr accessManager) {
- this.accessManager = accessManager;
- }
-
-}
-</code></pre>
-<p>In the above source code you can see how I construct a new principal by creating a new attribute map with values contained withing the <em>Apache Fortress</em> Session xml.</p>
+<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-Java" data-lang="Java">
+ <span style="color:#080;font-style:italic">/*
+</span><span style="color:#080;font-style:italic"> * Copyright 2017 to PT. Global Digital Niaga(Blibli.com)
+</span><span style="color:#080;font-style:italic"> *
+</span><span style="color:#080;font-style:italic"> * Licensed under the Apache License, Version 2.0; you may not use this file except in compliance
+</span><span style="color:#080;font-style:italic"> * with the License. You may obtain a copy of the License at
+</span><span style="color:#080;font-style:italic"> *
+</span><span style="color:#080;font-style:italic"> * http://www.apache.org/licenses/LICENSE-2.0
+</span><span style="color:#080;font-style:italic"> *
+</span><span style="color:#080;font-style:italic"> * Unless required by applicable law or agreed to in writing, software distributed under the License
+</span><span style="color:#080;font-style:italic"> * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+</span><span style="color:#080;font-style:italic"> * or implied. See the License for the specific language governing permissions and limitations under
+</span><span style="color:#080;font-style:italic"> * the License.
+</span><span style="color:#080;font-style:italic"> */</span>
+ <span style="color:#a2f;font-weight:bold">package</span> <span style="color:#00f;font-weight:bold">com.gdn.iam.cas</span><span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">java.io.StringWriter</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">java.security.GeneralSecurityException</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">java.util.HashMap</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">java.util.Map</span><span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">javax.xml.bind.JAXBContext</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">javax.xml.bind.JAXBException</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">javax.xml.bind.Marshaller</span><span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.apache.directory.fortress.core.AccessMgr</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.apache.directory.fortress.core.model.Session</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.apache.directory.fortress.core.model.User</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.jasig.cas.authentication.HandlerResult</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.jasig.cas.authentication.PreventedException</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.jasig.cas.authentication.UsernamePasswordCredential</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.slf4j.Logger</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.slf4j.LoggerFactory</span><span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">class</span> <span style="color:#00f">IamAuthenticationHandler</span> <span style="color:#a2f;font-weight:bold">extends</span> AbstractUsernamePasswordAuthenticationHandler <span style="color:#666">{</span>
+
+ <span style="color:#a2f;font-weight:bold">private</span> <span style="color:#a2f;font-weight:bold">static</span> <span style="color:#a2f;font-weight:bold">final</span> Logger LOG <span style="color:#666">=</span> LoggerFactory<span style="color:#666">.</span><span style="color:#b44">getLogger</span><span style="color:#666">(</span>IamAuthenticationHandler<span style="color:#666">.</span><span style="color:#b44">class</span><span style="color:#666">)</span><span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">private</span> AccessMgr accessManager<span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">private</span> JAXBContext jaxbContext<span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">private</span> Marshaller marshaller<span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">public</span> <span style="color:#00a000">IamAuthenticationHandler</span><span style="color:#666">(</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">try</span> <span style="color:#666">{</span>
+ jaxbContext <span style="color:#666">=</span> JAXBContext<span style="color:#666">.</span><span style="color:#b44">newInstance</span><span style="color:#666">(</span>Session<span style="color:#666">.</span><span style="color:#b44">class</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ marshaller <span style="color:#666">=</span> jaxbContext<span style="color:#666">.</span><span style="color:#b44">createMarshaller</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>JAXBException e<span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">error</span><span style="color:#666">(</span><span style="color:#b44">"cannot bind Session with jaxb context"</span><span style="color:#666">,</span> e<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span>
+
+ <span style="color:#a2f">@Override</span>
+ <span style="color:#a2f;font-weight:bold">protected</span> HandlerResult <span style="color:#00a000">authenticateUsernamePasswordInternal</span><span style="color:#666">(</span>
+ UsernamePasswordCredential usernamePasswordCredential<span style="color:#666">)</span>
+ <span style="color:#a2f;font-weight:bold">throws</span> GeneralSecurityException<span style="color:#666">,</span> PreventedException <span style="color:#666">{</span>
+ String username <span style="color:#666">=</span> usernamePasswordCredential<span style="color:#666">.</span><span style="color:#b44">getUsername</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ String password <span style="color:#666">=</span> usernamePasswordCredential<span style="color:#666">.</span><span style="color:#b44">getPassword</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ Session iamSession <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">;</span>
+ String iamXmlSession <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">try</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">trace</span><span style="color:#666">(</span><span style="color:#b44">"trying to authenticate username : {}, password : {}"</span><span style="color:#666">,</span>
+ <span style="color:#a2f;font-weight:bold">new</span> Object<span style="color:#666">[</span><span style="color:#666">]</span> <span style="color:#666">{</span>username<span style="color:#666">,</span> password<span style="color:#666">}</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ iamSession <span style="color:#666">=</span> accessManager<span style="color:#666">.</span><span style="color:#b44">createSession</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> User<span style="color:#666">(</span>username<span style="color:#666">,</span> password<span style="color:#666">.</span><span style="color:#b44">toCharArray</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</spa [...]
+ LOG<span style="color:#666">.</span><span style="color:#b44">trace</span><span style="color:#666">(</span><span style="color:#b44">"iam session : {}"</span><span style="color:#666">,</span> iamSession<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span> <span style="color:#666">(</span>iamSession <span style="color:#666">!</span><span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ StringWriter writer <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> StringWriter<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ marshaller<span style="color:#666">.</span><span style="color:#b44">marshal</span><span style="color:#666">(</span>iamSession<span style="color:#666">,</span> writer<span style="color:#666">)</span><span style="color:#666">;</span>
+ iamXmlSession <span style="color:#666">=</span> writer<span style="color:#666">.</span><span style="color:#b44">toString</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">trace</span><span style="color:#666">(</span><span style="color:#b44">"iam xml session : {}"</span><span style="color:#666">,</span> iamXmlSession<span style="color:#666">)</span><span style="color:#666">;</span>
+ Map<span style="color:#666"><</span>String<span style="color:#666">,</span> Object<span style="color:#666">></span> attributes <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> HashMap<span style="color:#666"><</span><span style="color:#666">></span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ attributes<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span><span style="color:#b44">"iamSession"</span><span style="color:#666">,</span> iamXmlSession<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">return</span> createHandlerResult<span style="color:#666">(</span>usernamePasswordCredential<span style="color:#666">,</span>
+ principalFactory<span style="color:#666">.</span><span style="color:#b44">createPrincipal</span><span style="color:#666">(</span>username<span style="color:#666">,</span> attributes<span style="color:#666">)</span><span style="color:#666">,</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>org<span style="color:#666">.</span><span style="color:#b44">apache</span><span style="color:#666">.</span><span style="color:#b44">directory</span><span style="color:#666">.</span><span style="color:#b44">fortress</span><span style="color:#666">.</span><span style="color:#b44">core</span><span style="color:#666">.</span><span style="color:#b44">SecurityExcept [...]
+ String errorMessage <span style="color:#666">=</span> <span style="color:#b44">"IAM authentication failed for ["</span> <span style="color:#666">+</span> username <span style="color:#666">+</span> <span style="color:#b44">"]"</span><span style="color:#666">;</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">trace</span><span style="color:#666">(</span>errorMessage<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">throw</span> <span style="color:#a2f;font-weight:bold">new</span> GeneralSecurityException<span style="color:#666">(</span>errorMessage<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>JAXBException e<span style="color:#666">)</span> <span style="color:#666">{</span>
+ String errorMessage <span style="color:#666">=</span> <span style="color:#b44">"cannot marshalling session with value : "</span> <span style="color:#666">+</span> iamSession <span style="color:#666">=</span><span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span> <span style="color:#666">?</span> <span style="color:#b44">"null"</span>
+ <span style="color:#666">:</span> iamSession<span style="color:#666">.</span><span style="color:#b44">toString</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">trace</span><span style="color:#666">(</span>errorMessage<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">throw</span> <span style="color:#a2f;font-weight:bold">new</span> GeneralSecurityException<span style="color:#666">(</span>errorMessage<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">trace</span><span style="color:#666">(</span><span style="color:#b44">"returning default handler"</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">return</span> createHandlerResult<span style="color:#666">(</span>usernamePasswordCredential<span style="color:#666">,</span>
+ principalFactory<span style="color:#666">.</span><span style="color:#b44">createPrincipal</span><span style="color:#666">(</span>username<span style="color:#666">)</span><span style="color:#666">,</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+
+ <span style="color:#a2f;font-weight:bold">public</span> AccessMgr <span style="color:#00a000">getAccessManager</span><span style="color:#666">(</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">return</span> accessManager<span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+
+ <span style="color:#a2f;font-weight:bold">public</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">setAccessManager</span><span style="color:#666">(</span>AccessMgr accessManager<span style="color:#666">)</span> <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">this</span><span style="color:#666">.</span><span style="color:#b44">accessManager</span> <span style="color:#666">=</span> accessManager<span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+
+ <span style="color:#666">}</span>
+</code></pre></div><p>In the above source code you can see how I construct a new principal by creating a new attribute map with values contained withing the <em>Apache Fortress</em> Session xml.</p>
<h4 id="2-the-attribute-populator">2. The Attribute Populator</h4>
<p>In order to populate fortress and pass it on to the client we need to override the <em>casServiceValidationSuccess.jsp</em> file, located at <em>WEB-INF/view/jsp/protocol/2.0/</em>, since its default view won’t populating the necessary attributes. Here is how I was able to accomplish that:</p>
-<pre><code>:::XML
-
-<%@ page session="false" contentType="application/xml; charset=UTF-8" %>
-<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
-<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
-<cas:serviceResponse xmlns:cas='http://www.yale.edu/tp/cas'>
- <!-- cas 2 validation success -->
- <cas:authenticationSuccess>
- <cas:user>${fn:escapeXml(assertion.primaryAuthentication.principal.id)}</cas:user>
- <c:if test="${not empty assertion.primaryAuthentication.principal.attributes}">
- <cas:attributes>
- <c:forEach var="attr" items="${assertion.primaryAuthentication.principal.attributes}" >
- <cas:${fn:escapeXml(attr.key)}><![CDATA[${attr.value}]]></cas:${fn:escapeXml(attr.key)}>
- </c:forEach>
- </cas:attributes>
- </c:if>
- <c:if test="${not empty pgtIou}">
- <cas:proxyGrantingTicket>${pgtIou}</cas:proxyGrantingTicket>
- </c:if>
- <c:if test="${fn:length(assertion.chainedAuthentications) > 1}">
- <cas:proxies>
- <c:forEach var="proxy" items="${assertion.chainedAuthentications}" varStatus="loopStatus" begin="0" end="${fn:length(assertion.chainedAuthentications)-2}" step="1">
- <cas:proxy>${fn:escapeXml(proxy.principal.id)}</cas:proxy>
- </c:forEach>
- </cas:proxies>
- </c:if>
- </cas:authenticationSuccess>
-</cas:serviceResponse>
-</code></pre>
-<p>One thing that I love about <strong>CAS</strong>, even if you correctly extracted the attribute at this page (or maybe you just got hacked at this page), <strong>CAS</strong> is able to protect the returned attributes by changing the services registry configuration. see the <em>HTTPSandIMAPS-10000001.json</em> file. I’ve put <em>ReturnAllAttributeReleasePolicy</em> type for debuging all the attributes returned, you can change it later to make your application more secure as well.</p>
+<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-XML" data-lang="XML">
+ <span style=""><</span>%@ page session="false" contentType="application/xml; charset=UTF-8" %>
+ <span style=""><</span>%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+ <span style=""><</span>%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
+ <span style="color:#008000;font-weight:bold"><cas:serviceResponse</span> <span style="color:#b44">xmlns:cas=</span><span style="color:#b44">'http://www.yale.edu/tp/cas'</span><span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#080;font-style:italic"><!--</span><span style="color:#080;font-style:italic"> cas 2 validation success </span><span style="color:#080;font-style:italic">--></span>
+ <span style="color:#008000;font-weight:bold"><cas:authenticationSuccess</span><span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#008000;font-weight:bold"><cas:user</span><span style="color:#008000;font-weight:bold">></span>${fn:escapeXml(assertion.primaryAuthentication.principal.id)}<span style="color:#008000;font-weight:bold"></cas:user></span>
+ <span style="color:#008000;font-weight:bold"><c:if</span> <span style="color:#b44">test=</span><span style="color:#b44">"${not empty assertion.primaryAuthentication.principal.attributes}"</span><span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#008000;font-weight:bold"><cas:attributes</span><span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#008000;font-weight:bold"><c:forEach</span> <span style="color:#b44">var=</span><span style="color:#b44">"attr"</span> <span style="color:#b44">items=</span><span style="color:#b44">"${assertion.primaryAuthentication.principal.attributes}"</span> <span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#008000;font-weight:bold"><cas:</span><span style="">$</span><span style="">{</span><span style="">f</span><span style="">n</span><span style="">:</span><span style="">e</span><span style="">s</span><span style="">c</span><span style="">a</span><span style="">p</span><span style="">e</span><span style="">X</span><span style="">m</span><span style="">l</span><span style="">(</span><span style="">a</span><span style="">t</span><span style="">t</spa [...]
+ <span style="color:#008000;font-weight:bold"></c:forEach></span>
+ <span style="color:#008000;font-weight:bold"></cas:attributes></span>
+ <span style="color:#008000;font-weight:bold"></c:if></span>
+ <span style="color:#008000;font-weight:bold"><c:if</span> <span style="color:#b44">test=</span><span style="color:#b44">"${not empty pgtIou}"</span><span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#008000;font-weight:bold"><cas:proxyGrantingTicket</span><span style="color:#008000;font-weight:bold">></span>${pgtIou}<span style="color:#008000;font-weight:bold"></cas:proxyGrantingTicket></span>
+ <span style="color:#008000;font-weight:bold"></c:if></span>
+ <span style="color:#008000;font-weight:bold"><c:if</span> <span style="color:#b44">test=</span><span style="color:#b44">"${fn:length(assertion.chainedAuthentications) > 1}"</span><span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#008000;font-weight:bold"><cas:proxies</span><span style="color:#008000;font-weight:bold">></span>
+ <span style="color:#008000;font-weight:bold"><c:forEach</span> <span style="color:#b44">var=</span><span style="color:#b44">"proxy"</span> <span style="color:#b44">items=</span><span style="color:#b44">"${assertion.chainedAuthentications}"</span> <span style="color:#b44">varStatus=</span><span style="color:#b44">"loopStatus"</span> <span style="color:#b44">begin=</span><span style="color:#b44">"0"</span> <span style="color:#b44">end=</sp [...]
+ <span style="color:#008000;font-weight:bold"><cas:proxy</span><span style="color:#008000;font-weight:bold">></span>${fn:escapeXml(proxy.principal.id)}<span style="color:#008000;font-weight:bold"></cas:proxy></span>
+ <span style="color:#008000;font-weight:bold"></c:forEach></span>
+ <span style="color:#008000;font-weight:bold"></cas:proxies></span>
+ <span style="color:#008000;font-weight:bold"></c:if></span>
+ <span style="color:#008000;font-weight:bold"></cas:authenticationSuccess></span>
+ <span style="color:#008000;font-weight:bold"></cas:serviceResponse></span>
+</code></pre></div><p>One thing that I love about <strong>CAS</strong>, even if you correctly extracted the attribute at this page (or maybe you just got hacked at this page), <strong>CAS</strong> is able to protect the returned attributes by changing the services registry configuration. see the <em>HTTPSandIMAPS-10000001.json</em> file. I’ve put <em>ReturnAllAttributeReleasePolicy</em> type for debuging all the attributes returned, you can change it later to make your application more s [...]
<h4 id="3-apache-ignite-for-ticket-replication">3. Apache Ignite For Ticket Replication</h4>
<p>To have a production readiness we need to somehow manage a high availability requirement, so we’re not just using a single <strong>CAS</strong> server. That is why we needed to have a centralized or distributed ticket repository, to allow <strong>CAS</strong> to scale. To scale the ticket repository, I chose <a href="https://ignite.apache.org/">Apache Ignite</a> for distributing the tickets. To Implement is very simple, and is also written about in <a href="https://www.apereo.or [...]
<h3 id="client-side-development">Client side development:</h3>
<h4 id="1-the-spring-voter">1. The Spring Voter</h4>
<p><strong>Spring</strong> is a great framework, they allow you to add your own interceptors to use your own implementation. <em>WebExpressionVoter</em> is the class you need to extend in order to override the normal spring decision mechanism. Usually you will use xml + regex for registering the condition. However, xml + regex is not the approach I wanted for my development team. See below code snippet, to understand what I did to make this more dynamic.</p>
-<pre><code>:::Java
- @Override
- @SuppressWarnings("static-access")
- public int vote(Authentication authentication, FilterInvocation fi,
- Collection<ConfigAttribute> attributes) {
- Authentication securityContextAuthentication =
- SecurityContextHolder.getContext().getAuthentication();
- int result = super.vote(securityContextAuthentication, fi, attributes);
- if (System.getenv(IAM_SECURITY_PARAMETER) != null) {
- LOG.warn("iam security is disable, enable all access mode is enable");
- return result;
- } else {
- LOG.debug("authentication = {}",
- ToStringBuilder.reflectionToString(securityContextAuthentication));
- LOG.debug("super vote for : {}", result);
- if (super.ACCESS_GRANTED == result) {
- String requestMethod = fi.getRequest().getMethod().toLowerCase();
- String filterUrl = getFilterUrl(fi.getHttpRequest());
- if (filterUrl == null) {
- return result;
- }
- try {
- CasAuthenticationToken casAuthenticationToken =
- ((CasAuthenticationToken) securityContextAuthentication);
- LOG.debug("assertion : {}",
- ToStringBuilder.reflectionToString(casAuthenticationToken.getAssertion()));
- String iamSessionXml = (String) casAuthenticationToken.getAssertion().getAttributes()
- .get(IAM_SESSION_ATTRIBUTE_KEY);
- LOG.debug("iam session xml == {}", iamSessionXml);
- Session iamSession = sessionCache.getIfPresent(casAuthenticationToken.getKeyHash());
- if (iamSession == null) {
- Unmarshaller unmarshaller = null;
- try {
- unmarshaller = context.createUnmarshaller();
- } catch (JAXBException ex) {
- LOG.warn("cannot create unmarshaller : ", ex);
- }
- iamSession = (Session) unmarshaller.unmarshal(new StringReader(iamSessionXml));
- sessionCache.put(casAuthenticationToken.getKeyHash(), iamSession);
- }
- StringBuilder sessionPermissionKeyBuilder = new StringBuilder(iamSession.getSessionId()).append(filterUrl).append(requestMethod);
- Boolean isAllowed = accessCache.getIfPresent(sessionPermissionKeyBuilder.toString());
- if(isAllowed == null) {
- isAllowed = accessManager.checkAccess(iamSession, new Permission(filterUrl, requestMethod));
- accessCache.put(sessionPermissionKeyBuilder.toString(), isAllowed);
- }
- LOG.debug("{} is {} to access {} with method {}",
- new Object[] {securityContextAuthentication.getName(),
- isAllowed ? "granted" : "denied", filterUrl, requestMethod});
- if (isAllowed) {
- return super.ACCESS_GRANTED;
- }
- } catch (Exception e) {
- LOG.error("catch exception when communicate with iam server", e);
- }
- }
- return super.ACCESS_DENIED;
- }
- }
-</code></pre>
-<p>Yep, I’m calling fortress to check if the user is allowed to access fortress permissions or not.</p>
+<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-Java" data-lang="Java"> <span style="color:#a2f">@Override</span>
+ <span style="color:#a2f">@SuppressWarnings</span><span style="color:#666">(</span><span style="color:#b44">"static-access"</span><span style="color:#666">)</span>
+ <span style="color:#a2f;font-weight:bold">public</span> <span style="color:#0b0;font-weight:bold">int</span> <span style="color:#00a000">vote</span><span style="color:#666">(</span>Authentication authentication<span style="color:#666">,</span> FilterInvocation fi<span style="color:#666">,</span>
+ Collection<span style="color:#666"><</span>ConfigAttribute<span style="color:#666">></span> attributes<span style="color:#666">)</span> <span style="color:#666">{</span>
+ Authentication securityContextAuthentication <span style="color:#666">=</span>
+ SecurityContextHolder<span style="color:#666">.</span><span style="color:#b44">getContext</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">getAuthentication</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#0b0;font-weight:bold">int</span> result <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">super</span><span style="color:#666">.</span><span style="color:#b44">vote</span><span style="color:#666">(</span>securityContextAuthentication<span style="color:#666">,</span> fi<span style="color:#666">,</span> attributes<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span> <span style="color:#666">(</span>System<span style="color:#666">.</span><span style="color:#b44">getenv</span><span style="color:#666">(</span>IAM_SECURITY_PARAMETER<span style="color:#666">)</span> <span style="color:#666">!</span><span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">warn</span><span style="color:#666">(</span><span style="color:#b44">"iam security is disable, enable all access mode is enable"</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">return</span> result<span style="color:#666">;</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">else</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"authentication = {}"</span><span style="color:#666">,</span>
+ ToStringBuilder<span style="color:#666">.</span><span style="color:#b44">reflectionToString</span><span style="color:#666">(</span>securityContextAuthentication<span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"super vote for : {}"</span><span style="color:#666">,</span> result<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span> <span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">super</span><span style="color:#666">.</span><span style="color:#b44">ACCESS_GRANTED</span> <span style="color:#666">=</span><span style="color:#666">=</span> result<span style="color:#666">)</span> <span style="color:#666">{</span>
+ String requestMethod <span style="color:#666">=</span> fi<span style="color:#666">.</span><span style="color:#b44">getRequest</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">getMethod</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">toLowerCase</span><span style="color:#666">(</span><span style="color:#666">)</span> [...]
+ String filterUrl <span style="color:#666">=</span> getFilterUrl<span style="color:#666">(</span>fi<span style="color:#666">.</span><span style="color:#b44">getHttpRequest</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span> <span style="color:#666">(</span>filterUrl <span style="color:#666">=</span><span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">return</span> result<span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#a2f;font-weight:bold">try</span> <span style="color:#666">{</span>
+ CasAuthenticationToken casAuthenticationToken <span style="color:#666">=</span>
+ <span style="color:#666">(</span><span style="color:#666">(</span>CasAuthenticationToken<span style="color:#666">)</span> securityContextAuthentication<span style="color:#666">)</span><span style="color:#666">;</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"assertion : {}"</span><span style="color:#666">,</span>
+ ToStringBuilder<span style="color:#666">.</span><span style="color:#b44">reflectionToString</span><span style="color:#666">(</span>casAuthenticationToken<span style="color:#666">.</span><span style="color:#b44">getAssertion</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ String iamSessionXml <span style="color:#666">=</span> <span style="color:#666">(</span>String<span style="color:#666">)</span> casAuthenticationToken<span style="color:#666">.</span><span style="color:#b44">getAssertion</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">getAttributes</span><span style="color:#666">(</span><span style="color:#666">)</span>
+ <span style="color:#666">.</span><span style="color:#b44">get</span><span style="color:#666">(</span>IAM_SESSION_ATTRIBUTE_KEY<span style="color:#666">)</span><span style="color:#666">;</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"iam session xml == {}"</span><span style="color:#666">,</span> iamSessionXml<span style="color:#666">)</span><span style="color:#666">;</span>
+ Session iamSession <span style="color:#666">=</span> sessionCache<span style="color:#666">.</span><span style="color:#b44">getIfPresent</span><span style="color:#666">(</span>casAuthenticationToken<span style="color:#666">.</span><span style="color:#b44">getKeyHash</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span> <span style="color:#666">(</span>iamSession <span style="color:#666">=</span><span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ Unmarshaller unmarshaller <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">try</span> <span style="color:#666">{</span>
+ unmarshaller <span style="color:#666">=</span> context<span style="color:#666">.</span><span style="color:#b44">createUnmarshaller</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>JAXBException ex<span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">warn</span><span style="color:#666">(</span><span style="color:#b44">"cannot create unmarshaller : "</span><span style="color:#666">,</span> ex<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ iamSession <span style="color:#666">=</span> <span style="color:#666">(</span>Session<span style="color:#666">)</span> unmarshaller<span style="color:#666">.</span><span style="color:#b44">unmarshal</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> StringReader<span style="color:#666">(</span>iamSessionXml<span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ sessionCache<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span>casAuthenticationToken<span style="color:#666">.</span><span style="color:#b44">getKeyHash</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">,</span> iamSession<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ StringBuilder sessionPermissionKeyBuilder <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> StringBuilder<span style="color:#666">(</span>iamSession<span style="color:#666">.</span><span style="color:#b44">getSessionId</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">append</span><span style="color:#666">(</span>filterUrl<spa [...]
+ Boolean isAllowed <span style="color:#666">=</span> accessCache<span style="color:#666">.</span><span style="color:#b44">getIfPresent</span><span style="color:#666">(</span>sessionPermissionKeyBuilder<span style="color:#666">.</span><span style="color:#b44">toString</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span><span style="color:#666">(</span>isAllowed <span style="color:#666">=</span><span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ isAllowed <span style="color:#666">=</span> accessManager<span style="color:#666">.</span><span style="color:#b44">checkAccess</span><span style="color:#666">(</span>iamSession<span style="color:#666">,</span> <span style="color:#a2f;font-weight:bold">new</span> Permission<span style="color:#666">(</span>filterUrl<span style="color:#666">,</span> requestMethod<span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ accessCache<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span>sessionPermissionKeyBuilder<span style="color:#666">.</span><span style="color:#b44">toString</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">,</span> isAllowed<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"{} is {} to access {} with method {}"</span><span style="color:#666">,</span>
+ <span style="color:#a2f;font-weight:bold">new</span> Object<span style="color:#666">[</span><span style="color:#666">]</span> <span style="color:#666">{</span>securityContextAuthentication<span style="color:#666">.</span><span style="color:#b44">getName</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">,</span>
+ isAllowed <span style="color:#666">?</span> <span style="color:#b44">"granted"</span> <span style="color:#666">:</span> <span style="color:#b44">"denied"</span><span style="color:#666">,</span> filterUrl<span style="color:#666">,</span> requestMethod<span style="color:#666">}</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span> <span style="color:#666">(</span>isAllowed<span style="color:#666">)</span> <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">return</span> <span style="color:#a2f;font-weight:bold">super</span><span style="color:#666">.</span><span style="color:#b44">ACCESS_GRANTED</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>Exception e<span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">error</span><span style="color:#666">(</span><span style="color:#b44">"catch exception when communicate with iam server"</span><span style="color:#666">,</span> e<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span>
+ <span style="color:#a2f;font-weight:bold">return</span> <span style="color:#a2f;font-weight:bold">super</span><span style="color:#666">.</span><span style="color:#b44">ACCESS_DENIED</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span>
+</code></pre></div><p>Yep, I’m calling fortress to check if the user is allowed to access fortress permissions or not.</p>
<h5 id="2-userdetail-populator">2. UserDetail Populator</h5>
<p>Spring uses the implementation of <em>AbstractCasAssertionUserDetailsService</em> to populate user details following successful authentication, you can see the example at <em>IamUserDetails</em> code, here is the snipet of that class:</p>
-<pre><code>:::Java
-@Override
- protected UserDetails loadUserDetails(final Assertion assertion) {
- List<GrantedAuthority> grantedAuthorities = new ArrayList<>();
- LOG.debug("user asssertion : {}", ToStringBuilder.reflectionToString(assertion));
- boolean accountNonExpired = true;
- boolean credentialsNonExpired = true;
- boolean accountNonLocked = true;
- boolean enabled = true;
- for (String attribute : this.attributes) {
- String value = (String) assertion.getPrincipal().getAttributes().get(attribute);
- LOG.debug("value = {}", value);
- if (value != null) {
- LOG.debug("adding default authorization to user");
- grantedAuthorities.add(new SimpleGrantedAuthority(ROLE_USER));
-
- Unmarshaller unmarshaller = null;
- Session iamSession = null;
- try {
- unmarshaller = context.createUnmarshaller();
- iamSession = (Session) unmarshaller.unmarshal(new StringReader(value));
- for (UserRole role : iamSession.getRoles()) {
- LOG.debug("adding {} authorization to user", role.getName().toUpperCase());
- grantedAuthorities.add(new SimpleGrantedAuthority(role.getName().toUpperCase()));
- }
- } catch (Exception ex) {
- LOG.error("cannot generate user details", ex);
- }
- }
- }
- LOG.debug(
- "accountNonExpired : {}, credentialsNonExpired : {}, accountNonLocked : {}, enabled : {}",
- new Object[] {accountNonExpired, credentialsNonExpired, accountNonLocked, enabled});
- return new User(assertion.getPrincipal().getName().toLowerCase().trim(), NON_EXISTENT_PASSWORD_VALUE, enabled,
- accountNonExpired, credentialsNonExpired, accountNonLocked, grantedAuthorities);
- }
-</code></pre>
-<p>You can change the implementation later for your needs.</p>
+<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-Java" data-lang="Java"> <span style="color:#a2f">@Override</span>
+ <span style="color:#a2f;font-weight:bold">protected</span> UserDetails <span style="color:#00a000">loadUserDetails</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">final</span> Assertion assertion<span style="color:#666">)</span> <span style="color:#666">{</span>
+ List<span style="color:#666"><</span>GrantedAuthority<span style="color:#666">></span> grantedAuthorities <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> ArrayList<span style="color:#666"><</span><span style="color:#666">></span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"user asssertion : {}"</span><span style="color:#666">,</span> ToStringBuilder<span style="color:#666">.</span><span style="color:#b44">reflectionToString</span><span style="color:#666">(</span>assertion<span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#0b0;font-weight:bold">boolean</span> accountNonExpired <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">true</span><span style="color:#666">;</span>
+ <span style="color:#0b0;font-weight:bold">boolean</span> credentialsNonExpired <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">true</span><span style="color:#666">;</span>
+ <span style="color:#0b0;font-weight:bold">boolean</span> accountNonLocked <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">true</span><span style="color:#666">;</span>
+ <span style="color:#0b0;font-weight:bold">boolean</span> enabled <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">true</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">for</span> <span style="color:#666">(</span>String attribute <span style="color:#666">:</span> <span style="color:#a2f;font-weight:bold">this</span><span style="color:#666">.</span><span style="color:#b44">attributes</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ String value <span style="color:#666">=</span> <span style="color:#666">(</span>String<span style="color:#666">)</span> assertion<span style="color:#666">.</span><span style="color:#b44">getPrincipal</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">getAttributes</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">get</spa [...]
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"value = {}"</span><span style="color:#666">,</span> value<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">if</span> <span style="color:#666">(</span>value <span style="color:#666">!</span><span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"adding default authorization to user"</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ grantedAuthorities<span style="color:#666">.</span><span style="color:#b44">add</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> SimpleGrantedAuthority<span style="color:#666">(</span>ROLE_USER<span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+
+ Unmarshaller unmarshaller <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">;</span>
+ Session iamSession <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">null</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">try</span> <span style="color:#666">{</span>
+ unmarshaller <span style="color:#666">=</span> context<span style="color:#666">.</span><span style="color:#b44">createUnmarshaller</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ iamSession <span style="color:#666">=</span> <span style="color:#666">(</span>Session<span style="color:#666">)</span> unmarshaller<span style="color:#666">.</span><span style="color:#b44">unmarshal</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> StringReader<span style="color:#666">(</span>value<span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">for</span> <span style="color:#666">(</span>UserRole role <span style="color:#666">:</span> iamSession<span style="color:#666">.</span><span style="color:#b44">getRoles</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span><span style="color:#b44">"adding {} authorization to user"</span><span style="color:#666">,</span> role<span style="color:#666">.</span><span style="color:#b44">getName</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">toUpperCase</span><span style="color:#666">(</span><span style= [...]
+ grantedAuthorities<span style="color:#666">.</span><span style="color:#b44">add</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> SimpleGrantedAuthority<span style="color:#666">(</span>role<span style="color:#666">.</span><span style="color:#b44">getName</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">toUpperCase</span><span style="color:#666">(</spa [...]
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>Exception ex<span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">error</span><span style="color:#666">(</span><span style="color:#b44">"cannot generate user details"</span><span style="color:#666">,</span> ex<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span>
+ <span style="color:#666">}</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">debug</span><span style="color:#666">(</span>
+ <span style="color:#b44">"accountNonExpired : {}, credentialsNonExpired : {}, accountNonLocked : {}, enabled : {}"</span><span style="color:#666">,</span>
+ <span style="color:#a2f;font-weight:bold">new</span> Object<span style="color:#666">[</span><span style="color:#666">]</span> <span style="color:#666">{</span>accountNonExpired<span style="color:#666">,</span> credentialsNonExpired<span style="color:#666">,</span> accountNonLocked<span style="color:#666">,</span> enabled<span style="color:#666">}</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">return</span> <span style="color:#a2f;font-weight:bold">new</span> User<span style="color:#666">(</span>assertion<span style="color:#666">.</span><span style="color:#b44">getPrincipal</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="color:#b44">getName</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">.</span><span style="co [...]
+ accountNonExpired<span style="color:#666">,</span> credentialsNonExpired<span style="color:#666">,</span> accountNonLocked<span style="color:#666">,</span> grantedAuthorities<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+</code></pre></div><p>You can change the implementation later for your needs.</p>
<h5 id="3-network-might-be-a-problem">3. Network Might Be a Problem</h5>
<p>Since this is running inside a production environment, we needed to consider that sometimes there might be a trouble over our network that causes problems and requires retries. That is why it’s important to allow a little delay time in our application. Here’s an example of how allow a small delay, in order to allow temporary network glitches and slowdowns to work themselves out.</p>
-<pre><code>:::Java
-/*
- * Copyright 2017 to PT. Global Digital Niaga(Blibli.com)
- *
- * Licensed under the Apache License, Version 2.0; you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the License
- * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
- * or implied. See the License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.gdn.iam.spring.security;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.security.cas.authentication.CasAuthenticationProvider;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.AuthenticationException;
-
-public class GdnCasAuthenticationProvider extends CasAuthenticationProvider {
-
- private static transient Logger LOG = LoggerFactory.getLogger(GdnCasAuthenticationProvider.class);
- private long sleepForDistributeTicketTime = 300;
-
- @Override
- public Authentication authenticate(Authentication authentication) throws AuthenticationException {
- try {
- LOG.trace(
- "will try to sleep for waiting ticket to be distributed to other node, sleep time : {}",
- getSleepForDistributeTicketTime());
- Thread.sleep(getSleepForDistributeTicketTime());
- } catch (InterruptedException e) {
- LOG.error("something wrong when sleeping", e);
- }
- return super.authenticate(authentication);
- }
-
- public long getSleepForDistributeTicketTime() {
- return sleepForDistributeTicketTime;
- }
-
- public void setSleepForDistributeTicketTime(long sleepForDistributeTicketTime) {
- this.sleepForDistributeTicketTime = sleepForDistributeTicketTime;
- }
-
-}
-</code></pre>
-<h3 id="descriptions-of-authentication-flow">Descriptions of authentication flow</h3>
+<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-Java" data-lang="Java"> <span style="color:#080;font-style:italic">/*
+</span><span style="color:#080;font-style:italic"> * Copyright 2017 to PT. Global Digital Niaga(Blibli.com)
+</span><span style="color:#080;font-style:italic"> *
+</span><span style="color:#080;font-style:italic"> * Licensed under the Apache License, Version 2.0; you may not use this file except in compliance
+</span><span style="color:#080;font-style:italic"> * with the License. You may obtain a copy of the License at
+</span><span style="color:#080;font-style:italic"> *
+</span><span style="color:#080;font-style:italic"> * http://www.apache.org/licenses/LICENSE-2.0
+</span><span style="color:#080;font-style:italic"> *
+</span><span style="color:#080;font-style:italic"> * Unless required by applicable law or agreed to in writing, software distributed under the License
+</span><span style="color:#080;font-style:italic"> * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+</span><span style="color:#080;font-style:italic"> * or implied. See the License for the specific language governing permissions and limitations under
+</span><span style="color:#080;font-style:italic"> * the License.
+</span><span style="color:#080;font-style:italic"> */</span>
+ <span style="color:#a2f;font-weight:bold">package</span> <span style="color:#00f;font-weight:bold">com.gdn.iam.spring.security</span><span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.slf4j.Logger</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.slf4j.LoggerFactory</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.springframework.security.cas.authentication.CasAuthenticationProvider</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.springframework.security.core.Authentication</span><span style="color:#666">;</span>
+ <span style="color:#a2f;font-weight:bold">import</span> <span style="color:#00f;font-weight:bold">org.springframework.security.core.AuthenticationException</span><span style="color:#666">;</span>
+
+ <span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">class</span> <span style="color:#00f">GdnCasAuthenticationProvider</span> <span style="color:#a2f;font-weight:bold">extends</span> CasAuthenticationProvider <span style="color:#666">{</span>
+
+ <span style="color:#a2f;font-weight:bold">private</span> <span style="color:#a2f;font-weight:bold">static</span> <span style="color:#a2f;font-weight:bold">transient</span> Logger LOG <span style="color:#666">=</span> LoggerFactory<span style="color:#666">.</span><span style="color:#b44">getLogger</span><span style="color:#666">(</span>GdnCasAuthenticationProvider<span style="color:#666">.</span><span style="color:#b44">class</span><span style="color:#666">)</span><span style="color [...]
+ <span style="color:#a2f;font-weight:bold">private</span> <span style="color:#0b0;font-weight:bold">long</span> sleepForDistributeTicketTime <span style="color:#666">=</span> 300<span style="color:#666">;</span>
+
+ <span style="color:#a2f">@Override</span>
+ <span style="color:#a2f;font-weight:bold">public</span> Authentication <span style="color:#00a000">authenticate</span><span style="color:#666">(</span>Authentication authentication<span style="color:#666">)</span> <span style="color:#a2f;font-weight:bold">throws</span> AuthenticationException <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">try</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">trace</span><span style="color:#666">(</span>
+ <span style="color:#b44">"will try to sleep for waiting ticket to be distributed to other node, sleep time : {}"</span><span style="color:#666">,</span>
+ getSleepForDistributeTicketTime<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ Thread<span style="color:#666">.</span><span style="color:#b44">sleep</span><span style="color:#666">(</span>getSleepForDistributeTicketTime<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>InterruptedException e<span style="color:#666">)</span> <span style="color:#666">{</span>
+ LOG<span style="color:#666">.</span><span style="color:#b44">error</span><span style="color:#666">(</span><span style="color:#b44">"something wrong when sleeping"</span><span style="color:#666">,</span> e<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+ <span style="color:#a2f;font-weight:bold">return</span> <span style="color:#a2f;font-weight:bold">super</span><span style="color:#666">.</span><span style="color:#b44">authenticate</span><span style="color:#666">(</span>authentication<span style="color:#666">)</span><span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+
+ <span style="color:#a2f;font-weight:bold">public</span> <span style="color:#0b0;font-weight:bold">long</span> <span style="color:#00a000">getSleepForDistributeTicketTime</span><span style="color:#666">(</span><span style="color:#666">)</span> <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">return</span> sleepForDistributeTicketTime<span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+
+ <span style="color:#a2f;font-weight:bold">public</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">setSleepForDistributeTicketTime</span><span style="color:#666">(</span><span style="color:#0b0;font-weight:bold">long</span> sleepForDistributeTicketTime<span style="color:#666">)</span> <span style="color:#666">{</span>
+ <span style="color:#a2f;font-weight:bold">this</span><span style="color:#666">.</span><span style="color:#b44">sleepForDistributeTicketTime</span> <span style="color:#666">=</span> sleepForDistributeTicketTime<span style="color:#666">;</span>
+ <span style="color:#666">}</span>
+
+ <span style="color:#666">}</span>
+</code></pre></div><h3 id="descriptions-of-authentication-flow">Descriptions of authentication flow</h3>
<p>The <strong>CAS</strong> authentication flow will be the same, no changes are required in terms of that authentication flow. Furthermore, you can see that flow at <a href="https://www.apereo.org/projects/cas">Apereo CAS</a> 4.2.x documentation page.</p>
<p>The main difference now is we don’t put the ticket registry inside an in-memory database, we put it inside an <a href="https://ignite.apache.org/">Apache Ignite</a> cache, so when other nodes are there it can replicate the ticket between them which increases efficiencies.</p>
<h3 id="descriptions-of-authorization-flow">Descriptions of authorization flow</h3>
@@ -466,10 +456,8 @@ public class GdnCasAuthenticationProvider extends CasAuthenticationProvider {
</ul>
<p>and configure your <strong>Apache Fortress</strong> properly.</p>
<h5 id="2-clone-the-project-from-link-at-where-to-download-section-below-change-the-configuration-properly-inside-cas-fortress-serverssrcmainresources-folder-and-package-it-using">2. Clone the project from link at <em>Where to download</em> section below, change the configuration properly inside <em>cas-fortress-servers/src/main/resources</em> folder and package it using:</h5>
-<pre><code>:::Maven
-mvn clean package.
-</code></pre>
-<p>Copy the war file from <em>cas-fortress-server/target</em> into the <em>web-container</em> deploy directory.</p>
+<pre><code class="language-Maven" data-lang="Maven"> mvn clean package.
+</code></pre><p>Copy the war file from <em>cas-fortress-server/target</em> into the <em>web-container</em> deploy directory.</p>
<h5 id="3-start-your-web-container-and-you-get-cas-fortress-integrated">3. Start your web-container and you get CAS fortress integrated.</h5>
<h4 id="client-section">Client Section</h4>
<ul>
diff --git a/content/sitemap.xml b/content/sitemap.xml
index 8ca14e9..1942f7e 100644
--- a/content/sitemap.xml
+++ b/content/sitemap.xml
@@ -1784,7 +1784,7 @@
<url>
<loc>https://directory.apache.org/fortress.html</loc>
- <lastmod>2021-05-17T09:09:26+02:00</lastmod>
+ <lastmod>2021-05-18T23:33:49+02:00</lastmod>
</url>
<url>
@@ -2244,7 +2244,7 @@
<url>
<loc>https://directory.apache.org/fortress/testimonials.html</loc>
- <lastmod>2021-05-17T09:09:26+02:00</lastmod>
+ <lastmod>2021-05-18T23:33:49+02:00</lastmod>
</url>
<url>