Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Puschhof committed Feb 18, 2016
1 parent bab94a6 commit c74aa10
Show file tree
Hide file tree
Showing 4 changed files with 236 additions and 0 deletions.
File renamed without changes.
57 changes: 57 additions & 0 deletions eu/midan/JIRAAuthenticatorWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/********************************************//**
* \file JIRAAuthenticatorWrapper.java
* \brief \c JIAAuthenticatorWrapper.java provides a wrapper for
* the JIRA Seraph authenticator.
*
* \author Sebastian Puschhof, MIDAN SOFTWARE GmbH
* \version 1.0 JIRAAuthenticatorWrapper.java, v1.0 2015/09/30 13:35 SPF
*
* \note Copyright © 2015 MIDAN SOFTWARE GmbH
*
* This file is part of MIDANAuthenticator.
*
* MIDANAuthenticator is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* MIDANAuthenticator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MIDANAuthenticator. If not, see <http://www.gnu.org/licenses/>.
*
* See COPYING file for the full LGPL text.
***********************************************/

package eu.midan;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;

import com.atlassian.jira.security.login.JiraSeraphAuthenticator;
import com.atlassian.seraph.auth.AuthenticatorException;

public class JIRAAuthenticatorWrapper extends JiraSeraphAuthenticator {

private static final long serialVersionUID = 1L;

public boolean pubAuthenticate(Principal paramPrincipal, String paramString) {
try {
return super.authenticate(paramPrincipal, paramString);
} catch (AuthenticatorException e) {
return false;
}
}

public Principal pubGetUser(String paramString) {
return super.getUser(paramString);
}

public Principal pubRefreshPrincipalObtainedFromSession(HttpServletRequest httpServletRequest, Principal principal) {
return super.refreshPrincipalObtainedFromSession(httpServletRequest, principal);
}
}
127 changes: 127 additions & 0 deletions eu/midan/MIDANAuthenticator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/********************************************//**
* \file MIDANAuthenticator.java
* \brief \c MIDANAuthenticator.java combines Crowd SSO and
* JIRA local database authorization.
*
* \author Sebastian Puschhof, MIDAN SOFTWARE GmbH
* \version 1.0 MIDANAuthenticator.java, v1.0 2015/09/30 14:34 SPF
*
* \note Copyright &copy; 2015 MIDAN SOFTWARE GmbH
*
* This file is part of MIDANAuthenticator.
*
* MIDANAuthenticator is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* MIDANAuthenticator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MIDANAuthenticator. If not, see <http://www.gnu.org/licenses/>.
*
* See COPYING file for the full LGPL text.
***********************************************/

package eu.midan;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.security.Principal;

import com.atlassian.seraph.config.SecurityConfig;
import com.atlassian.seraph.auth.DefaultAuthenticator;

import eu.midan.SSOAuthenticatorWrapper;
import eu.midan.JIRAAuthenticatorWrapper;

public class MIDANAuthenticator extends DefaultAuthenticator {

private static final long serialVersionUID = 1L;

private SSOAuthenticatorWrapper sso;
private JIRAAuthenticatorWrapper jira;

public MIDANAuthenticator() {
sso = new SSOAuthenticatorWrapper();
jira = new JIRAAuthenticatorWrapper();
}

public void init(Map<String, String> params, SecurityConfig config) {
sso.init(params, config);
jira.init(params, config);
super.init(params, config);
}

public boolean login(HttpServletRequest request, HttpServletResponse response, String username, String password, boolean cookie) {
boolean result = false;

try {
result = sso.login(request, response, username, password, cookie);
if(result == false) {
result = jira.login(request, response, username, password, cookie);
}
} catch(Exception e) {
result = false;
}

return result;
}

public boolean logout(HttpServletRequest request, HttpServletResponse response) {
boolean result = false;

try {
result = sso.logout(request, response);
if(result == false) {
result = jira.logout(request, response);
}
} catch (Exception e) {
result = false;
}

return result;
}

protected Principal refreshPrincipalObtainedFromSession(HttpServletRequest httpServletRequest, Principal principal) {
Principal user = sso.pubRefreshPrincipalObtainedFromSession(httpServletRequest, principal);

if(user == null) {
user = jira.pubRefreshPrincipalObtainedFromSession(httpServletRequest, principal);
}

return user;
}

protected boolean authenticate(Principal user, String password) {
if(sso.pubAuthenticate(user, password)) {
return true;
} else if(jira.pubAuthenticate(user, password)) {
return true;
}

return false;
}

public Principal getUser(HttpServletRequest request, HttpServletResponse response) {
Principal user = jira.getUser(request, response);
if(user == null) {
user = sso.getUser(request, response);
}
return user;
}

protected Principal getUser(String username) {
Principal user = sso.pubGetUser(username);
if(user == null) {
user = jira.pubGetUser(username);
}
return user;
}
}
52 changes: 52 additions & 0 deletions eu/midan/SSOAuthenticatorWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/********************************************//**
* \file SSOAuthenticatorWrapper.java
* \brief \c SSOAuthenticatorWrapper.java provides a wrapper for
* the Crowd SSO authenticator.
*
* \author Sebastian Puschhof, MIDAN SOFTWARE GmbH
* \version 1.0 SSOAuthenticatorWrapper.java, v1.0 2015/09/30 13:49 SPF
*
* \note Copyright &copy; 2015 MIDAN SOFTWARE GmbH
*
* This file is part of MIDANAuthenticator.
*
* MIDANAuthenticator is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* MIDANAuthenticator is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with MIDANAuthenticator. If not, see <http://www.gnu.org/licenses/>.
*
* See COPYING file for the full LGPL text.
***********************************************/

package eu.midan;

import java.security.Principal;

import javax.servlet.http.HttpServletRequest;

import com.atlassian.jira.security.login.SSOSeraphAuthenticator;

public class SSOAuthenticatorWrapper extends SSOSeraphAuthenticator {

private static final long serialVersionUID = 1L;

public boolean pubAuthenticate(Principal paramPrincipal, String paramString) {
return super.authenticate(paramPrincipal, paramString);
}

public Principal pubGetUser(String paramString) {
return super.getUser(paramString);
}

public Principal pubRefreshPrincipalObtainedFromSession(HttpServletRequest httpServletRequest, Principal principal) {
return super.refreshPrincipalObtainedFromSession(httpServletRequest, principal);
}
}

0 comments on commit c74aa10

Please sign in to comment.