-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Sebastian Puschhof
committed
Feb 18, 2016
1 parent
bab94a6
commit c74aa10
Showing
4 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 © 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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 © 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); | ||
} | ||
} |