parent
8a32fd2061
commit
42cc968a2e
|
|
@ -6,6 +6,7 @@
|
|||
package org.jasig.cas.client.integration.atlassian;
|
||||
|
||||
import com.atlassian.confluence.user.ConfluenceAuthenticator;
|
||||
import com.atlassian.seraph.auth.AuthenticatorException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jasig.cas.client.util.AbstractCasFilter;
|
||||
|
|
@ -21,35 +22,54 @@ import java.security.Principal;
|
|||
* via CAS.
|
||||
*
|
||||
* @author Scott Battaglia
|
||||
* @author John Watson
|
||||
* @version $Revision$ $Date$
|
||||
* @since 3.1.2
|
||||
*/
|
||||
public final class ConfluenceCasAuthenticator extends ConfluenceAuthenticator {
|
||||
|
||||
private static final Log log = LogFactory.getLog(ConfluenceCasAuthenticator.class);
|
||||
private static final Log LOG = LogFactory.getLog(ConfluenceCasAuthenticator.class);
|
||||
|
||||
public Principal getUser(final HttpServletRequest request, final HttpServletResponse response) {
|
||||
final HttpSession session = request.getSession();
|
||||
|
||||
if (session != null) {
|
||||
// user already exists
|
||||
if (session.getAttribute(ConfluenceCasAuthenticator.LOGGED_IN_KEY) != null) {
|
||||
log.info("Session found; user already logged in.");
|
||||
return (Principal) session.getAttribute(LOGGED_IN_KEY);
|
||||
if (session.getAttribute(LOGGED_IN_KEY) != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Session found; user already logged in.");
|
||||
}
|
||||
return (Principal) session.getAttribute(LOGGED_IN_KEY);
|
||||
}
|
||||
|
||||
final Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
|
||||
|
||||
if (assertion != null) {
|
||||
final Principal p = getUser(assertion.getPrincipal().getName());
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Logging in [" + p.getName() + "] from CAS.");
|
||||
}
|
||||
|
||||
final Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
|
||||
|
||||
if (assertion != null) {
|
||||
if (assertion != null) {
|
||||
final Principal p = getUser(assertion.getPrincipal().getName());
|
||||
request.getSession().setAttribute(LOGGED_IN_KEY, p);
|
||||
request.getSession().setAttribute(LOGGED_OUT_KEY, null);
|
||||
return p;
|
||||
}
|
||||
}
|
||||
session.setAttribute(LOGGED_IN_KEY, p);
|
||||
session.setAttribute(LOGGED_OUT_KEY, null);
|
||||
return p;
|
||||
}
|
||||
|
||||
return super.getUser(request, response);
|
||||
}
|
||||
|
||||
public boolean logout(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticatorException {
|
||||
final HttpSession session = request.getSession();
|
||||
|
||||
final Principal principal = (Principal) session.getAttribute(LOGGED_IN_KEY);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Logging out [" + principal.getName() + "] from CAS.");
|
||||
}
|
||||
|
||||
session.setAttribute(LOGGED_OUT_KEY, principal);
|
||||
session.setAttribute(LOGGED_IN_KEY, null);
|
||||
session.setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
package org.jasig.cas.client.integration.atlassian;
|
||||
|
||||
import com.atlassian.seraph.auth.DefaultAuthenticator;
|
||||
import com.atlassian.seraph.auth.AuthenticatorException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.jasig.cas.client.util.AbstractCasFilter;
|
||||
|
|
@ -21,33 +22,53 @@ import java.security.Principal;
|
|||
* via CAS.
|
||||
*
|
||||
* @author Scott Battaglia
|
||||
* @author John Watson
|
||||
* @version $Revision$ $Date$
|
||||
* @since 3.1.3
|
||||
*/
|
||||
public final class JiraCasAuthenticator extends DefaultAuthenticator {
|
||||
|
||||
private static final Log log = LogFactory.getLog(JiraCasAuthenticator.class);
|
||||
private static final Log LOG = LogFactory.getLog(JiraCasAuthenticator.class);
|
||||
|
||||
public Principal getUser(final HttpServletRequest request, final HttpServletResponse response) {
|
||||
final HttpSession session = request.getSession();
|
||||
|
||||
if (session != null) {
|
||||
// user already exists
|
||||
if (session.getAttribute(ConfluenceCasAuthenticator.LOGGED_IN_KEY) != null) {
|
||||
log.info("Session found; user already logged in.");
|
||||
return (Principal) session.getAttribute(LOGGED_IN_KEY);
|
||||
if (session.getAttribute(LOGGED_IN_KEY) != null) {
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Session found; user already logged in.");
|
||||
}
|
||||
return (Principal) session.getAttribute(LOGGED_IN_KEY);
|
||||
}
|
||||
|
||||
final Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
|
||||
|
||||
if (assertion != null) {
|
||||
final Principal p = getUser(assertion.getPrincipal().getName());
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Logging in [" + p.getName() + "] from CAS.");
|
||||
}
|
||||
|
||||
final Assertion assertion = (Assertion) session.getAttribute(AbstractCasFilter.CONST_CAS_ASSERTION);
|
||||
|
||||
if (assertion != null) {
|
||||
final Principal p = getUser(assertion.getPrincipal().getName());
|
||||
request.getSession().setAttribute(LOGGED_IN_KEY, p);
|
||||
request.getSession().setAttribute(LOGGED_OUT_KEY, null);
|
||||
return p;
|
||||
}
|
||||
session.setAttribute(LOGGED_IN_KEY, p);
|
||||
session.setAttribute(LOGGED_OUT_KEY, null);
|
||||
return p;
|
||||
}
|
||||
|
||||
return super.getUser(request, response);
|
||||
}
|
||||
|
||||
public boolean logout(final HttpServletRequest request, final HttpServletResponse response) throws AuthenticatorException {
|
||||
final HttpSession session = request.getSession();
|
||||
final Principal p = (Principal) session.getAttribute(LOGGED_IN_KEY);
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
LOG.debug("Logging out [" + p.getName() + "] from CAS.");
|
||||
}
|
||||
|
||||
session.setAttribute(LOGGED_OUT_KEY, p);
|
||||
session.setAttribute(LOGGED_IN_KEY, null);
|
||||
session.setAttribute(AbstractCasFilter.CONST_CAS_ASSERTION, null);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue