Skip to content
Snippets Groups Projects
Commit bb2fc7e0 authored by ribeaudc's avatar ribeaudc
Browse files

change:

- IAuthenticationService refactored: it extends ISelfTestable and functionality previously implemented only by 'authenticate' has been splitted.

SVN: 660
parent 914a4b13
No related branches found
No related tags found
No related merge requests found
...@@ -28,15 +28,26 @@ public final class DummyAuthenticationService implements IAuthenticationService ...@@ -28,15 +28,26 @@ public final class DummyAuthenticationService implements IAuthenticationService
// IAuthenticationService // IAuthenticationService
// //
public String authenticateApplication()
{
// We do not care about the returned application token.
return null;
}
/** /**
* Returns always a non-<code>null</code> token, meaning that the login was successfull. * Always returns <code>true</code>, meaning that the login was successfull.
*/ */
public final Principal authenticate(String user, String password) public final boolean authenticateUser(String applicationToken, String user, String password)
{ {
return new Principal(user, "John", "Doe", "jdoe@somewhere.org"); return true;
} }
public final void checkAvailability() public final Principal getPrincipal(String applicationToken, String user)
{
return new Principal(user, "John", "Doe", "jdoe@somewhere.org");
}
public final void check()
{ {
// Always available. // Always available.
} }
......
...@@ -16,27 +16,50 @@ ...@@ -16,27 +16,50 @@
package ch.systemsx.cisd.authentication; package ch.systemsx.cisd.authentication;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.utilities.ISelfTestable;
/** /**
* Interface for authentication. * Interface for authentication.
* *
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
public interface IAuthenticationService public interface IAuthenticationService extends ISelfTestable
{ {
/** /**
* Checks whether the service is available or not. * Attempts authentication of the application with credentials passed in the constructor and retuns the application
* token.
* <p>
* The returned application token can then be used to authenticate an user (via
* {@link #authenticateUser(String, String, String)}) or to retrieve additional details about an user (via
* {@link #getPrincipal(String, String)})
* </p>
* *
* @throws EnvironmentFailureException if the service is not available. * @return the application token if the application has been successfully authenticated, <code>null</code>
* otherwise.
*/ */
public void checkAvailability(); public String authenticateApplication();
/** /**
* Attempts authentication for the given user credentials. * Attempts authentication for the given user credentials.
* <p>
* Note that the application must be authenticated (meaning that <var>applicationToken</var> is not
* <code>null</code>) to perform this lookup.
* </p>
*
* @return <code>true</code> if the <var>user</var> has been successfully authenticated.
*/
public boolean authenticateUser(String applicationToken, String user, String password);
/**
* For a given user name returns additional details encapsulated in returned <code>Principal</code>.
* <p>
* Note that the application must be authenticated (meaning that <var>applicationToken</var> is not
* <code>null</code>) to perform this lookup.
* </p>
* *
* @return a <code>Principal</code> object if the <var>user</var> has been successfully authenticated, * @return a <code>Principal</code> object if given <var>user</var> could be found, <code>null</code>
* <code>null</code> otherwise. * otherwise.
*/ */
public Principal authenticate(String user, String password); public Principal getPrincipal(String applicationToken, String user);
} }
\ No newline at end of file
...@@ -37,6 +37,7 @@ import ch.systemsx.cisd.authentication.IAuthenticationService; ...@@ -37,6 +37,7 @@ import ch.systemsx.cisd.authentication.IAuthenticationService;
import ch.systemsx.cisd.authentication.Principal; import ch.systemsx.cisd.authentication.Principal;
import ch.systemsx.cisd.authentication.crowd.CrowdSoapElements.SOAPAttribute; import ch.systemsx.cisd.authentication.crowd.CrowdSoapElements.SOAPAttribute;
import ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel; import ch.systemsx.cisd.common.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException;
import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException;
import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogCategory;
import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.logging.LogFactory;
...@@ -44,6 +45,10 @@ import ch.systemsx.cisd.common.logging.LogFactory; ...@@ -44,6 +45,10 @@ import ch.systemsx.cisd.common.logging.LogFactory;
/** /**
* This <code>IAuthenticationService</code> implementation first registers the application on the <i>Crowd</i> * This <code>IAuthenticationService</code> implementation first registers the application on the <i>Crowd</i>
* server, then authenticates the user. * server, then authenticates the user.
* <p>
* The modus operandi is based on information found at <a
* href="http://confluence.atlassian.com/display/CROWD/SOAP+API">http://confluence.atlassian.com/display/CROWD/SOAP+API</a>
* </p>
* *
* @author Franz-Josef Elmer * @author Franz-Josef Elmer
*/ */
...@@ -126,7 +131,11 @@ public class CrowdAuthenticationService implements IAuthenticationService ...@@ -126,7 +131,11 @@ public class CrowdAuthenticationService implements IAuthenticationService
} }
} }
public final void checkAvailability() //
// IAuthenticationService
//
public final void check() throws EnvironmentFailureException, ConfigurationFailureException
{ {
try try
{ {
...@@ -148,17 +157,14 @@ public class CrowdAuthenticationService implements IAuthenticationService ...@@ -148,17 +157,14 @@ public class CrowdAuthenticationService implements IAuthenticationService
} }
} }
public final Principal authenticate(String user, String password) public final String authenticateApplication()
{ {
assert user != null;
// Application login
final String applicationToken = final String applicationToken =
StringEscapeUtils.unescapeXml(execute(CrowdSoapElements.TOKEN, AUTHENTICATE_APPL, application, StringEscapeUtils.unescapeXml(execute(CrowdSoapElements.TOKEN, AUTHENTICATE_APPL, application,
applicationPassword)); applicationPassword));
if (applicationToken == null) if (applicationToken == null)
{ {
operationLog.error("CROWD: application '" + application + "' failed to authenticate."); operationLog.error("CROWD: application '" + application + "' failed to authenticate.");
return null;
} else } else
{ {
if (operationLog.isDebugEnabled()) if (operationLog.isDebugEnabled())
...@@ -166,6 +172,14 @@ public class CrowdAuthenticationService implements IAuthenticationService ...@@ -166,6 +172,14 @@ public class CrowdAuthenticationService implements IAuthenticationService
operationLog.debug("CROWD: application '" + application + "' successfully authenticated."); operationLog.debug("CROWD: application '" + application + "' successfully authenticated.");
} }
} }
return applicationToken;
}
public final boolean authenticateUser(String applicationToken, String user, String password)
{
assert applicationToken != null;
assert user != null;
final String userToken = final String userToken =
StringEscapeUtils.unescapeXml(execute("out", AUTHENTICATE_USER, application, applicationToken, user, StringEscapeUtils.unescapeXml(execute("out", AUTHENTICATE_USER, application, applicationToken, user,
password)); password));
...@@ -180,12 +194,11 @@ public class CrowdAuthenticationService implements IAuthenticationService ...@@ -180,12 +194,11 @@ public class CrowdAuthenticationService implements IAuthenticationService
operationLog.info(msg + "SUCCESS."); operationLog.info(msg + "SUCCESS.");
} }
} }
if (userToken == null) return userToken != null;
{ }
return null;
} public final Principal getPrincipal(String applicationToken, String user)
// Find principal by name. Obviously we do not need to make an user authentication to get {
// these informations.
String xmlResponse = null; String xmlResponse = null;
try try
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment