diff --git a/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java b/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java index ccb6c75f3f..9043d4e619 100644 --- a/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java +++ b/source/java/org/alfresco/filesys/server/config/ServerConfiguration.java @@ -2310,9 +2310,9 @@ public class ServerConfiguration extends AbstractLifecycleBean } 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 diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index 9596740c72..2e37892c83 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -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.avmsync.AVMDifference; 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.remote.RepoRemote; import org.alfresco.service.cmr.repository.ContentData; @@ -111,10 +112,10 @@ public class AVMServiceTest extends AVMServiceTestBase try { fService.setStoreProperty("main", QName.createQName(null, ".dns.main"), - new PropertyValue(QName.createQName(null, "silly"), "Nothing.")); + new PropertyValue(DataTypeDefinition.TEXT, "Nothing.")); fService.createStore("test"); fService.setStoreProperty("test", QName.createQName(null, ".dns.test.main"), - new PropertyValue(QName.createQName(null, "silly"), "Nothing.")); + new PropertyValue(DataTypeDefinition.TEXT, "Nothing.")); setupBasicTree0(); authService.authenticateAsGuest(); // assertEquals(0, fLockingService.getUsersLocks("admin").size()); @@ -195,7 +196,7 @@ public class AVMServiceTest extends AVMServiceTestBase results.close(); 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.createSnapshot("main", null, null); results = searchService.query(storeRef, "lucene", LuceneQueryParser.escape("@{silly.uri}SillyProperty")+":\"Silly\""); @@ -5162,7 +5163,7 @@ public class AVMServiceTest extends AVMServiceTestBase try { 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); PropertyValue found = fService.getStoreProperty("main", name); assertEquals(value.toString(), found.toString()); diff --git a/source/java/org/alfresco/repo/domain/PropertyValue.java b/source/java/org/alfresco/repo/domain/PropertyValue.java index 55ccce5cd3..bc917bf6d3 100644 --- a/source/java/org/alfresco/repo/domain/PropertyValue.java +++ b/source/java/org/alfresco/repo/domain/PropertyValue.java @@ -24,10 +24,10 @@ */ package org.alfresco.repo.domain; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; -import java.io.PipedInputStream; -import java.io.PipedOutputStream; import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; @@ -516,11 +516,15 @@ public class PropertyValue implements Cloneable, Serializable } else { - // Convert the value to the type required. This ensures that any type conversion issues - // 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); + // Does the client consider the type to be important? + if (typeQName != null) + { + // Convert the value to the type required. This ensures that any type conversion issues + // 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 ValueType persistedValueType = this.actualType.getPersistedType(value); // convert to the persistent type @@ -705,27 +709,41 @@ public class PropertyValue implements Cloneable, Serializable */ private Serializable cloneSerializable(Serializable original) { + ObjectOutputStream objectOut = null; + ByteArrayOutputStream byteOut = null; + ObjectInputStream objectIn = null; try { - // Connect the pipes - PipedOutputStream pipeOut = new PipedOutputStream(); - PipedInputStream pipeIn = new PipedInputStream(); - pipeOut.connect(pipeIn); + // Write the object out to a byte array + byteOut = new ByteArrayOutputStream(); + objectOut = new ObjectOutputStream(byteOut); + objectOut.writeObject(original); + objectOut.flush(); - ObjectOutputStream objectOut = new ObjectOutputStream(pipeOut); - ObjectInputStream objectIn = new ObjectInputStream(pipeIn); - - // Now write the object - objectOut.writeObject(original); - // Read the new object in - Object newObj = objectIn.readObject(); - // Done - return (Serializable) newObj; + objectIn = new ObjectInputStream(new ByteArrayInputStream(byteOut.toByteArray())); + Object target = objectIn.readObject(); + // Done + return (Serializable) target; } catch (Throwable 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) {} + } + } } /** diff --git a/source/java/org/alfresco/repo/jscript/AlfrescoRhinoScriptDebugger.java b/source/java/org/alfresco/repo/jscript/AlfrescoRhinoScriptDebugger.java index 29120247a1..56f1f59e24 100644 --- a/source/java/org/alfresco/repo/jscript/AlfrescoRhinoScriptDebugger.java +++ b/source/java/org/alfresco/repo/jscript/AlfrescoRhinoScriptDebugger.java @@ -24,6 +24,8 @@ */ package org.alfresco.repo.jscript; +import java.awt.event.ActionEvent; + import javax.swing.WindowConstants; import org.alfresco.repo.security.authentication.AuthenticationUtil; @@ -46,17 +48,15 @@ import org.mozilla.javascript.tools.shell.Global; * * @author davidc */ -public class AlfrescoRhinoScriptDebugger extends Dim +public class AlfrescoRhinoScriptDebugger { // Logger private static final Log logger = LogFactory.getLog(AlfrescoRhinoScriptDebugger.class); - - private boolean active = false; - private boolean visible = false; - private ContextFactory factory = null; - private Global global = null; - private AlfrescoRhinoScriptDebugger dim = null; + + private ContextFactory factory = null; + private AlfrescoDim dim = null; private SwingGui gui = null; + /** @@ -70,22 +70,27 @@ public class AlfrescoRhinoScriptDebugger extends Dim show(); } } - + /** * Activate the Debugger */ public synchronized void activate() { factory = ContextFactory.getGlobal(); - global = new Global(); + Global global = new Global(); global.init(factory); - dim = new AlfrescoRhinoScriptDebugger(); - dim.setScopeProvider(IProxy.newScopeProvider((Scriptable)global)); - gui = new SwingGui(dim, "Alfresco JavaScript Debugger"); - gui.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - active = true; + global.setIn(System.in); + global.setOut(System.out); + global.setErr(System.err); + dim = new AlfrescoDim(); + 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 */ @@ -97,15 +102,14 @@ public class AlfrescoRhinoScriptDebugger extends Dim } dim.setBreakOnExceptions(true); - dim.setBreakOnEnter(true); - dim.setBreakOnReturn(true); + dim.setBreak(); dim.attachTo(factory); gui.pack(); gui.setSize(600, 460); gui.setVisible(true); - visible = true; } + /** * Hide the Debugger */ @@ -115,7 +119,6 @@ public class AlfrescoRhinoScriptDebugger extends Dim { dim.detach(); gui.dispose(); - visible = false; } } @@ -126,7 +129,7 @@ public class AlfrescoRhinoScriptDebugger extends Dim */ public boolean isVisible() { - return visible; + return isActive() && gui.isVisible(); } /** @@ -136,38 +139,61 @@ public class AlfrescoRhinoScriptDebugger extends Dim */ public boolean isActive() { - return active; + return gui != null; } - - /* (non-Javadoc) - * @see org.mozilla.javascript.tools.debugger.Dim#objectToString(java.lang.Object) - */ - @Override - public String objectToString(final Object arg0) + + public static class AlfrescoDim extends Dim { - // execute command in context of currently selected user - return AuthenticationUtil.runAs(new RunAsWork() + /* (non-Javadoc) + * @see org.mozilla.javascript.tools.debugger.Dim#objectToString(java.lang.Object) + */ + @Override + public String objectToString(final Object arg0) { - @SuppressWarnings("synthetic-access") - public String doWork() throws Exception + // execute command in context of currently selected user + return AuthenticationUtil.runAs(new RunAsWork() { - return AlfrescoRhinoScriptDebugger.super.objectToString(arg0); - } - }, AuthenticationUtil.getSystemUserName()); + @SuppressWarnings("synthetic-access") + public String doWork() throws Exception + { + return AlfrescoDim.super.objectToString(arg0); + } + }, AuthenticationUtil.getSystemUserName()); + } } - - /** - * Class to consolidate all internal implementations of interfaces to avoid - * class generation bloat. - */ - private static class IProxy implements Runnable, ScopeProvider + + private static class AlfrescoGui extends SwingGui { + 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'. public static final int EXIT_ACTION = 1; - public static final int SCOPE_PROVIDER = 2; /** @@ -180,7 +206,7 @@ public class AlfrescoRhinoScriptDebugger extends Dim * {@link #SCOPE_PROVIDER}. */ private Scriptable scope; - + /** * Creates a new IProxy. @@ -195,7 +221,7 @@ public class AlfrescoRhinoScriptDebugger extends Dim */ public static ScopeProvider newScopeProvider(Scriptable scope) { - IProxy scopeProvider = new IProxy(SCOPE_PROVIDER); + IProxy scopeProvider = new IProxy(EXIT_ACTION); scopeProvider.scope = scope; return scopeProvider; } @@ -225,5 +251,4 @@ public class AlfrescoRhinoScriptDebugger extends Dim return scope; } } - } diff --git a/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java b/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java index 6287be07e8..de022298da 100644 --- a/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java +++ b/source/java/org/alfresco/repo/search/impl/lucene/ADMLuceneTest.java @@ -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" + " 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"); - 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(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"))); 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 QName multimlQName = QName.createQName(TEST_NAMESPACE, "mltext-many-ista"); diff --git a/source/java/org/alfresco/repo/search/impl/lucene/LuceneAnalyser.java b/source/java/org/alfresco/repo/search/impl/lucene/LuceneAnalyser.java index 0f8c2834a2..a8c810676b 100644 --- a/source/java/org/alfresco/repo/search/impl/lucene/LuceneAnalyser.java +++ b/source/java/org/alfresco/repo/search/impl/lucene/LuceneAnalyser.java @@ -262,7 +262,7 @@ public class LuceneAnalyser extends Analyzer PropertyDefinition propertyDef = dictionaryService.getProperty(propertyQName); if (propertyDef != null) { - if (propertyDef.getDataType().equals(DataTypeDefinition.MLTEXT)) + if (propertyDef.getDataType().getName().equals(DataTypeDefinition.MLTEXT)) { return 1000; } diff --git a/source/java/org/alfresco/repo/search/impl/lucene/LuceneQueryParser.java b/source/java/org/alfresco/repo/search/impl/lucene/LuceneQueryParser.java index 1b576956bf..a8829bc490 100644 --- a/source/java/org/alfresco/repo/search/impl/lucene/LuceneQueryParser.java +++ b/source/java/org/alfresco/repo/search/impl/lucene/LuceneQueryParser.java @@ -90,6 +90,8 @@ public class LuceneQueryParser extends QueryParser private IndexReader indexReader; + private int internalSlop = 0; + /** * Parses a query string, returning a {@link org.apache.lucene.search.Query}. * @@ -168,6 +170,21 @@ public class LuceneQueryParser extends QueryParser 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 { try @@ -691,7 +708,7 @@ public class LuceneQueryParser extends QueryParser { v.add(it.next()); count++; - if(count > 1) + if (count > 1) { severalTokensAtSamePosition = true; } @@ -752,7 +769,7 @@ public class LuceneQueryParser extends QueryParser { v.add(it.next()); count++; - if(count > 1) + if (count > 1) { severalTokensAtSamePosition = true; } @@ -1019,7 +1036,7 @@ public class LuceneQueryParser extends QueryParser { // phrase query: MultiPhraseQuery mpq = new MultiPhraseQuery(); - mpq.setSlop(phraseSlop); + mpq.setSlop(internalSlop); ArrayList multiTerms = new ArrayList(); for (int i = 0; i < v.size(); i++) { @@ -1053,7 +1070,7 @@ public class LuceneQueryParser extends QueryParser else { MultiPhraseQuery q = new MultiPhraseQuery(); - q.setSlop(phraseSlop); + q.setSlop(internalSlop); for (int i = 0; i < v.size(); i++) { t = (org.apache.lucene.analysis.Token) v.get(i); @@ -1096,9 +1113,9 @@ public class LuceneQueryParser extends QueryParser while (!wcte.endEnum()) { 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); } @@ -1108,7 +1125,7 @@ public class LuceneQueryParser extends QueryParser { terms.add(current); } - + wcte.next(); } } diff --git a/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java b/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java index c4f0f2663a..baa5b6b4e9 100644 --- a/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java +++ b/source/java/org/alfresco/repo/security/authentication/AbstractAuthenticationComponent.java @@ -39,9 +39,8 @@ import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.service.cmr.security.PermissionService; /** - * 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. + * 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. * * @author Andy Hind */ @@ -50,7 +49,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC // Name of the system user - private static final String SYSTEM_USER_NAME = "System"; + static final String SYSTEM_USER_NAME = "System"; private Boolean allowGuestLogin = null; @@ -63,7 +62,24 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC { 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. * @@ -97,8 +113,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC ud = getUserDetails(userName); } - UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud - .getAuthorities()); + UsernamePasswordAuthenticationToken auth = new UsernamePasswordAuthenticationToken(ud, "", ud.getAuthorities()); auth.setDetails(ud); auth.setAuthenticated(true); return setCurrentAuthentication(auth); @@ -133,28 +148,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC */ public Authentication setCurrentAuthentication(Authentication authentication) { - if (authentication == null) - { - 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; - } + return AuthenticationUtil.setCurrentAuthentication(authentication); } /** @@ -165,12 +159,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC */ public Authentication getCurrentAuthentication() throws AuthenticationException { - Context context = ContextHolder.getContext(); - if ((context == null) || !(context instanceof SecureContext)) - { - return null; - } - return ((SecureContext) context).getAuthentication(); + return AuthenticationUtil.getCurrentAuthentication(); } /** @@ -181,12 +170,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC */ public String getCurrentUserName() throws AuthenticationException { - Context context = ContextHolder.getContext(); - if ((context == null) || !(context instanceof SecureContext)) - { - return null; - } - return getUserName(((SecureContext) context).getAuthentication()); + return AuthenticationUtil.getCurrentUserName(); } /** @@ -201,7 +185,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC String username; if (authentication.getPrincipal() instanceof UserDetails) { - username = ((UserDetails)authentication.getPrincipal()).getUsername(); + username = ((UserDetails) authentication.getPrincipal()).getUsername(); } else { @@ -246,31 +230,31 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC { if (allowGuestLogin == null) { - if(implementationAllowsGuestLogin()) + if (implementationAllowsGuestLogin()) { return setCurrentUser(PermissionService.GUEST_AUTHORITY); } else { - throw new AuthenticationException("Guest authentication is not allowed"); + throw new AuthenticationException("Guest authentication is not allowed"); } } else { - if(allowGuestLogin.booleanValue()) + if (allowGuestLogin.booleanValue()) { return setCurrentUser(PermissionService.GUEST_AUTHORITY); } else { - throw new AuthenticationException("Guest authentication is not allowed"); + throw new AuthenticationException("Guest authentication is not allowed"); } - + } } protected abstract boolean implementationAllowsGuestLogin(); - + /** * @return true if Guest user authentication is allowed, false otherwise */ @@ -291,7 +275,7 @@ public abstract class AbstractAuthenticationComponent implements AuthenticationC */ public void clearCurrentSecurityContext() { - ContextHolder.setContext(null); + AuthenticationUtil.clearCurrentSecurityContext(); } /** diff --git a/source/java/org/alfresco/repo/security/authentication/AuthenticationComponentImpl.java b/source/java/org/alfresco/repo/security/authentication/AuthenticationComponentImpl.java index 2893af5018..b2a9f10942 100644 --- a/source/java/org/alfresco/repo/security/authentication/AuthenticationComponentImpl.java +++ b/source/java/org/alfresco/repo/security/authentication/AuthenticationComponentImpl.java @@ -65,7 +65,7 @@ public class AuthenticationComponentImpl extends AbstractAuthenticationComponent /** * Authenticate */ - public void authenticate(String userName, char[] password) throws AuthenticationException + protected void authenticateImpl(String userName, char[] password) throws AuthenticationException { try { diff --git a/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java b/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java index 5c82567fa7..23f345cdd5 100644 --- a/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java +++ b/source/java/org/alfresco/repo/security/authentication/AuthenticationTest.java @@ -234,6 +234,11 @@ public class AuthenticationTest extends TestCase } } + public void testGuest() + { + authenticationService.authenticate("GUEST", "".toCharArray()); + } + public void testCreateUsers() { authenticationService.createAuthentication("GUEST", "".toCharArray()); diff --git a/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java b/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java index 65869247b1..a83ef0a637 100644 --- a/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java +++ b/source/java/org/alfresco/repo/security/authentication/AuthenticationUtil.java @@ -140,30 +140,38 @@ public abstract class AuthenticationUtil */ public static Authentication setCurrentAuthentication(Authentication authentication) { - Context context = ContextHolder.getContext(); - SecureContext sc = null; - if ((context == null) || !(context instanceof SecureContext)) + if (authentication == null) { - sc = new SecureContextImpl(); - ContextHolder.setContext(sc); + clearCurrentSecurityContext(); + return null; } else { - sc = (SecureContext) context; - } - authentication.setAuthenticated(true); - sc.setAuthentication(authentication); + 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); - // Support for logging tenant domain / username (via log4j NDC) - String userName = SYSTEM_USER_NAME; - if (authentication.getPrincipal() instanceof UserDetails) - { - userName = ((UserDetails) authentication.getPrincipal()).getUsername(); + // Support for logging tenant domain / username (via log4j NDC) + String userName = SYSTEM_USER_NAME; + if (authentication.getPrincipal() instanceof UserDetails) + { + userName = ((UserDetails) authentication.getPrincipal()).getUsername(); + } + + logNDC(userName); + + return authentication; } - - logNDC(userName); - - return authentication; } public static void logNDC(String userName) diff --git a/source/java/org/alfresco/repo/security/authentication/MD4PasswordEncoderImpl.java b/source/java/org/alfresco/repo/security/authentication/MD4PasswordEncoderImpl.java index 0d018b8f6d..d7e6d2c565 100644 --- a/source/java/org/alfresco/repo/security/authentication/MD4PasswordEncoderImpl.java +++ b/source/java/org/alfresco/repo/security/authentication/MD4PasswordEncoderImpl.java @@ -34,8 +34,7 @@ import net.sf.acegisecurity.providers.encoding.BaseDigestPasswordEncoder; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; - -import cryptix.jce.provider.CryptixCrypto; +import org.bouncycastle.jce.provider.BouncyCastleProvider; /** *

