Merged V2.1 to HEAD

6386: Fix for AR-1649
   6387: Fix for AR-1645
   6388: Updated Polish messages
   6389: Updated security providers
   6392: Add support to log in as guest with any password (if guest is allowed)
   6393: AR-1562 : Cannot directly exit/disable Alfresco JavaScript Debugger window
   6394: Allow creation of PropertyValue persisted properties without knowing the type QName
   6397: Log Serializable properties don't cause infinte waits
   6398: Build fix and tidy up for authentication chaining
            Resolved conflicted state of 'root\projects\repository\source\java\org\alfresco\repo\security\authentication\AuthenticationUtil.java'
   6402: AR-1643 Web Script args object does not handle multi-value arguments
   6407: Removed use of QName "{}silly" as a data type definition.


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@6728 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley 2007-09-10 15:41:43 +00:00
parent 1050a3cb98
commit a3ddf17f8e
16 changed files with 253 additions and 153 deletions

View File

@ -2310,9 +2310,9 @@ public class ServerConfiguration extends AbstractLifecycleBean
} }
else else
{ {
// Use the default Cryptix JCE provider // Use the default Bouncy Castle
setJCEProvider("cryptix.jce.provider.CryptixCrypto"); setJCEProvider("org.bouncycastle.jce.provider.BouncyCastleProvider");
} }
// Check if any domain mappings have been specified // Check if any domain mappings have been specified

View File

@ -72,6 +72,7 @@ import org.alfresco.service.cmr.avm.deploy.DeploymentReport;
import org.alfresco.service.cmr.avm.deploy.DeploymentService; import org.alfresco.service.cmr.avm.deploy.DeploymentService;
import org.alfresco.service.cmr.avmsync.AVMDifference; import org.alfresco.service.cmr.avmsync.AVMDifference;
import org.alfresco.service.cmr.avmsync.AVMSyncException; import org.alfresco.service.cmr.avmsync.AVMSyncException;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.model.FileFolderService; import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.remote.RepoRemote; import org.alfresco.service.cmr.remote.RepoRemote;
import org.alfresco.service.cmr.repository.ContentData; import org.alfresco.service.cmr.repository.ContentData;
@ -111,10 +112,10 @@ public class AVMServiceTest extends AVMServiceTestBase
try try
{ {
fService.setStoreProperty("main", QName.createQName(null, ".dns.main"), fService.setStoreProperty("main", QName.createQName(null, ".dns.main"),
new PropertyValue(QName.createQName(null, "silly"), "Nothing.")); new PropertyValue(DataTypeDefinition.TEXT, "Nothing."));
fService.createStore("test"); fService.createStore("test");
fService.setStoreProperty("test", QName.createQName(null, ".dns.test.main"), fService.setStoreProperty("test", QName.createQName(null, ".dns.test.main"),
new PropertyValue(QName.createQName(null, "silly"), "Nothing.")); new PropertyValue(DataTypeDefinition.TEXT, "Nothing."));
setupBasicTree0(); setupBasicTree0();
authService.authenticateAsGuest(); authService.authenticateAsGuest();
// assertEquals(0, fLockingService.getUsersLocks("admin").size()); // assertEquals(0, fLockingService.getUsersLocks("admin").size());
@ -195,7 +196,7 @@ public class AVMServiceTest extends AVMServiceTestBase
results.close(); results.close();
QName name = QName.createQName("silly.uri", "SillyProperty"); QName name = QName.createQName("silly.uri", "SillyProperty");
PropertyValue value = new PropertyValue(name, "Silly Property Value"); PropertyValue value = new PropertyValue(DataTypeDefinition.TEXT, "Silly Property Value");
fService.setNodeProperty("main:/a/b/c/foo", name, value); fService.setNodeProperty("main:/a/b/c/foo", name, value);
fService.createSnapshot("main", null, null); fService.createSnapshot("main", null, null);
results = searchService.query(storeRef, "lucene", LuceneQueryParser.escape("@{silly.uri}SillyProperty")+":\"Silly\""); results = searchService.query(storeRef, "lucene", LuceneQueryParser.escape("@{silly.uri}SillyProperty")+":\"Silly\"");
@ -5162,7 +5163,7 @@ public class AVMServiceTest extends AVMServiceTestBase
try try
{ {
QName name = QName.createQName("silly.uri", "SillyProperty"); QName name = QName.createQName("silly.uri", "SillyProperty");
PropertyValue value = new PropertyValue(name, "Silly Property Value"); PropertyValue value = new PropertyValue(DataTypeDefinition.TEXT, "Silly Property Value");
fService.setStoreProperty("main", name, value); fService.setStoreProperty("main", name, value);
PropertyValue found = fService.getStoreProperty("main", name); PropertyValue found = fService.getStoreProperty("main", name);
assertEquals(value.toString(), found.toString()); assertEquals(value.toString(), found.toString());

View File

@ -24,10 +24,10 @@
*/ */
package org.alfresco.repo.domain; package org.alfresco.repo.domain;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -516,11 +516,15 @@ public class PropertyValue implements Cloneable, Serializable
} }
else else
{ {
// Convert the value to the type required. This ensures that any type conversion issues // Does the client consider the type to be important?
// are caught early and prevent the scenario where the data in the DB cannot be given if (typeQName != null)
// back out because it is unconvertable. {
ValueType valueType = makeValueType(typeQName); // Convert the value to the type required. This ensures that any type conversion issues
value = valueType.convert(value); // are caught early and prevent the scenario where the data in the DB cannot be given
// back out because it is unconvertable.
ValueType valueType = makeValueType(typeQName);
value = valueType.convert(value);
}
// get the persisted type // get the persisted type
ValueType persistedValueType = this.actualType.getPersistedType(value); ValueType persistedValueType = this.actualType.getPersistedType(value);
// convert to the persistent type // convert to the persistent type
@ -705,27 +709,41 @@ public class PropertyValue implements Cloneable, Serializable
*/ */
private Serializable cloneSerializable(Serializable original) private Serializable cloneSerializable(Serializable original)
{ {
ObjectOutputStream objectOut = null;
ByteArrayOutputStream byteOut = null;
ObjectInputStream objectIn = null;
try try
{ {
// Connect the pipes // Write the object out to a byte array
PipedOutputStream pipeOut = new PipedOutputStream(); byteOut = new ByteArrayOutputStream();
PipedInputStream pipeIn = new PipedInputStream(); objectOut = new ObjectOutputStream(byteOut);
pipeOut.connect(pipeIn); objectOut.writeObject(original);
objectOut.flush();
ObjectOutputStream objectOut = new ObjectOutputStream(pipeOut); objectIn = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray()));
ObjectInputStream objectIn = new ObjectInputStream(pipeIn); Object target = objectIn.readObject();
// Done
// Now write the object return (Serializable) target;
objectOut.writeObject(original);
// Read the new object in
Object newObj = objectIn.readObject();
// Done
return (Serializable) newObj;
} }
catch (Throwable e) catch (Throwable e)
{ {
throw new AlfrescoRuntimeException("Failed to clone serializable object: " + original, e); throw new AlfrescoRuntimeException("Failed to clone serializable object: " + original, e);
} }
finally
{
if (objectOut != null)
{
try { objectOut.close(); } catch (Throwable e) {}
}
if (byteOut != null)
{
try { byteOut.close(); } catch (Throwable e) {}
}
if (objectIn != null)
{
try { objectIn.close(); } catch (Throwable e) {}
}
}
} }
/** /**

View File

@ -24,6 +24,8 @@
*/ */
package org.alfresco.repo.jscript; package org.alfresco.repo.jscript;
import java.awt.event.ActionEvent;
import javax.swing.WindowConstants; import javax.swing.WindowConstants;
import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.authentication.AuthenticationUtil;
@ -46,17 +48,15 @@ import org.mozilla.javascript.tools.shell.Global;
* *
* @author davidc * @author davidc
*/ */
public class AlfrescoRhinoScriptDebugger extends Dim public class AlfrescoRhinoScriptDebugger
{ {
// Logger // Logger
private static final Log logger = LogFactory.getLog(AlfrescoRhinoScriptDebugger.class); private static final Log logger = LogFactory.getLog(AlfrescoRhinoScriptDebugger.class);
private boolean active = false; private ContextFactory factory = null;
private boolean visible = false; private AlfrescoDim dim = null;
private ContextFactory factory = null;
private Global global = null;
private AlfrescoRhinoScriptDebugger dim = null;
private SwingGui gui = null; private SwingGui gui = null;
/** /**
@ -70,22 +70,27 @@ public class AlfrescoRhinoScriptDebugger extends Dim
show(); show();
} }
} }
/** /**
* Activate the Debugger * Activate the Debugger
*/ */
public synchronized void activate() public synchronized void activate()
{ {
factory = ContextFactory.getGlobal(); factory = ContextFactory.getGlobal();
global = new Global(); Global global = new Global();
global.init(factory); global.init(factory);
dim = new AlfrescoRhinoScriptDebugger(); global.setIn(System.in);
dim.setScopeProvider(IProxy.newScopeProvider((Scriptable)global)); global.setOut(System.out);
gui = new SwingGui(dim, "Alfresco JavaScript Debugger"); global.setErr(System.err);
gui.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); dim = new AlfrescoDim();
active = true; ScopeProvider sp = IProxy.newScopeProvider((Scriptable)global);
dim.setScopeProvider(sp);
gui = new AlfrescoGui(dim, "Alfresco JavaScript Debugger", this);
gui.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
gui.setExitAction((Runnable)sp);
} }
/** /**
* Show the debugger * Show the debugger
*/ */
@ -97,15 +102,14 @@ public class AlfrescoRhinoScriptDebugger extends Dim
} }
dim.setBreakOnExceptions(true); dim.setBreakOnExceptions(true);
dim.setBreakOnEnter(true); dim.setBreak();
dim.setBreakOnReturn(true);
dim.attachTo(factory); dim.attachTo(factory);
gui.pack(); gui.pack();
gui.setSize(600, 460); gui.setSize(600, 460);
gui.setVisible(true); gui.setVisible(true);
visible = true;
} }
/** /**
* Hide the Debugger * Hide the Debugger
*/ */
@ -115,7 +119,6 @@ public class AlfrescoRhinoScriptDebugger extends Dim
{ {
dim.detach(); dim.detach();
gui.dispose(); gui.dispose();
visible = false;
} }
} }
@ -126,7 +129,7 @@ public class AlfrescoRhinoScriptDebugger extends Dim
*/ */
public boolean isVisible() public boolean isVisible()
{ {
return visible; return isActive() && gui.isVisible();
} }
/** /**
@ -136,38 +139,61 @@ public class AlfrescoRhinoScriptDebugger extends Dim
*/ */
public boolean isActive() public boolean isActive()
{ {
return active; return gui != null;
} }
/* (non-Javadoc)
* @see org.mozilla.javascript.tools.debugger.Dim#objectToString(java.lang.Object) public static class AlfrescoDim extends Dim
*/
@Override
public String objectToString(final Object arg0)
{ {
// execute command in context of currently selected user /* (non-Javadoc)
return AuthenticationUtil.runAs(new RunAsWork<String>() * @see org.mozilla.javascript.tools.debugger.Dim#objectToString(java.lang.Object)
*/
@Override
public String objectToString(final Object arg0)
{ {
@SuppressWarnings("synthetic-access") // execute command in context of currently selected user
public String doWork() throws Exception return AuthenticationUtil.runAs(new RunAsWork<String>()
{ {
return AlfrescoRhinoScriptDebugger.super.objectToString(arg0); @SuppressWarnings("synthetic-access")
} public String doWork() throws Exception
}, AuthenticationUtil.getSystemUserName()); {
return AlfrescoDim.super.objectToString(arg0);
}
}, AuthenticationUtil.getSystemUserName());
}
} }
/**
* Class to consolidate all internal implementations of interfaces to avoid private static class AlfrescoGui extends SwingGui
* class generation bloat.
*/
private static class IProxy implements Runnable, ScopeProvider
{ {
private static final long serialVersionUID = 5053205080777378416L;
private AlfrescoRhinoScriptDebugger debugger;
public AlfrescoGui(Dim dim, String title, AlfrescoRhinoScriptDebugger debugger)
{
super(dim, title);
this.debugger = debugger;
}
public void actionPerformed(ActionEvent e)
{
String cmd = e.getActionCommand();
if (cmd.equals("Exit"))
{
debugger.hide();
}
else
{
super.actionPerformed(e);
}
}
}
public static class IProxy implements Runnable, ScopeProvider
{
// Constants for 'type'. // Constants for 'type'.
public static final int EXIT_ACTION = 1; public static final int EXIT_ACTION = 1;
public static final int SCOPE_PROVIDER = 2; public static final int SCOPE_PROVIDER = 2;
/** /**
@ -180,7 +206,7 @@ public class AlfrescoRhinoScriptDebugger extends Dim
* {@link #SCOPE_PROVIDER}. * {@link #SCOPE_PROVIDER}.
*/ */
private Scriptable scope; private Scriptable scope;
/** /**
* Creates a new IProxy. * Creates a new IProxy.
@ -195,7 +221,7 @@ public class AlfrescoRhinoScriptDebugger extends Dim
*/ */
public static ScopeProvider newScopeProvider(Scriptable scope) public static ScopeProvider newScopeProvider(Scriptable scope)
{ {
IProxy scopeProvider = new IProxy(SCOPE_PROVIDER); IProxy scopeProvider = new IProxy(EXIT_ACTION);
scopeProvider.scope = scope; scopeProvider.scope = scope;
return scopeProvider; return scopeProvider;
} }
@ -225,5 +251,4 @@ public class AlfrescoRhinoScriptDebugger extends Dim
return scope; return scope;
} }
} }
} }

View File

@ -393,7 +393,7 @@ public class ADMLuceneTest extends TestCase
writer.putContent("The quick brown fox jumped over the lazy dog and ate the Alfresco Tutorial, in pdf format, along with the following stop words; a an and are" writer.putContent("The quick brown fox jumped over the lazy dog and ate the Alfresco Tutorial, in pdf format, along with the following stop words; a an and are"
+ " as at be but by for if in into is it no not of on or such that the their then there these they this to was will with: " + " as at be but by for if in into is it no not of on or such that the their then there these they this to was will with: "
+ " and random charcters \u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF"); + " and random charcters \u00E0\u00EA\u00EE\u00F0\u00F1\u00F6\u00FB\u00FF");
System.out.println("Size is " + writer.getSize()); //System.out.println("Size is " + writer.getSize());
nodeService.addChild(rootNodeRef, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-0")); nodeService.addChild(rootNodeRef, n8, ContentModel.ASSOC_CHILDREN, QName.createQName("{namespace}eight-0"));
nodeService.addChild(n1, n8, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-1")); nodeService.addChild(n1, n8, ASSOC_TYPE_QNAME, QName.createQName("{namespace}eight-1"));
@ -2527,6 +2527,49 @@ public class ADMLuceneTest extends TestCase
assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista"))); assertNotNull(results.getRow(0).getValue(QName.createQName(TEST_NAMESPACE, "any-many-ista")));
results.close(); results.close();
// proximity searches
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~0", null, null);
assertEquals(0, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~1", null, null);
assertEquals(0, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~2", null, null);
assertEquals(1, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "TEXT:\"Tutorial Alfresco\"~3", null, null);
assertEquals(1, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + LuceneQueryParser.escape(ContentModel.PROP_DESCRIPTION.toString())+":\"Alfresco Tutorial\"", null, null);
assertEquals(1, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + LuceneQueryParser.escape(ContentModel.PROP_DESCRIPTION.toString())+":\"Tutorial Alfresco\"", null, null);
assertEquals(0, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + LuceneQueryParser.escape(ContentModel.PROP_DESCRIPTION.toString())+":\"Tutorial Alfresco\"~0", null, null);
assertEquals(0, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + LuceneQueryParser.escape(ContentModel.PROP_DESCRIPTION.toString())+":\"Tutorial Alfresco\"~1", null, null);
assertEquals(0, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + LuceneQueryParser.escape(ContentModel.PROP_DESCRIPTION.toString())+":\"Tutorial Alfresco\"~2", null, null);
assertEquals(1, results.length());
results.close();
results = searcher.query(rootNodeRef.getStoreRef(), "lucene", "@" + LuceneQueryParser.escape(ContentModel.PROP_DESCRIPTION.toString())+":\"Tutorial Alfresco\"~3", null, null);
assertEquals(1, results.length());
results.close();
// multi ml text // multi ml text
QName multimlQName = QName.createQName(TEST_NAMESPACE, "mltext-many-ista"); QName multimlQName = QName.createQName(TEST_NAMESPACE, "mltext-many-ista");

View File

@ -262,7 +262,7 @@ public class LuceneAnalyser extends Analyzer
PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName); PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName);
if (propertyDef != null) if (propertyDef != null)
{ {
if (propertyDef.getDataType().equals(DataTypeDefinition.MLTEXT)) if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT))
{ {
return 1000; return 1000;
} }

View File

@ -90,6 +90,8 @@ public class LuceneQueryParser extends QueryParser
private IndexReader indexReader; private IndexReader indexReader;
private int internalSlop = 0;
/** /**
* Parses a query string, returning a {@link org.apache.lucene.search.Query}. * Parses a query string, returning a {@link org.apache.lucene.search.Query}.
* *
@ -168,6 +170,21 @@ public class LuceneQueryParser extends QueryParser
super(arg0); super(arg0);
} }
protected Query getFieldQuery(String field, String queryText, int slop) throws ParseException
{
try
{
internalSlop = slop;
Query query = getFieldQuery(field, queryText);
return query;
}
finally
{
internalSlop = 0;
}
}
protected Query getFieldQuery(String field, String queryText) throws ParseException protected Query getFieldQuery(String field, String queryText) throws ParseException
{ {
try try
@ -691,7 +708,7 @@ public class LuceneQueryParser extends QueryParser
{ {
v.add(it.next()); v.add(it.next());
count++; count++;
if(count > 1) if (count > 1)
{ {
severalTokensAtSamePosition = true; severalTokensAtSamePosition = true;
} }
@ -752,7 +769,7 @@ public class LuceneQueryParser extends QueryParser
{ {
v.add(it.next()); v.add(it.next());
count++; count++;
if(count > 1) if (count > 1)
{ {
severalTokensAtSamePosition = true; severalTokensAtSamePosition = true;
} }
@ -1019,7 +1036,7 @@ public class LuceneQueryParser extends QueryParser
{ {
// phrase query: // phrase query:
MultiPhraseQuery mpq = new MultiPhraseQuery(); MultiPhraseQuery mpq = new MultiPhraseQuery();
mpq.setSlop(phraseSlop); mpq.setSlop(internalSlop);
ArrayList<Term> multiTerms = new ArrayList<Term>(); ArrayList<Term> multiTerms = new ArrayList<Term>();
for (int i = 0; i < v.size(); i++) for (int i = 0; i < v.size(); i++)
{ {
@ -1053,7 +1070,7 @@ public class LuceneQueryParser extends QueryParser
else else
{ {
MultiPhraseQuery q = new MultiPhraseQuery(); MultiPhraseQuery q = new MultiPhraseQuery();
q.setSlop(phraseSlop); q.setSlop(internalSlop);
for (int i = 0; i < v.size(); i++) for (int i = 0; i < v.size(); i++)
{ {
t = (org.apache.lucene.analysis.Token) v.get(i); t = (org.apache.lucene.analysis.Token) v.get(i);
@ -1096,9 +1113,9 @@ public class LuceneQueryParser extends QueryParser
while (!wcte.endEnum()) while (!wcte.endEnum())
{ {
Term current = wcte.term(); Term current = wcte.term();
if((current.text() != null) && (current.text().length() > 0) && (current.text().charAt(0) == '{')) if ((current.text() != null) && (current.text().length() > 0) && (current.text().charAt(0) == '{'))
{ {
if((term != null) && (term.text().length() > 0) && (term.text().charAt(0) == '{')) if ((term != null) && (term.text().length() > 0) && (term.text().charAt(0) == '{'))
{ {
terms.add(current); terms.add(current);
} }
@ -1108,7 +1125,7 @@ public class LuceneQueryParser extends QueryParser
{ {
terms.add(current); terms.add(current);
} }
wcte.next(); wcte.next();
} }
} }

View File

@ -39,9 +39,8 @@ import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.service.cmr.security.PermissionService; import org.alfresco.service.cmr.security.PermissionService;
/** /**
* This class abstract the support required to set up and query the Acegi context for security enforcement. * This class abstract the support required to set up and query the Acegi context for security enforcement. There are
* * some simple default method implementations to support simple authentication.
* There are some simple default method implementations to support simple authentication.
* *
* @author Andy Hind * @author Andy Hind
*/ */
@ -50,7 +49,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
// Name of the system user // Name of the system user
private static final String SYSTEM_USER_NAME = "System"; static final String SYSTEM_USER_NAME = "System";
private Boolean allowGuestLogin = null; private Boolean allowGuestLogin = null;
@ -63,7 +62,24 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
{ {
this.allowGuestLogin = allowGuestLogin; this.allowGuestLogin = allowGuestLogin;
} }
public void authenticate(String userName, char[] password) throws AuthenticationException
{
if ((userName != null) && (userName.equalsIgnoreCase(PermissionService.GUEST_AUTHORITY)))
{
setGuestUserAsCurrentUser();
}
else
{
authenticateImpl(userName, password);
}
}
protected void authenticateImpl(String userName, char[] password)
{
throw new UnsupportedOperationException();
}
/** /**
* Explicitly set the current user to be authenticated. * Explicitly set the current user to be authenticated.
* *
@ -97,8 +113,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
ud = getUserDetails(userName); ud = getUserDetails(userName);
} }
UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud.getAuthorities());
.getAuthorities());
auth.setDetails(ud); auth.setDetails(ud);
auth.setAuthenticated(true); auth.setAuthenticated(true);
return setCurrentAuthentication(auth); return setCurrentAuthentication(auth);
@ -133,28 +148,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
*/ */
public Authentication setCurrentAuthentication(Authentication authentication) public Authentication setCurrentAuthentication(Authentication authentication)
{ {
if (authentication == null) return AuthenticationUtil.setCurrentAuthentication(authentication);
{
clearCurrentSecurityContext();
return null;
}
else
{
Context context = ContextHolder.getContext();
SecureContext sc = null;
if ((context == null) || !(context instanceof SecureContext))
{
sc = new SecureContextImpl();
ContextHolder.setContext(sc);
}
else
{
sc = (SecureContext) context;
}
authentication.setAuthenticated(true);
sc.setAuthentication(authentication);
return authentication;
}
} }
/** /**
@ -165,12 +159,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
*/ */
public Authentication getCurrentAuthentication() throws AuthenticationException public Authentication getCurrentAuthentication() throws AuthenticationException
{ {
Context context = ContextHolder.getContext(); return AuthenticationUtil.getCurrentAuthentication();
if ((context == null) || !(context instanceof SecureContext))
{
return null;
}
return ((SecureContext) context).getAuthentication();
} }
/** /**
@ -181,12 +170,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
*/ */
public String getCurrentUserName() throws AuthenticationException public String getCurrentUserName() throws AuthenticationException
{ {
Context context = ContextHolder.getContext(); return AuthenticationUtil.getCurrentUserName();
if ((context == null) || !(context instanceof SecureContext))
{
return null;
}
return getUserName(((SecureContext) context).getAuthentication());
} }
/** /**
@ -201,7 +185,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
String username; String username;
if (authentication.getPrincipal() instanceof UserDetails) if (authentication.getPrincipal() instanceof UserDetails)
{ {
username = ((UserDetails)authentication.getPrincipal()).getUsername(); username = ((UserDetails) authentication.getPrincipal()).getUsername();
} }
else else
{ {
@ -246,31 +230,31 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
{ {
if (allowGuestLogin == null) if (allowGuestLogin == null)
{ {
if(implementationAllowsGuestLogin()) if (implementationAllowsGuestLogin())
{ {
return setCurrentUser(PermissionService.GUEST_AUTHORITY); return setCurrentUser(PermissionService.GUEST_AUTHORITY);
} }
else else
{ {
throw new AuthenticationException("Guest authentication is not allowed"); throw new AuthenticationException("Guest authentication is not allowed");
} }
} }
else else
{ {
if(allowGuestLogin.booleanValue()) if (allowGuestLogin.booleanValue())
{ {
return setCurrentUser(PermissionService.GUEST_AUTHORITY); return setCurrentUser(PermissionService.GUEST_AUTHORITY);
} }
else else
{ {
throw new AuthenticationException("Guest authentication is not allowed"); throw new AuthenticationException("Guest authentication is not allowed");
} }
} }
} }
protected abstract boolean implementationAllowsGuestLogin(); protected abstract boolean implementationAllowsGuestLogin();
/** /**
* @return true if Guest user authentication is allowed, false otherwise * @return true if Guest user authentication is allowed, false otherwise
*/ */
@ -291,7 +275,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC
*/ */
public void clearCurrentSecurityContext() public void clearCurrentSecurityContext()
{ {
ContextHolder.setContext(null); AuthenticationUtil.clearCurrentSecurityContext();
} }
/** /**

View File

@ -65,7 +65,7 @@ public class AuthenticationComponentImpl extends AbstractAuthenticationComponent
/** /**
* Authenticate * Authenticate
*/ */
public void authenticate(String userName, char[] password) throws AuthenticationException protected void authenticateImpl(String userName, char[] password) throws AuthenticationException
{ {
try try
{ {

View File

@ -234,6 +234,11 @@ public class AuthenticationTest extends TestCase
} }
} }
public void testGuest()
{
authenticationService.authenticate("GUEST", "".toCharArray());
}
public void testCreateUsers() public void testCreateUsers()
{ {
authenticationService.createAuthentication("GUEST", "".toCharArray()); authenticationService.createAuthentication("GUEST", "".toCharArray());

View File

@ -140,30 +140,38 @@ public abstract class AuthenticationUtil
*/ */
public static Authentication setCurrentAuthentication(Authentication authentication) public static Authentication setCurrentAuthentication(Authentication authentication)
{ {
Context context = ContextHolder.getContext(); if (authentication == null)
SecureContext sc = null;
if ((context == null) || !(context instanceof SecureContext))
{ {
sc = new SecureContextImpl(); clearCurrentSecurityContext();
ContextHolder.setContext(sc); return null;
} }
else else
{ {
sc = (SecureContext) context; Context context = ContextHolder.getContext();
} SecureContext sc = null;
authentication.setAuthenticated(true); if ((context == null) || !(context instanceof SecureContext))
sc.setAuthentication(authentication); {
sc = new SecureContextImpl();
ContextHolder.setContext(sc);
}
else
{
sc = (SecureContext) context;
}
authentication.setAuthenticated(true);
sc.setAuthentication(authentication);
// Support for logging tenant domain / username (via log4j NDC) // Support for logging tenant domain / username (via log4j NDC)
String userName = SYSTEM_USER_NAME; String userName = SYSTEM_USER_NAME;
if (authentication.getPrincipal() instanceof UserDetails) if (authentication.getPrincipal() instanceof UserDetails)
{ {
userName = ((UserDetails) authentication.getPrincipal()).getUsername(); userName = ((UserDetails) authentication.getPrincipal()).getUsername();
}
logNDC(userName);
return authentication;
} }
logNDC(userName);
return authentication;
} }
public static void logNDC(String userName) public static void logNDC(String userName)

View File

@ -34,8 +34,7 @@ import net.sf.acegisecurity.providers.encoding.BaseDigestPasswordEncoder;
import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex; import org.apache.commons.codec.binary.Hex;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import cryptix.jce.provider.CryptixCrypto;
/** /**
* <p> * <p>
@ -62,7 +61,7 @@ public class MD4PasswordEncoderImpl extends BaseDigestPasswordEncoder implements
} }
catch (NoSuchAlgorithmException e) catch (NoSuchAlgorithmException e)
{ {
Security.addProvider(new CryptixCrypto()); Security.addProvider(new BouncyCastleProvider());
} }
} }

View File

@ -51,7 +51,7 @@ public class SimpleAcceptOrRejectAllAuthenticationComponentImpl extends Abstract
this.accept = accept; this.accept = accept;
} }
public void authenticate(String userName, char[] password) throws AuthenticationException public void authenticateImpl(String userName, char[] password) throws AuthenticationException
{ {
if(accept) if(accept)
{ {

View File

@ -126,7 +126,7 @@ public class JAASAuthenticationComponent extends AbstractAuthenticationComponent
/** /**
* Implement Authentication * Implement Authentication
*/ */
public void authenticate(String userName, char[] password) throws AuthenticationException protected void authenticateImpl(String userName, char[] password) throws AuthenticationException
{ {
LoginContext lc; LoginContext lc;

View File

@ -62,7 +62,7 @@ public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationCompo
/** /**
* Implement the authentication method * Implement the authentication method
*/ */
public void authenticate(String userName, char[] password) throws AuthenticationException protected void authenticateImpl(String userName, char[] password) throws AuthenticationException
{ {
InitialDirContext ctx = null; InitialDirContext ctx = null;
try try

View File

@ -507,7 +507,7 @@ public class NTLMAuthenticationComponentImpl extends AbstractAuthenticationCompo
* @param password char[] * @param password char[]
* @throws AuthenticationException * @throws AuthenticationException
*/ */
public void authenticate(String userName, char[] password) throws AuthenticationException protected void authenticateImpl(String userName, char[] password) throws AuthenticationException
{ {
// Debug // Debug