@@ -62,7 +61,7 @@ public class MD4PasswordEncoderImpl extends BaseDigestPasswordEncoder implements } catch (NoSuchAlgorithmException e) { - Security.addProvider(new CryptixCrypto()); + Security.addProvider(new BouncyCastleProvider()); } } diff --git a/source/java/org/alfresco/repo/security/authentication/SimpleAcceptOrRejectAllAuthenticationComponentImpl.java b/source/java/org/alfresco/repo/security/authentication/SimpleAcceptOrRejectAllAuthenticationComponentImpl.java index ac41d13135..af27b148b4 100644 --- a/source/java/org/alfresco/repo/security/authentication/SimpleAcceptOrRejectAllAuthenticationComponentImpl.java +++ b/source/java/org/alfresco/repo/security/authentication/SimpleAcceptOrRejectAllAuthenticationComponentImpl.java @@ -51,7 +51,7 @@ public class SimpleAcceptOrRejectAllAuthenticationComponentImpl extends Abstract this.accept = accept; } - public void authenticate(String userName, char[] password) throws AuthenticationException + public void authenticateImpl(String userName, char[] password) throws AuthenticationException { if(accept) { diff --git a/source/java/org/alfresco/repo/security/authentication/jaas/JAASAuthenticationComponent.java b/source/java/org/alfresco/repo/security/authentication/jaas/JAASAuthenticationComponent.java index 3890967fc4..ce7e5458fd 100644 --- a/source/java/org/alfresco/repo/security/authentication/jaas/JAASAuthenticationComponent.java +++ b/source/java/org/alfresco/repo/security/authentication/jaas/JAASAuthenticationComponent.java @@ -126,7 +126,7 @@ public class JAASAuthenticationComponent extends AbstractAuthenticationComponent /** * Implement Authentication */ - public void authenticate(String userName, char[] password) throws AuthenticationException + protected void authenticateImpl(String userName, char[] password) throws AuthenticationException { LoginContext lc; diff --git a/source/java/org/alfresco/repo/security/authentication/ldap/LDAPAuthenticationComponentImpl.java b/source/java/org/alfresco/repo/security/authentication/ldap/LDAPAuthenticationComponentImpl.java index 02b5aa8b05..ef8c0c6ea5 100644 --- a/source/java/org/alfresco/repo/security/authentication/ldap/LDAPAuthenticationComponentImpl.java +++ b/source/java/org/alfresco/repo/security/authentication/ldap/LDAPAuthenticationComponentImpl.java @@ -62,7 +62,7 @@ public class LDAPAuthenticationComponentImpl extends AbstractAuthenticationCompo /** * 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; try diff --git a/source/java/org/alfresco/repo/security/authentication/ntlm/NTLMAuthenticationComponentImpl.java b/source/java/org/alfresco/repo/security/authentication/ntlm/NTLMAuthenticationComponentImpl.java index 1461b30c45..33863ab311 100644 --- a/source/java/org/alfresco/repo/security/authentication/ntlm/NTLMAuthenticationComponentImpl.java +++ b/source/java/org/alfresco/repo/security/authentication/ntlm/NTLMAuthenticationComponentImpl.java @@ -507,7 +507,7 @@ public class NTLMAuthenticationComponentImpl extends AbstractAuthenticationCompo * @param password char[] * @throws AuthenticationException */ - public void authenticate(String userName, char[] password) throws AuthenticationException + protected void authenticateImpl(String userName, char[] password) throws AuthenticationException { // Debug