exfex-cvs-commit Mailing List for Extended Form of examination (Page 2)
Status: Planning
Brought to you by:
mstsxfx
You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(93) |
Oct
(134) |
Nov
(29) |
Dec
(14) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(20) |
Feb
(1) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(15) |
Nov
|
Dec
|
From: Michal H. <ms...@us...> - 2006-01-19 19:21:15
|
Update of /cvsroot/exfex/exfex/tests/source/exfex/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21068/tests/source/exfex/editor Added Files: AllTests.java Log Message: testsuite classes for packages --- NEW FILE: AllTests.java --- package exfex.editor; import junit.framework.Test; import junit.framework.TestSuite; /** * @author msts * */ @SuppressWarnings("all") public class AllTests { public static Test suite() { TestSuite suite = new TestSuite("Test for exfex.common"); //$JUnit-BEGIN$ // place suite.add for each direct subpackage AllTests //$JUnit-END$ return suite; } } |
From: Michal H. <ms...@us...> - 2006-01-19 19:21:14
|
Update of /cvsroot/exfex/exfex/tests/source/exfex/program In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21068/tests/source/exfex/program Added Files: AllTests.java Log Message: testsuite classes for packages --- NEW FILE: AllTests.java --- package exfex.program; import junit.framework.Test; import junit.framework.TestSuite; /** * @author bossek * */ @SuppressWarnings("all") public class AllTests { public static Test suite() { TestSuite suite = new TestSuite("Test for exfex.common"); //$JUnit-BEGIN$ // place suite.add for each direct subpackage AllTests //$JUnit-END$ return suite; } } |
From: Michal H. <ms...@us...> - 2006-01-19 19:21:08
|
Update of /cvsroot/exfex/exfex/tests/source/exfex/common/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20983/tests/source/exfex/common/utils Log Message: Directory /cvsroot/exfex/exfex/tests/source/exfex/common/utils added to the repository |
From: Michal H. <ms...@us...> - 2006-01-19 19:21:05
|
Update of /cvsroot/exfex/exfex/tests/source/exfex/program In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20983/tests/source/exfex/program Log Message: Directory /cvsroot/exfex/exfex/tests/source/exfex/program added to the repository |
From: Michal H. <ms...@us...> - 2006-01-19 19:21:05
|
Update of /cvsroot/exfex/exfex/tests/source/exfex/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20983/tests/source/exfex/editor Log Message: Directory /cvsroot/exfex/exfex/tests/source/exfex/editor added to the repository |
From: Michal H. <ms...@us...> - 2006-01-02 21:26:21
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7809/source/exfex/common/plugins/security Modified Files: StandardDomain.java Log Message: member list initialization and import/export Index: StandardDomain.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/plugins/security/StandardDomain.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** StandardDomain.java 2 Jan 2006 17:37:07 -0000 1.3 --- StandardDomain.java 2 Jan 2006 21:26:13 -0000 1.4 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.4 2006/01/02 21:26:13 mstsxfx + * member list initialization and import/export + * * Revision 1.3 2006/01/02 17:37:07 mstsxfx * new methods export,import members *************** *** 16,19 **** --- 19,23 ---- package exfex.common.plugins.security; + import java.util.LinkedList; import java.util.List; *************** *** 45,49 **** /** Members of domain. */ ! private List<Integer> members; /** Direct subdomains. */ --- 49,53 ---- /** Members of domain. */ ! private List<Integer> members=new LinkedList<Integer>(); /** Direct subdomains. */ |
From: Michal H. <ms...@us...> - 2006-01-02 17:37:18
|
Update of /cvsroot/exfex/exfex/source/exfex/common/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12717/source/exfex/common/security Modified Files: IDomain.java Log Message: new methods export,import members Index: IDomain.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/IDomain.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** IDomain.java 28 Dec 2005 18:49:02 -0000 1.2 --- IDomain.java 2 Jan 2006 17:37:07 -0000 1.3 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.3 2006/01/02 17:37:07 mstsxfx + * new methods export,import members + * * Revision 1.2 2005/12/28 18:49:02 mstsxfx * sync with SecurityContext *************** *** 12,15 **** --- 15,20 ---- package exfex.common.security; + import java.util.List; + /** Interface for domain. * *************** *** 61,64 **** --- 66,92 ---- public Integer[] getMembers(); + /** Exports members to the world. + * + * This method should be called if external handling is needed for domain. Caller has + * to realize that changes made to the returned list take effect to members known to the + * domain. + * + * @return List containing all members or null if not supported. + */ + public List<Integer> exportMembers(); + + /** Imports members. + * + * This method will set new members list from given one. It is implementation specific if + * original users are forgotten or not. + * <br> + * Holder of the list can control this list (this means that caller can create list instance + * and then use it to manipulate with members (add, remove, ...) ). + * + * @param members Members list. Must be non null. + * @return true if successfully set or false otherwise. + */ + public boolean importMembers(List<Integer> members); + /** Adds new member. * Sets member specific security context. Authorization evaluator should |
From: Michal H. <ms...@us...> - 2006-01-02 17:37:15
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12717/source/exfex/common/plugins/security Modified Files: StandardDomain.java Log Message: new methods export,import members Index: StandardDomain.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/plugins/security/StandardDomain.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** StandardDomain.java 29 Dec 2005 16:16:00 -0000 1.2 --- StandardDomain.java 2 Jan 2006 17:37:07 -0000 1.3 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.3 2006/01/02 17:37:07 mstsxfx + * new methods export,import members + * * Revision 1.2 2005/12/29 16:16:00 mstsxfx * doc update *************** *** 190,193 **** --- 193,225 ---- } + /** Returns members list. + * + * Returned list is reference to the internal members list, so changes to the list takes + * effect to the internal members. + * + */ + public List<Integer> exportMembers() + { + return members; + } + + /** Imports members. + * + * NOTE that this method will forget all previous members. + * <br> + * Given parameter is used to set <code>members</code> field and so changes to given list + * takes effect to the internal members. + * @return true if members is not null, false otherwise. + */ + public boolean importMembers(List<Integer> members) + { + if(members==null) + return false; + + this.members=members; + return true; + } + + /** Equals method. * |
From: Michal H. <ms...@us...> - 2006-01-02 17:04:44
|
Update of /cvsroot/exfex/exfex/source/exfex/common/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5753/source/exfex/common/utils Modified Files: IdAssigner.java Log Message: release - try to decrease top value Index: IdAssigner.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/utils/IdAssigner.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IdAssigner.java 27 Nov 2005 13:10:01 -0000 1.1 --- IdAssigner.java 2 Jan 2006 17:04:32 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2006/01/02 17:04:32 mstsxfx + * release - try to decrease top value + * * Revision 1.1 2005/11/27 13:10:01 mstsxfx * new helper classes *************** *** 22,25 **** --- 25,29 ---- * <pre> * Changes: + * 2.1.2006 msts - relese try to decrese top if possible * 28.10.2005 msts - created * </pre> *************** *** 68,74 **** /** Releases given id. * ! * Prepares id for reuse. We want to reuse the oldest released ids, so ! * id is inserted to the end of the <code>releaseList</code> list. ! * TODO we could decrease top value if it can be done. * * @param id Id to release. --- 72,80 ---- /** Releases given id. * ! * Prepares id for reuse. ! * <br> ! * If id is <code>top - 1</code> value, decrease top value. Otherwise inserts id to the ! * <code>releaseList</code> to the last position (so lastly released ids are returned later ! * than previous). * * @param id Id to release. *************** *** 77,80 **** --- 83,93 ---- public void release(Integer id) { + // try to decrease top at first (only if top is not maximal) + if(top!=Integer.MAX_VALUE && (id.intValue()+1==top.intValue())) + { + top=id; + return; + } + // inserts id to the end of the releaseList releaseList.add(releaseList.size(),id); |
From: Michal H. <ms...@us...> - 2006-01-02 16:49:21
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2142/source/exfex/common/plugins/security Modified Files: StandardSecurityDataFactory.java Log Message: doc update Index: StandardSecurityDataFactory.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/plugins/security/StandardSecurityDataFactory.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StandardSecurityDataFactory.java 28 Dec 2005 18:48:01 -0000 1.1 --- StandardSecurityDataFactory.java 2 Jan 2006 16:49:12 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2006/01/02 16:49:12 mstsxfx + * doc update + * * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) *************** *** 12,21 **** import exfex.common.pluginsystem.IAcceptPlugin; import exfex.common.pluginsystem.IContext; import exfex.common.pluginsystem.PluginManager; import exfex.common.security.ISecurityData; import exfex.common.security.ISecurityDataFactory; ! /** * * <p> * <pre> --- 15,36 ---- import exfex.common.pluginsystem.IAcceptPlugin; import exfex.common.pluginsystem.IContext; + import exfex.common.pluginsystem.IPluginPolicy; + import exfex.common.pluginsystem.IPluginStrategy; import exfex.common.pluginsystem.PluginManager; import exfex.common.security.ISecurityData; import exfex.common.security.ISecurityDataFactory; ! /** Factory to produce StandardSecurityData instances. * + * <br><b>Plugin Name</b>: "StandardSecurityData" + * <br><b>Depends</b>: no dependencies + * <br><b>Special notes</b>: + * <ul> + * <li>Returned object is {@link exfex.common.plugins.security.StandardSecurityData} instance (new + * after each {@link #getSecurityDataInstance()} call. + * <li>Registers itself to the PluginManager. + * <li>Needs StandardSecurityData class file in appropriate directory to be enable class loader to + * find it. + * </ul> * <p> * <pre> *************** *** 25,28 **** --- 40,48 ---- * @author msts */ + @IPluginPolicy( replaceStrategy = IPluginStrategy.Type.ATLEAST, + version = 1, + author = "msts", + description = "Plugin to produce Standard implementation of SecurityData class. " + + "This implementation doesn't provide any persistancy model.") public class StandardSecurityDataFactory extends AbstractPlugin implements ISecurityDataFactory *************** *** 42,48 **** * Calls supertype constructor with plugin name parameter. */ ! StandardSecurityDataFactory() { ! super(name); } --- 62,68 ---- * Calls supertype constructor with plugin name parameter. */ ! public StandardSecurityDataFactory() { ! super(name,manager); } |
From: Michal H. <ms...@us...> - 2006-01-02 16:49:05
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2096/source/exfex/common/plugins/security Modified Files: PasswordAuthVerifier.java Log Message: note for implementation request Index: PasswordAuthVerifier.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/plugins/security/PasswordAuthVerifier.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PasswordAuthVerifier.java 27 Nov 2005 13:06:32 -0000 1.1 --- PasswordAuthVerifier.java 2 Jan 2006 16:48:53 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2006/01/02 16:48:53 mstsxfx + * note for implementation request + * * Revision 1.1 2005/11/27 13:06:32 mstsxfx * password authentication plugins *************** *** 33,36 **** --- 36,41 ---- * <p> * <pre> + * TODO original data obtaining + * * Changes: * 24.11.2005 msts - created *************** *** 283,287 **** * to the {@link PasswordAuthBean} type. * ! * @throws BeanFormatException if bean's check method throws this * exception which means that it doesn't contain all necessary * information. --- 288,292 ---- * to the {@link PasswordAuthBean} type. * ! * @throws UnsupportedAuthTypeException if bean's check method throws this * exception which means that it doesn't contain all necessary * information. *************** *** 336,339 **** --- 341,345 ---- } + // TODO remove protected PasswordAuthBean test() { |
From: Michal H. <ms...@us...> - 2005-12-29 17:55:07
|
Update of /cvsroot/exfex/exfex/source/exfex/common/pluginsystem In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18857/source/exfex/common/pluginsystem Modified Files: AbstractPlugin.java Log Message: new constructor + doc update Index: AbstractPlugin.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/pluginsystem/AbstractPlugin.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** AbstractPlugin.java 1 Nov 2005 20:16:02 -0000 1.2 --- AbstractPlugin.java 29 Dec 2005 17:54:53 -0000 1.3 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.3 2005/12/29 17:54:53 mstsxfx + * new constructor + doc update + * * Revision 1.2 2005/11/01 20:16:02 mstsxfx * String code cleanup (doesn't use new String construction) *************** *** 48,52 **** * <li>If the manager is static in the system (e.g. PluginManager, LogManager * etc.) instance of the manager is known in time when constructor is called, so ! * it be set immediately after super is called: * <pre> * private PluginManager manager=PluginManager.getInstance(); --- 51,55 ---- * <li>If the manager is static in the system (e.g. PluginManager, LogManager * etc.) instance of the manager is known in time when constructor is called, so ! * it be set in constructor: * <pre> * private PluginManager manager=PluginManager.getInstance(); *************** *** 54,59 **** * public FooPlugin() * { ! * super("PluginName"); ! * setManager(manager); * } * </pre> --- 57,61 ---- * public FooPlugin() * { ! * super("PluginName", manager); * } * </pre> *************** *** 93,97 **** /** Initializating constructor. * ! * Sets plugin name. * @param name Plugin Name. */ --- 95,99 ---- /** Initializating constructor. * ! * Sets plugin name. This constructor should be used if manager is dependency. * @param name Plugin Name. */ *************** *** 101,104 **** --- 103,118 ---- } + /** Initializing constructor. + * + * Sets name and manager. This constructor should be used if manager is not dependency + * and its instance is known in Plugin constructor. + * @param name Plugin name. + * @param manager Manager instance. + */ + public AbstractPlugin(String name, IAcceptPlugin manager) + { + this.name=name; + this.manager=manager; + } /** Default implementation of dependencyNotify method. |
From: Michal H. <ms...@us...> - 2005-12-29 16:16:45
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28900/source/exfex/common/plugins/security Modified Files: StandardResource.java Log Message: doc update hashCode, equals, toString implemented Index: StandardResource.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/plugins/security/StandardResource.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StandardResource.java 28 Dec 2005 18:48:01 -0000 1.1 --- StandardResource.java 29 Dec 2005 16:16:32 -0000 1.2 *************** *** 3,6 **** --- 3,10 ---- * * $Log$ + * Revision 1.2 2005/12/29 16:16:32 mstsxfx + * doc update + * hashCode, equals, toString implemented + * * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) *************** *** 13,17 **** /** Standard implementation of resource. ! * TODO doc * <p> * <pre> --- 17,21 ---- /** Standard implementation of resource. ! * * <p> * <pre> *************** *** 33,36 **** --- 37,46 ---- } + /** Initializating constructor. + * + * @param name Name of the resource. Must be non null. + * @param res Object representing resource. + * @throws ResourceException If instance can't be initializated (name is null) + */ public StandardResource(String name, Object res) throws ResourceException *************** *** 64,66 **** --- 74,111 ---- } + /** Equals method. + * + * Given object equals to this instance iff: + * <ul> + * <li>o is not null + * <li>o is StandardResource type instance + * <li>o has same name as this instance + * </ul> + */ + @Override public boolean equals(Object o) + { + if(!(o instanceof StandardResource)) + return false; + + StandardResource ro=(StandardResource)o; + + // compares names + if(!name.equals(ro.getName())) + return false; + + // everything ok + return true; + } + + @Override public String toString() + { + return "StandardResource[name=\""+name+"\"]"; + } + + @Override public int hashCode() + { + int result=19; + result=37*result+name.hashCode(); + return result; + } } |
From: Michal H. <ms...@us...> - 2005-12-29 16:16:10
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28784/source/exfex/common/plugins/security Modified Files: StandardDomain.java Log Message: doc update equals, hashCode, toString implemented Index: StandardDomain.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/plugins/security/StandardDomain.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StandardDomain.java 28 Dec 2005 18:48:01 -0000 1.1 --- StandardDomain.java 29 Dec 2005 16:16:00 -0000 1.2 *************** *** 3,6 **** --- 3,10 ---- * * $Log$ + * Revision 1.2 2005/12/29 16:16:00 mstsxfx + * doc update + * equals, hashCode, toString implemented + * * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) *************** *** 16,20 **** /** Standard implementation of domain. * ! * TODO doc * <p> * <pre> --- 20,27 ---- /** Standard implementation of domain. * ! * This implementation brings basic functionality. Context is supported just for domains and ! * not also for members. ! * ! * * <p> * <pre> *************** *** 27,34 **** { /** Domain name. */ ! private String name; private StandardDomain() { } --- 34,42 ---- { /** Domain name. */ ! private final String name; private StandardDomain() { + name=null; } *************** *** 182,184 **** --- 190,228 ---- } + /** Equals method. + * + * Examines if given object equals to this instance. GIven object equals iff, + * <ul> + * <li>o is not null + * <li>o is StandardDomain type instance + * <li>name of o is same as this name + * <li>TODO children comparing (is it needed) + * </ul> + */ + @Override public boolean equals(Object o) + { + if(!(o instanceof StandardDomain)) + return false; + + StandardDomain sdo=(StandardDomain)o; + + // names must be same + if(!name.equals(sdo.getName())) + return false; + + // everything ok + return true; + } + + @Override public String toString() + { + return "StandardDomain[name=\""+name+"\"]"; + } + + @Override public int hashCode() + { + int result=19; + result=37*result+name.hashCode(); + return result; + } } |
From: Michal H. <ms...@us...> - 2005-12-29 16:15:29
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28660/source/exfex/common/plugins/security Modified Files: StandardSecurityData.java Log Message: doc update Index: StandardSecurityData.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/plugins/security/StandardSecurityData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StandardSecurityData.java 28 Dec 2005 18:48:01 -0000 1.1 --- StandardSecurityData.java 29 Dec 2005 16:15:19 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2005/12/29 16:15:19 mstsxfx + * doc update + * * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) *************** *** 24,28 **** /** Standard implementation of security data class. * ! * TODO doc * <p> * <pre> --- 27,38 ---- /** Standard implementation of security data class. * ! * This instance is product of {@link exfex.common.plugins.security.StandardSecurityDataFactory} ! * plugin. It doesn't provide any persistancy and so can be used only there where data ! * reconstruction after system (program) failure is needed. ! * <br> ! * Factory methods for domain resp. resource creation provides ! * {@link exfex.common.plugins.security.StandardDomain} resp. ! * {@link exfex.common.plugins.security.StandardResource} instances. ! * * <p> * <pre> *************** *** 39,45 **** private long magicNumber=666L; - /** Container of all registered resources. */ - private List<IResource> res=new LinkedList<IResource>(); - /** Relation mapping. * Keys are resources (each resource maximaly once) and list of associated domains. --- 49,52 ---- *************** *** 103,113 **** associated=mapping.get(resource); ! // puts domain to the associated list and put pair to the mapping ! mapping.put(resource, associated); } /** Creates new Standard domain instance. * ! * @return Standard domain instance. */ public IDomain createDomain(String name) throws DomainException --- 110,125 ---- associated=mapping.get(resource); ! // puts domain to the associated list (only if not presented yet) and put the ! // pair to the mapping ! if(!associated.contains(dom)) ! { ! associated.add(dom); ! mapping.put(resource, associated); ! } } /** Creates new Standard domain instance. * ! * @return {@link StandardDomain} instance. */ public IDomain createDomain(String name) throws DomainException *************** *** 173,181 **** if(!associated.remove(dom)) throw new DomainException(dom.getName()+" is not associated"); } /** Creates Standard resource instance. * ! * @return StandardResource instance. */ public IResource createResource(Object object, String name) --- 185,195 ---- if(!associated.remove(dom)) throw new DomainException(dom.getName()+" is not associated"); + + // resources with no domains are kept } /** Creates Standard resource instance. * ! * @return {@link StandardResource} instance. */ public IResource createResource(Object object, String name) *************** *** 185,189 **** } ! /** Removes resource and forget all associations. */ public void removeResource(IResource resource) throws ResourceException --- 199,203 ---- } ! /** Removes resource and forgets all associations. */ public void removeResource(IResource resource) throws ResourceException *************** *** 232,235 **** throw new ResourceException(name+" not found"); } - } --- 246,248 ---- |
From: Michal H. <ms...@us...> - 2005-12-29 16:13:35
|
Update of /cvsroot/exfex/exfex/source/exfex/common/utils/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28347/source/exfex/common/utils/security Modified Files: PublicSecretSecurityDataAdapter.java Log Message: secret key is stored to the name.secretKey.resourceName.domName Index: PublicSecretSecurityDataAdapter.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/utils/security/PublicSecretSecurityDataAdapter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PublicSecretSecurityDataAdapter.java 28 Dec 2005 18:49:32 -0000 1.1 --- PublicSecretSecurityDataAdapter.java 29 Dec 2005 16:13:27 -0000 1.2 *************** *** 3,6 **** --- 3,10 ---- * * $Log$ + * Revision 1.2 2005/12/29 16:13:27 mstsxfx + * secret key is stored to the + * name.secretKey.resourceName.domName + * * Revision 1.1 2005/12/28 18:49:32 mstsxfx * Adapters for securityData *************** *** 136,140 **** * domains). * @param dataStorage Instance of security data. Must be non null. - * TODO should be rather factory class as parameter * @param instanceName Name of this instance. It should be unique among other * instances to prevent problems. Must be non null --- 140,143 ---- *************** *** 318,322 **** * Sets secret key to the user profile as: * <pre> ! * name.secretKey.READ * </pre> * named value (where name is instance name field value). --- 321,325 ---- * Sets secret key to the user profile as: * <pre> ! * name.secretKey.resourceName.READ * </pre> * named value (where name is instance name field value). *************** *** 372,376 **** * Sets secret key to the user profile as: * <pre> ! * name.secretKey.WRITE * </pre> * named value (where name is instance name field value). --- 375,379 ---- * Sets secret key to the user profile as: * <pre> ! * name.secretKey.resourceName.WRITE * </pre> * named value (where name is instance name field value). *************** *** 426,430 **** * Sets secret key to the user profile as: * <pre> ! * name.secretKey.CONTROL * </pre> * named value (where name is instance name field value). --- 429,433 ---- * Sets secret key to the user profile as: * <pre> ! * name.secretKey.resourceName.CONTROL * </pre> * named value (where name is instance name field value). *************** *** 561,565 **** * as * <pre> ! * name.secretKey.domName * </pre> * named value (where name is instance name field value and domName is --- 564,568 ---- * as * <pre> ! * name.secretKey.resourceName.domName * </pre> * named value (where name is instance name field value and domName is *************** *** 587,591 **** byte [] key=getSecretKey(resourceName, domName); ! userProfile.setProfileInfo(name+".secretKey."+domName,key); }catch (DomainException e) { // shouldn't happen - bug --- 590,594 ---- byte [] key=getSecretKey(resourceName, domName); ! userProfile.setProfileInfo(name+".secretKey."+resourceName+"."+domName,key); }catch (DomainException e) { // shouldn't happen - bug *************** *** 602,609 **** * * Gets secret key stored in the given user profile (value with name ! * <pre>name.secretKey.domName</pre> where name stands for this instance ! * name field and domName is given paramter) and compare it with secret ! * key from domain with given domName associated with resource with ! * given resourceName. * <br> * This method doesn't need no external synchronization because it uses --- 605,612 ---- * * Gets secret key stored in the given user profile (value with name ! * <pre>name.secretKey.resourceName.domName</pre> where name stands for this instance ! * name field, resourceName is name of the associating resource and domName is given ! * paramter) and compare it with secret key from domain with given domName associated with ! * resource with given resourceName. * <br> * This method doesn't need no external synchronization because it uses *************** *** 629,633 **** // gets key from user profile ! byte userKey[]=(byte[])userProfile.getProfileInfo(name+".secretKey."+domName); // gets secret key from resource's READ domain --- 632,636 ---- // gets key from user profile ! byte userKey[]=(byte[])userProfile.getProfileInfo(name+".secretKey."+resourceName+"."+domName); // gets secret key from resource's READ domain |
From: Michal H. <ms...@us...> - 2005-12-28 18:49:42
|
Update of /cvsroot/exfex/exfex/source/exfex/common/utils/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4017/source/exfex/common/utils/security Added Files: UnixSecurityDataAdapter.java PublicSecretSecurityDataAdapter.java Log Message: Adapters for securityData --- NEW FILE: PublicSecretSecurityDataAdapter.java --- /** * $RCSfile: PublicSecretSecurityDataAdapter.java,v $ * * $Log: PublicSecretSecurityDataAdapter.java,v $ * Revision 1.1 2005/12/28 18:49:32 mstsxfx * Adapters for securityData * */ package exfex.common.utils.security; import java.math.BigInteger; import java.util.Random; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; import exfex.common.security.DomainException; import exfex.common.security.IDomain; import exfex.common.security.IResource; import exfex.common.security.ISecurityData; import exfex.common.security.User; import exfex.common.security.ResourceException; import exfex.common.security.SecurityContext; import exfex.common.security.SecurityContextException; /** Adapter for ISecurityData for public secret permission handling. * * <h3>Overview</h3> * This class adaptes ISecurityData instance (which is supplied in constructor). * All calls to this class performes logic upon security data storage. TODO * * <h3>Principes</h3> * Each resource (entity that has to be protected by security system) is * associated with 3 domains: * <ul> * <li>with <b>READ</b> name * <li>with <b>WRITE</b> name * <li>with <b>CONTROL</b> name * </ul> * * These domains are not intended to keep any members. Only relevant information * is security context. This has one key-value pair with key name * <b>SECRET_KEY</b> which is associated with byte array value. Everybody who * knows this value is granted for permision for domain. This implementation * doesn't provide any persistancy because of security so when instance is * destroyed all secret keys are forgotten. * <br> * Creation of the private key value is in power of this class (as well as key * lenght). * * <h3>Usage</h3> * Instance of class can be made only using constructor with non null * {@link exfex.common.security.ISecurityData} instance. Implementation is not * important. Each instance is also associated with name to recognise them. Name * is also set in constructor. * <br> * User of this class can ask for and set permission by 3 pairs of methods: * <ul> * <li>{@link #canRead(String, User)} and {@link #setRead(String, User)} * <li>{@link #canWrite(String, User)} and {@link #setWrite(String, User)} * <li>{@link #canControl(String, User)} and {@link #setControl(String, User)} * </ul> * * Resources are manipulated strictly by names, because IResource instance could * lead to the information leak or internal damage. To manipulate with * resources, use following methods: * <ul> * <li>{@link #getResourceNames()}, {@link #getResourceObject(String)} for * information abour resources. * <li>{@link #registerResource(String, Object)}, {@link #removeResource(String)} * for adding resp. removing resources. * </ul> * * Instance will set key to the user profile using * {@link exfex.common.security.User#setProfileInfo(String, Object)} method * when someone asks for certain permission. Same profile info from * {@link exfex.common.security.User#getProfileInfo(String)} is compared when * examining permission. User instance is responsible not to tell this * information. * * <h3>Synchronization</h3> * Each instance uses Read-Write locks for synchronization, so it can be used in * multi-threaded environment. Locking is optimized for many readers. * <p> * <pre> * Changes: * 9.12.2005 msts - created * </pre> * * @author miso */ public class PublicSecretSecurityDataAdapter { /** Security data instance. * * This instance is used for resource and domain handling. */ private ISecurityData storage; /** Name of this instance. * The name is used to distinguis different instances of this class * in user profiles. */ private String name; /** Read-Write lock for synchronization. */ private ReentrantReadWriteLock rwLock=new ReentrantReadWriteLock(); /** Read lock. * This lock is used in methods which doesn't provide any internal * changes. */ private ReadLock rLock=rwLock.readLock(); /** Write lock. * This lock is used in all methods which provide changes to internals. */ private WriteLock wLock=rwLock.writeLock(); /** Generator used for secret key generation. * */ private Random generator=new Random(System.nanoTime()); /** Empty constructor. * This constructor is disabled because we don't want instance without * ISecurityData instance. */ private PublicSecretSecurityDataAdapter() { } /** Initializating constructor. * * Cleans up given data storage instance (destroy all resources and * domains). * @param dataStorage Instance of security data. Must be non null. * TODO should be rather factory class as parameter * @param instanceName Name of this instance. It should be unique among other * instances to prevent problems. Must be non null * @throws NullPointerException If given dataStorage or name is null. */ public PublicSecretSecurityDataAdapter(ISecurityData dataStorage, String instanceName) throws NullPointerException { // storage check if(dataStorage==null) throw new NullPointerException("dataStorage is null"); if(instanceName==null) throw new NullPointerException("name is null"); storage=dataStorage; name=instanceName; } // Resource manipulation methods //=============================== /** Returns names of all available resources. * * Name returned from this method won't fail in * {@link #getResourceObject(String)} method object if no changes are * made meanwhile. * @return array of resources names. */ public String [] getResourceNames() { try { // ontains lock rLock.lock(); IResource resources[]=storage.getResources(); String names []=new String[resources.length]; // gets just names from IResources int i=0; for(IResource r: resources) names[i++]=r.getName(); return names; }finally { // release lock rLock.unlock(); } } /** Returns object associated with resource. * * @param name Name of the resource. * @return Object instance which is part of resource. This may be null. * @throws ResourceException If resource with given name is not * registered. */ public Object getResourceObject(String name) throws ResourceException { try { // obtains lock rLock.lock(); // if not found, exception is thrown IResource res=storage.getResourceByName(name); return res.getName(); }finally { // releases lock rLock.unlock(); } } /** Registers new resource. * * Examines if resource with given name is already registered and if so * throws an exception. Creates domains, generates key for each and * associates it with the resource. * * @param name Resource name. Must be non null. * @param object Object associated with resource. May be null. * @throws ResourceException If unable to create or register resource. */ public void registerResource(String name, Object object) throws ResourceException { try { // accuires write lock wLock.lock(); // check if resource with given name is already // registered and throws exception if so if(storage.knowsResourceByName(name)) throw new ResourceException(name+" already registered"); // creates resource instance, 3 domains and secret // key for each IResource res=storage.createResource(object,name); IDomain readDom=storage.createDomain("READ"); setSecretKey(readDom); IDomain writeDom=storage.createDomain("WRITE"); setSecretKey(writeDom); IDomain controlDom=storage.createDomain("CONTROL"); setSecretKey(controlDom); // everything ok, so we can associate storage.associateDomain(res, readDom); storage.associateDomain(res, writeDom); storage.associateDomain(res, controlDom); }catch(DomainException e) { // creation domain error or context error // we don't want to show this to user, so // ResourceException is thrown instead and domain // exception is set as cause throw new ResourceException("Resource registration problem",e); } finally { // releases write lock wLock.unlock(); } } /** Removes resource. * * Forget all domains and keys. * @param name Resource name. * @throws ResourceException if resource with given name is not * registered. */ public void removeResource(String name)throws ResourceException { try { // accuires write lock wLock.lock(); storage.removeResource(storage.getResourceByName(name)); }finally { // releases write lock wLock.unlock(); } } // Permission methods //==================== /** Checks if given user can read on given resource * * Gets key stored on user profile and compares it with secret key in * resource's READ domain. * * @see #checkUserProfile(String, User, String) for implementation * details (uses READ as last parameter). * @param resourceName Name of the resource. Must be non null. * @param userProfile User that should be examined. Must be non null. * @return true if both keys are same, false otherwise. * @throws ResourceException if resource with given name is not * registered. */ public boolean canRead(String resourceName, User userProfile) throws ResourceException { // null values are not valid, so returns with false if(resourceName==null || userProfile==null) return false; // uses helper method for all the work return checkUserProfile(resourceName, userProfile, "READ"); } /** Sets user information to be able read on given resource. * * Sets secret key to the user profile as: * <pre> * name.secretKey.READ * </pre> * named value (where name is instance name field value). * NOTE that this method doesn't check wheather there is such such * key, value binding in the profile. * <br> * Next call (unless key is changed) of {@link #canRead(String, User)} * will return true. * * @see #setUserProfile(String, User, String) for implementation * details (uses READ string as last parameter). * @param resourceName Name of the resource. Must be non null. * @param userProfile User profile. Must be non null. * @throws ResourceException If given resource is not registered. */ public void setRead(String resourceName, User userProfile) throws ResourceException { // null values are not valid, so returns with false if(resourceName==null || userProfile==null) return ; // uses helper method to perform all operations setUserProfile(resourceName,userProfile,"READ"); } /** Checks if given user can write on given resource * * Gets key stored on user profile and compares it with secret key in * resource's WRITE domain. * * @see #checkUserProfile(String, User, String) for implementation * details (uses WRITE as last parameter). * @param resourceName Name of the resource. Must be non null. * @param userProfile User that should be examined. Must be non null. * @return true if both keys are same, false otherwise. * @throws ResourceException if resource with given name is not * registered. */ public boolean canWrite(String resourceName, User userProfile) throws ResourceException { // null values are not valid, so returns with false if(resourceName==null || userProfile==null) return false; // uses helper method for all the work return checkUserProfile(resourceName, userProfile, "WRITE"); } /** Sets user information to be able write on given resource. * * Sets secret key to the user profile as: * <pre> * name.secretKey.WRITE * </pre> * named value (where name is instance name field value). * NOTE that this method doesn't check wheather there is such such * key, value binding in the profile. * <br> * Next call (unless key is changed) of {@link #canWrite(String, User)} * will return true. * * @see #setUserProfile(String, User, String) for implementation * details (uses WRITE string as last parameter). * @param resourceName Name of the resource. Must be non null. * @param userProfile User profile. Must be non null. * @throws ResourceException If given resource is not registered. */ public void setWrite(String resourceName, User userProfile) throws ResourceException { // null values are not valid, so returns with false if(resourceName==null || userProfile==null) return ; // uses helper method to perform all operations setUserProfile(resourceName,userProfile,"WRITE"); } /** Checks if given user can control given resource * * Gets key stored on user profile and compares it with secret key in * resource's CONTROL domain. * * @see #checkUserProfile(String, User, String) for implementation * details (uses CONTROL as last parameter). * @param resourceName Name of the resource. Must be non null. * @param userProfile User that should be examined. Must be non null. * @return true if both keys are same, false otherwise. * @throws ResourceException if resource with given name is not * registered. */ public boolean canControl(String resourceName, User userProfile) throws ResourceException { // null values are not valid, so returns with false if(resourceName==null || userProfile==null) return false; // uses helper method for all the work return checkUserProfile(resourceName, userProfile, "CONTROL"); } /** Sets user information to be able control given resource. * * Sets secret key to the user profile as: * <pre> * name.secretKey.CONTROL * </pre> * named value (where name is instance name field value). * NOTE that this method doesn't check wheather there is such such * key, value binding in the profile. * <br> * Next call (unless key is changed) of {@link #canControl(String, User)} * will return true. * * @see #setUserProfile(String, User, String) for implementation * details (uses CONTROL string as last parameter). * @param resourceName Name of the resource. Must be non null. * @param userProfile User profile. Must be non null. * @throws ResourceException If given resource is not registered. */ public void setControl(String resourceName, User userProfile) throws ResourceException { // null values are not valid, so returns with false if(resourceName==null || userProfile==null) return ; // uses helper method to perform all operations setUserProfile(resourceName,userProfile,"CONTROL"); } // Secret key handling //===================== /** Generates secret key and sets it to the domain. * * @param dom Domain instance. * @throws DomainException if unable to set value to the security * context. * @return Secret key set to the domain. */ private byte[] setSecretKey(IDomain dom)throws DomainException { // generates random number and uses it to define secret key. BigInteger rndNumner=new BigInteger(1024,generator); byte key [] = rndNumner.toByteArray(); // sets the value to the domain. SecurityContext context=new SecurityContext(); context.add("SECRET_KEY",key); try { dom.setSecurityContext(context); return key; }catch(SecurityContextException e) { // we are not able to set security context // throws Domain exception with security context // exception as a cause throw new DomainException("Unable to set SECRET_KEY",e); } } /** Returns secret key. * * @param resourceName Name of the resource. * @param domainName Name of the domain. * @return Byte array used as secret key or null if there is no defined. * @throws ResourceException if given resource is not registered. */ private byte [] getSecretKey(String resourceName, String domainName) throws ResourceException, DomainException { // gets resource and domain according names IResource res=storage.getResourceByName(resourceName); try { IDomain dom=storage.getDomainByName(res, domainName); // gets security context and value of secret key, which // is stored inside SecurityContext context=dom.getSecurityContext(); return context.get("SECRET_KEY",byte[].class); }catch(DomainException e) { // this shouldn't happen and if happens, then it is bug } catch(SecurityContextException e) { // this shouldn't happen and if happens, then it is bug } return null; } /** Compares two keys. * * Two keys are same if they are both null, or * <ul> * <li>have same length * <li>bytes on matching positions are same. * </ul> * * @param key1 Key array. * @param key2 Key array. * @return if both keys are same false otherwise. */ private boolean compareKeys(byte [] key1, byte[] key2) { // both are null is ok if(key1==null) return (key2==null); // key2 can't be null, becase key1 is not null if(key2==null) return false; // both arrays must have same length if(key1.length!=key2.length) return false; for(int i=0;i<key1.length;i++) // bytes on same positions must be same if(key1[i]!=key2[i]) return false; // everything is ok return true; } // HELPER METHODS // =============== /** User profile setter. * * Try to get resource according name and if exists, use its domName * domain to get secret key which uses to sets to the given userProfile * as * <pre> * name.secretKey.domName * </pre> * named value (where name is instance name field value and domName is * given parameter). * <br> * This method doesn't perform any parameters checking, so this has to * be done by its caller. * <br> * No external synchronization is needed, because this method uses * write lock. * * @param resourceName Name of the resource. * @param userProfile User profile instance. * @param domName Domain name. (name of the access permission) * @throws ResourceException if no resource with given name is * registered. */ private void setUserProfile(String resourceName, User userProfile, String domName) throws ResourceException { try { // accuires write lock wLock.lock(); byte [] key=getSecretKey(resourceName, domName); userProfile.setProfileInfo(name+".secretKey."+domName,key); }catch (DomainException e) { // shouldn't happen - bug // TODO handle } finally { // releases write lock wLock.unlock(); } } /** Checks user profile wheather it contains correct secret key. * * Gets secret key stored in the given user profile (value with name * <pre>name.secretKey.domName</pre> where name stands for this instance * name field and domName is given paramter) and compare it with secret * key from domain with given domName associated with resource with * given resourceName. * <br> * This method doesn't need no external synchronization because it uses * write lock. * * @see #getSecretKey(String, String) * @see #compareKeys(byte[], byte[]) * @param resourceName Name of the resource. * @param userProfile User profile instance. * @param domName Name of the domain. (name of the access permission) * @return true if user profile contains correct secret key, otherwise * returns false. * @throws ResourceException If resource with given name is not * registered. */ private boolean checkUserProfile(String resourceName, User userProfile, String domName) throws ResourceException { try { // accuires read lock rLock.lock(); // gets key from user profile byte userKey[]=(byte[])userProfile.getProfileInfo(name+".secretKey."+domName); // gets secret key from resource's READ domain byte secretKey[]=getSecretKey(resourceName,domName); // compares keys return compareKeys(userKey, secretKey); }catch(Exception e) { // problem with resource or profile info return false; }finally { // releases read lock rLock.unlock(); } } } --- NEW FILE: UnixSecurityDataAdapter.java --- /** * $RCSfile: UnixSecurityDataAdapter.java,v $ * * $Log: UnixSecurityDataAdapter.java,v $ * Revision 1.1 2005/12/28 18:49:32 mstsxfx * Adapters for securityData * */ package exfex.common.utils.security; /** Adapter for ISecurityData for Unix permision handling * * <p> * <pre> * Changes: * 9.12.2005 msts - created * </pre> * * @author miso */ public class UnixSecurityDataAdapter { } |
From: Michal H. <ms...@us...> - 2005-12-28 18:49:34
|
Update of /cvsroot/exfex/exfex/source/exfex/common/utils/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3998/source/exfex/common/utils/security Log Message: Directory /cvsroot/exfex/exfex/source/exfex/common/utils/security added to the repository |
From: Michal H. <ms...@us...> - 2005-12-28 18:49:10
|
Update of /cvsroot/exfex/exfex/source/exfex/common/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3908/source/exfex/common/security Modified Files: IDomain.java Log Message: sync with SecurityContext Index: IDomain.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/IDomain.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IDomain.java 27 Nov 2005 13:04:45 -0000 1.1 --- IDomain.java 28 Dec 2005 18:49:02 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2005/12/28 18:49:02 mstsxfx + * sync with SecurityContext + * * Revision 1.1 2005/11/27 13:04:45 mstsxfx * security system interfaces and classes *************** *** 40,52 **** * disabled in this domain and full access (defined by authorization * evaluator) for domain is guaranted */ ! public void setSecurityContext(ISecurityContext context); /** Returns actual security context. * * @return Security context instance set by ! * {@link #setSecurityContext(ISecurityContext)}. */ ! public ISecurityContext getSecurityContext(); /** Returns all members of domain. --- 43,57 ---- * disabled in this domain and full access (defined by authorization * evaluator) for domain is guaranted + * + * @throws SecurityContextException if wrong or unsupported context is supplied. */ ! public void setSecurityContext(SecurityContext context)throws SecurityContextException; /** Returns actual security context. * * @return Security context instance set by ! * {@link #setSecurityContext(SecurityContext)}. */ ! public SecurityContext getSecurityContext(); /** Returns all members of domain. *************** *** 68,72 **** * @return true if added, otherwise false. */ ! public boolean addMember(Integer id, ISecurityContext context); /** Changes user security context. --- 73,77 ---- * @return true if added, otherwise false. */ ! public boolean addMember(Integer id, SecurityContext context); /** Changes user security context. *************** *** 81,85 **** * @return true if changed/added, or false otherwise (id is null). */ ! public boolean changeMember(Integer id, ISecurityContext context); /** Removes member. --- 86,90 ---- * @return true if changed/added, or false otherwise (id is null). */ ! public boolean changeMember(Integer id, SecurityContext context); /** Removes member. |
From: Michal H. <ms...@us...> - 2005-12-28 18:48:09
|
Update of /cvsroot/exfex/exfex/source/exfex/common/plugins/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3723/source/exfex/common/plugins/security Added Files: StandardResource.java StandardDomain.java StandardSecurityData.java StandardSecurityDataFactory.java Log Message: domain, resource and security data implementation (TODO testing) --- NEW FILE: StandardSecurityDataFactory.java --- /** * $RCSfile: StandardSecurityDataFactory.java,v $ * * $Log: StandardSecurityDataFactory.java,v $ * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) * */ package exfex.common.plugins.security; import exfex.common.pluginsystem.AbstractPlugin; import exfex.common.pluginsystem.IAcceptPlugin; import exfex.common.pluginsystem.IContext; import exfex.common.pluginsystem.PluginManager; import exfex.common.security.ISecurityData; import exfex.common.security.ISecurityDataFactory; /** * * <p> * <pre> * Changes: * </pre> * * @author msts */ public class StandardSecurityDataFactory extends AbstractPlugin implements ISecurityDataFactory { static private final long serialVersionUID = 1L; /** Plugin name. */ static private final String name = "StandardSecurityData"; /** Manager of this plugin. * */ static private final IAcceptPlugin manager = PluginManager.getInstance(); /** Initializing constructor. * * Calls supertype constructor with plugin name parameter. */ StandardSecurityDataFactory() { super(name); } /** Creates StandardSecurityData instance. * @param context This parameter is ignored. */ @Override public Object getInstance(IContext context) { return getSecurityDataInstance(); } /** Creates StandardSecurityData instance. */ public ISecurityData getSecurityDataInstance() { return new StandardSecurityData(); } } --- NEW FILE: StandardDomain.java --- /** * $RCSfile: StandardDomain.java,v $ * * $Log: StandardDomain.java,v $ * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) * */ package exfex.common.plugins.security; import java.util.List; import exfex.common.security.IDomain; import exfex.common.security.SecurityContext; /** Standard implementation of domain. * * TODO doc * <p> * <pre> * Changes: * </pre> * * @author msts */ public class StandardDomain implements IDomain { /** Domain name. */ private String name; private StandardDomain() { } /** Members of domain. */ private List<Integer> members; /** Direct subdomains. */ private List<IDomain> children; /** Context for domain. */ private SecurityContext context; /** Initialization constructor. * * @param name Name of domain. * @throws NullPointerException if name is null. */ public StandardDomain(String name)throws NullPointerException { if(name==null) throw new NullPointerException("Domain is null"); this.name=name; } public String getName() { return name; } /** Sets security context. * Doesn't perform any context checking. */ public void setSecurityContext(SecurityContext context) { this.context=context; } public SecurityContext getSecurityContext() { return context; } public Integer[] getMembers() { Integer [] ret=new Integer[members.size()]; int i=0; for(Integer m: members) ret[i++]=m; return ret; } /** Adds new member. * * @param id Id of new member. Must be non null. * @param context This parameter is ignored. * @return true if id was added, false otherwise. */ public boolean addMember(Integer id, SecurityContext context) { if(id==null) return false; if(!members.contains(id)) { members.add(id); return true; } return false; } /** Empty method. * This method is not implemented because context for members is not supported. * @return false everytime. */ public boolean changeMember(Integer id, SecurityContext context) { return false; } public boolean removeMember(Integer id) { return members.remove(id); } public IDomain[] getSubDomains() { IDomain [] doms= new IDomain[children.size()]; int i=0; for(IDomain d:children) doms[i++]=d; return doms; } public boolean addSubDomain(IDomain dom) { if(dom==null || children.contains(dom)) return false; // check if cycle would occure after adding if(dom.isSubDomain(this)) return true; // adds only if not presented yet if(children.contains(dom)) return false; children.add(dom); return true; } public IDomain removeSubDomain(String name) { if(name==null) return null; IDomain [] doms=getSubDomains(); int i=0; for(IDomain d: doms) { if(d.getName().equals(name)) return children.remove(i); i++; } return null; } public boolean isSubDomain(IDomain dom) { if(dom==null) return false; // check direct children at first if(children.contains(dom)) return true; // recursively check children for(IDomain d: children) { if(d.isSubDomain(dom)) return true; } // not found return false; } } --- NEW FILE: StandardSecurityData.java --- /** * $RCSfile: StandardSecurityData.java,v $ * * $Log: StandardSecurityData.java,v $ * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) * */ package exfex.common.plugins.security; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; import exfex.common.security.DomainException; import exfex.common.security.IDomain; import exfex.common.security.IResource; import exfex.common.security.ISecurityData; import exfex.common.security.ModelNotSupportedException; import exfex.common.security.ResourceException; /** Standard implementation of security data class. * * TODO doc * <p> * <pre> * Changes: * </pre> * * @author msts */ public class StandardSecurityData implements ISecurityData { /** Magic number of this ecurity data. * */ private long magicNumber=666L; /** Container of all registered resources. */ private List<IResource> res=new LinkedList<IResource>(); /** Relation mapping. * Keys are resources (each resource maximaly once) and list of associated domains. */ private Map<IResource, List<IDomain>> mapping=new HashMap<IResource,List<IDomain>>(); public void setMagicNumber(long magic) { magicNumber=magic; } public long getMagicNumber() { return magicNumber; } /** Sets persistant model. * * This method just tests if supplied model is NONPERSISTANT because it doesn't * provide any other. */ public void setPersistanceModel(PersistanceModel model) throws ModelNotSupportedException { if(model!=PersistanceModel.NONPERSISTANT) throw new ModelNotSupportedException(model+" is not supported"); } /** Returns persistant model. * * Allways returns NONPERSISTANT model. */ public PersistanceModel getPersistanceModel() { return PersistanceModel.NONPERSISTANT; } /** Empty method. * */ public void checkPoint() { } public void associateDomain(IResource resource, IDomain dom) throws DomainException, ResourceException { // parameters checking if(resource==null) throw new ResourceException("resource is null"); if(dom==null) throw new DomainException("domain is null"); List<IDomain> associated; // if resource is not in mapping yet, creates associated list // otherwise get associated from mapping if(!mapping.containsKey(resource)) associated=new LinkedList<IDomain>(); else associated=mapping.get(resource); // puts domain to the associated list and put pair to the mapping mapping.put(resource, associated); } /** Creates new Standard domain instance. * * @return Standard domain instance. */ public IDomain createDomain(String name) throws DomainException { return new StandardDomain(name); } public IDomain[] getDomains(IResource resource) throws ResourceException { if(resource==null) throw new ResourceException("resource is null"); if(!mapping.containsKey(resource)) throw new ResourceException(resource.getName()+" is not associated"); // creates return array List<IDomain> associated=mapping.get(resource); IDomain [] ret=new IDomain[associated.size()]; int i=0; for(IDomain dom:associated) ret[i++]=dom; return ret; } public IDomain getDomainByName(IResource resource, String name) throws DomainException, ResourceException { // parameters checking if(resource==null) throw new ResourceException("resource is null"); if(name==null) throw new DomainException("domain name is null"); if(!mapping.containsKey(resource)) throw new ResourceException(resource.getName()+" is has no association"); List<IDomain> associated=mapping.get(resource); for(IDomain dom:associated) if(dom.getName().equals(name)) return dom; throw new DomainException(name+" not found"); } public void releaseDomain(IResource resource, IDomain dom) throws DomainException, ResourceException { // parameters checking if(resource==null) throw new ResourceException("resource is null"); if(dom==null) throw new DomainException("domain is null"); if(!mapping.containsKey(resource)) throw new ResourceException(resource.getName()+" not found"); List<IDomain> associated=mapping.get(resource); if(!associated.remove(dom)) throw new DomainException(dom.getName()+" is not associated"); } /** Creates Standard resource instance. * * @return StandardResource instance. */ public IResource createResource(Object object, String name) throws ResourceException { return new StandardResource(name, object); } /** Removes resource and forget all associations. */ public void removeResource(IResource resource) throws ResourceException { // parameters checking if(resource==null) throw new ResourceException("resource is null"); // associated list is never null if(mapping.remove(resource)==null) throw new ResourceException(resource.getName()+" not found"); } public IResource[] getResources() { Set<IResource> keys=mapping.keySet(); IResource [] ret=new IResource[keys.size()]; int i=0; for(IResource res: keys) ret[i++]=res; return ret; } public boolean knowsResourceByName(String name) { try { getResourceByName(name); return true; }catch(ResourceException e) { return false; } } public IResource getResourceByName(String name) throws ResourceException { IResource [] res=getResources(); for(IResource r: res) if(r.getName().equals(name)) return r; throw new ResourceException(name+" not found"); } } --- NEW FILE: StandardResource.java --- /** * $RCSfile: StandardResource.java,v $ * * $Log: StandardResource.java,v $ * Revision 1.1 2005/12/28 18:48:01 mstsxfx * domain, resource and security data implementation (TODO testing) * */ package exfex.common.plugins.security; import exfex.common.security.IResource; import exfex.common.security.ResourceException; /** Standard implementation of resource. * TODO doc * <p> * <pre> * Changes: * </pre> * * @author msts */ public class StandardResource implements IResource { /** Resource name. */ private String name; /** Resource object. */ private Object resourceObject; private StandardResource() { } public StandardResource(String name, Object res) throws ResourceException { if(name==null) throw new ResourceException(name+" is null"); this.name=name; this.resourceObject=res; } /** Sets new resource object. */ public void setResource(Object resorceObject) { this.resourceObject=resorceObject; } public Object getResource() { return resourceObject; } public String getName() { return name; } public void setName(String name) { this.name=name; } } |
From: Michal H. <ms...@us...> - 2005-12-28 16:45:49
|
Update of /cvsroot/exfex/exfex/source/exfex/common/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8452/source/exfex/common/security Modified Files: IAuthorizationManager.java Identity.java ICapability.java ILocalIdentity.java IdentityManager.java IAccountManager.java ISecurityData.java Log Message: changes syncing Index: IdentityManager.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/IdentityManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IdentityManager.java 27 Nov 2005 13:04:45 -0000 1.1 --- IdentityManager.java 28 Dec 2005 16:45:40 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2005/12/28 16:45:40 mstsxfx + * changes syncing + * * Revision 1.1 2005/11/27 13:04:45 mstsxfx * security system interfaces and classes *************** *** 108,112 **** * create identity. */ ! public Integer createIdentity(IUser profile) { if(profile==null) --- 111,115 ---- * create identity. */ ! public Integer createIdentity(User profile) { if(profile==null) Index: Identity.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/Identity.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Identity.java 27 Nov 2005 13:04:45 -0000 1.1 --- Identity.java 28 Dec 2005 16:45:40 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2005/12/28 16:45:40 mstsxfx + * changes syncing + * * Revision 1.1 2005/11/27 13:04:45 mstsxfx * security system interfaces and classes *************** *** 37,41 **** * <br> * To create instances of this class use static factory method ! * {@link #getIdentity(Integer, IUser, String)}. It can't be created directly to * prevent unintialized instances creation. * --- 40,44 ---- * <br> * To create instances of this class use static factory method ! * {@link #getIdentity(Integer, User, String)}. It can't be created directly to * prevent unintialized instances creation. * *************** *** 99,103 **** * This value is used when authorization is examined. */ ! private final IUser profile; /** Digest algorithm used to created checkSum. --- 102,106 ---- * This value is used when authorization is examined. */ ! private final User profile; /** Digest algorithm used to created checkSum. *************** *** 152,156 **** * begining of constructor and if values were wrong, it will be hard to * destroy running supertype). To create instance use static factory ! * method {@link #getIdentity(Integer, IUser, String)}. * * @param id Identificator of identity. This value should be produced --- 155,159 ---- * begining of constructor and if values were wrong, it will be hard to * destroy running supertype). To create instance use static factory ! * method {@link #getIdentity(Integer, User, String)}. * * @param id Identificator of identity. This value should be produced *************** *** 160,164 **** * @throws RemoteException If RMI problem occures. */ ! private Identity(Integer id, IUser profile, MessageDigest digestAlg) throws RemoteException { --- 163,167 ---- * @throws RemoteException If RMI problem occures. */ ! private Identity(Integer id, User profile, MessageDigest digestAlg) throws RemoteException { *************** *** 184,188 **** * @throws NoSuchAlgorithmException If given algorithm is not supported. */ ! static public Identity getIdentity(Integer id, IUser profile, String digestAlg) throws RemoteException, NullPointerException, NoSuchAlgorithmException { --- 187,191 ---- * @throws NoSuchAlgorithmException If given algorithm is not supported. */ ! static public Identity getIdentity(Integer id, User profile, String digestAlg) throws RemoteException, NullPointerException, NoSuchAlgorithmException { *************** *** 230,234 **** * @return Instance of user profile. */ ! synchronized public IUser getUser() { return profile; --- 233,237 ---- * @return Instance of user profile. */ ! synchronized public User getUser() { return profile; Index: ILocalIdentity.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/ILocalIdentity.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ILocalIdentity.java 27 Nov 2005 13:04:45 -0000 1.1 --- ILocalIdentity.java 28 Dec 2005 16:45:40 -0000 1.2 *************** *** 27,33 **** * authorization process. * ! * @return IUser type instance. Null value should never happen. */ ! public IUser getUser(); /** Examines checkSum. --- 27,33 ---- * authorization process. * ! * @return User type instance. Null value should never happen. */ ! public User getUser(); /** Examines checkSum. Index: IAccountManager.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/IAccountManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IAccountManager.java 27 Nov 2005 13:04:45 -0000 1.1 --- IAccountManager.java 28 Dec 2005 16:45:40 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2005/12/28 16:45:40 mstsxfx + * changes syncing + * * Revision 1.1 2005/11/27 13:04:45 mstsxfx * security system interfaces and classes *************** *** 105,109 **** * @throws AccountException If user doesn't exist in the system. */ ! public IUser getUserProfile(String name) throws AccountException; --- 108,112 ---- * @throws AccountException If user doesn't exist in the system. */ ! public User getUserProfile(String name) throws AccountException; Index: ICapability.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/ICapability.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ICapability.java 27 Nov 2005 13:04:45 -0000 1.1 --- ICapability.java 28 Dec 2005 16:45:40 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2005/12/28 16:45:40 mstsxfx + * changes syncing + * * Revision 1.1 2005/11/27 13:04:45 mstsxfx * security system interfaces and classes *************** *** 19,23 **** * Capabilities are recognized by their names ({@link #getName()} method). * Implementator of this interface perform all low level checking which are ! * implementation specific in {@link #hasCapability(IUser)} method. To get * all implementation specific data, uses its AuhtorizationManager which is * responsible for managing this data. This is not standardized and depends on --- 22,26 ---- * Capabilities are recognized by their names ({@link #getName()} method). * Implementator of this interface perform all low level checking which are ! * implementation specific in {@link #hasCapability(User)} method. To get * all implementation specific data, uses its AuhtorizationManager which is * responsible for managing this data. This is not standardized and depends on *************** *** 25,29 **** * <br> * On other hand, if we want to authorize user in certain context to perform ! * action on specified resource, we can use {@link #setCapability(IUser)} method * for all implementation specific low level actions. * <br> --- 28,32 ---- * <br> * On other hand, if we want to authorize user in certain context to perform ! * action on specified resource, we can use {@link #setCapability(User)} method * for all implementation specific low level actions. * <br> *************** *** 61,65 **** * @return true if user is authorized or false otherwise. */ ! public boolean hasCapability(IUser profile); /** Sets capability for user. --- 64,68 ---- * @return true if user is authorized or false otherwise. */ ! public boolean hasCapability(User profile); /** Sets capability for user. *************** *** 74,78 **** * @return true if succede, false otherwise */ ! public boolean setCapability(IUser profile); /** Sets context for the capability. --- 77,81 ---- * @return true if succede, false otherwise */ ! public boolean setCapability(User profile); /** Sets context for the capability. Index: IAuthorizationManager.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/IAuthorizationManager.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IAuthorizationManager.java 27 Nov 2005 13:04:45 -0000 1.1 --- IAuthorizationManager.java 28 Dec 2005 16:45:40 -0000 1.2 *************** *** 3,6 **** --- 3,9 ---- * * $Log$ + * Revision 1.2 2005/12/28 16:45:40 mstsxfx + * changes syncing + * * Revision 1.1 2005/11/27 13:04:45 mstsxfx * security system interfaces and classes *************** *** 103,107 **** * @param resource Resource */ ! public void setCapability(String capName, IUser profile, IResource resource); /** Adds resource. --- 106,110 ---- * @param resource Resource */ ! public void setCapability(String capName, User profile, IResource resource); /** Adds resource. Index: ISecurityData.java =================================================================== RCS file: /cvsroot/exfex/exfex/source/exfex/common/security/ISecurityData.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ISecurityData.java 27 Nov 2005 13:04:45 -0000 1.1 --- ISecurityData.java 28 Dec 2005 16:45:40 -0000 1.2 *************** *** 1,241 **** ! /* ! * $RCSfile$ ! * * $Log$ ! * Revision 1.1 2005/11/27 13:04:45 mstsxfx ! * security system interfaces and classes ! * ! */ ! package exfex.common.security; ! ! ! /** Interface for implementation independed repository of security data. ! * ! * <h3>Overview</h3> ! * Implementator is intended to collect data needed for authorization evaluation ! * done in {@link exfex.common.security.IAuthorizationManager} implementator. ! * <br> ! * To be independed on concrete model of authorization process, it declares ! * hierarchy domain model with resources. This model can be adapted to almost ! * all athorization models (like unix owner, group, other permisions; ! * hierarchical - military; ACL etc.). Authorization managers can use this class ! * directly or can create helper adapters for desired model. ! * See Description part for more information. ! * <br> ! * Instance of this type is product of ! * {@link exfex.common.security.ISecurityDataFactory} plugin. Created instance ! * is not responsible for its initialization. User (Authorization manager or its ! * helper adapter; we will use evaluator in further text) is responsible to ! * understand specific security (persmission) model and initialize this ! * instance. However AuthorizationManagers are not forced to use this class at ! * all, it may be helpful, because it poses implementation independed and so one ! * implementator would be enought (except that we want some better ! * implementations - with respect to effectivness or speed or whatever). ! * Advantage is that when it is implemented and has clearly defined rules, ! * adapters for concrete permission system may be created and so authorization ! * managers can use just these adapters and doesn't keep much logic inside. ! * TODO schema ! * ! * <h3>Description</h3> ! * SecurityData are based on Domain model. <b>Domain</b> is intended to be basic ! * entity which is associated with certain resource (in shared case resources). ! * Each domain has: ! * <ul> ! * <li>Name - string name of domain used basicly to distinguish two domains in ! * one resource scope (name has to be unique in this scope). ! * <li>Member set - memebers of domain (this can involve users, groups, etc.). ! * Member is defined as integral number and evaluator has to maintain mapping to ! * real persons, groups or whatever. Each member may have defined security ! * context. ! * <li>Security context - ! * {@link exfex.common.security.ISecurityContext restrictions} for domain. These ! * are used by evaluator as additional data. ! * <li>Subdomain set - children domains. ! * </ul> ! * ! * <h4>Rules</h4> ! * {@link exfex.common.security.IResource Resource} mapping to domains is m:n ! * relation (each resource can have multiple but at least 1 domain and domains ! * can be shared between resources, but no orphan domain is allowed). ! * <p> ! * Semantic of domain is given by evaluator (semantic means how evaluator uses ! * domain, what is the meaning and role - domain doesn't know anything about it). ! * Each domain can have its security context defined which can be used by ! * evaluator for more information about what all members of given domain are ! * allowed to do. If not specified (null value), evaluator can use full ! * qualified permissions defined for domain (by its semantic). ! * <br> ! * Domain doesn't have to understand details, but keeps this indormation and ! * returns them on demand. It is not responsible even to check or validate it. ! * Evaluator is responsible to keep the following rule: ! * Subdomain is allowed to, maximaly what its parent is allowed to (in top level ! * domain case - evaluator must provide logic). Maximaly means that it may ! * be restricted with respect to parent but is not allowed to be able to ! * anything that its parent is not allowed. Same rule works for each memeber of ! * domain: member is allowed to everything which its domain is. If user has ! * defined its security context this can may restrict default permissions (no ! * context defined means all permissions inherited from domain). ! * <br> ! * There are not allowed cycles in subdomains relations (domain's recursive ! * child is parent of domain is <b>forbidden</b>) and this class is responsible ! * to keep this invariant. This means that ! * {@link #associateDomain(IResource, IDomain)} may fail. ! * <br> ! * Members of domain are described by unique (in the system scope) number. ! * Domain doesn't have to know any details. Evaluator knows concrete entity ! * assigned to this number. ! * ! * <h4>Examples</h4> ! * To be more concrete, here are some examples how existing permission systems ! * can be defined with security data model. ! * ! * <h5>Unix permissions</h5> ! * Resource have 3 domains: ! * <ul> ! * <li>1st with name owner - member(s) is/are user(s) id(s) who owns this ! * resource (more than one is enhancement comparing to UNIX). Security context ! * contains <code>READ</code>, <code>WRITE</code>, <code>EXECUTE</code> elements ! * each with true/false value. ! * <li>2nd with name groups - member(s) is/are group(s) id(s) which are ! * associated with resource (more than one is enhancment comparing to UNIX). ! * Each member has security context which contains <code>READ</code>, ! * <code>WRITE</code>, <code>EXECUTE</code> elements each with true/false value. ! * Memebers of group have same permisions as its group. Evaluator has to ! * define logic which permission to use if user is memeber of multiple groups ! * and those are in members of this domain. ! * <li>3rd with name others - Security context contains <code>READ</code>, ! * <code>WRITE</code>, <code>EXECUTE</code> elements each with true/false value. ! * And everybody who is not memeber of previous domain has this permissions. ! * </ul> ! * Evaluator has to maintain/get user information (id) and groups-members ! * association (for intialization). ! * ! * <h5>ACL</h5> ! * Access control list are straight forward. Domain is ACL and members are users ! * (defined by its id). Security context can also be used as enhancement, but ! * ACL name is enough. Evalutor has to know all ACL and meaning of each with ! * its members (for intialization). ! * ! * <h5>Hierarchy-Military model</h5> ! * By hierarchy model, we means permission model, where each hierarchy stage is ! * allowed to perform some set of operation and this set of operations is ! * subset of superior stage and superset of stage under (similar to charges in ! * military system). Implementation using SecurityData is also straight forward. ! * Each resource is associated with predefined domains (each domain stands for ! * one hierarchy stage) and evaluator knows meaning, authority of each and its ! * members. Security context doesn't have to be used at all. ! * ! * <h5>Access cart model</h5> ! * By this model, we means permission model, where everbody who owns som public ! * secret in certain cathegory is allowed to perform an action in this cathegory. ! * For example, each resource can have 3 domains each with security context ! * containing <code>KEY</code> with key value: ! * <ul> ! * <il>full access - who knows (holds) same key is allowed to make all operations ! * on the resource. ! * <il>read only access - who knows (holds) same key is allowed to get all ! * information about resource (read its content or state or whatever, but is not ! * allowed to change it) ! * <il>write only access - who knows (holds) same key is allowed to change ! * resource's state or contente or whatever (but is not allowed to read changes) ! * </ul> ! * ! * <p> ! * <pre> ! * Changes: ! * 15.11.2005 msts - created ! * </pre> ! * ! * @author msts ! */ ! public interface ISecurityData ! { ! /** Associate resource with given domain. ! * ! * If given resource is not registered yet, it will be registered using ! * {@link #registerResource(Object, String)} method. ! * ! * @param resource Resource instance. ! * @param dom Domain to be associated. ! * @throws DomainException If problem occures during creation of ! * association (there already is such domain, etc.). ! */ ! public void associateDomain(IResource resource, IDomain dom) ! throws DomainException; ! ! /** Factory method for domain creation. ! * ! * Use this method for domain creation instead of using <code>new</code> ! * operator if you want to add new domain. ! * TODO some parameter ! * @return Domain instance. ! */ ! public IDomain createDomain(); ! ! /** Returns all domains associated with given resource. ! * ! * @param resource Resource instance. ! * @return An array of domains associated with resource added by ! * {@link #associateDomain(IResource, IDomain)} method. ! * @throws ResourceException if resource is not registered. ! */ ! public IDomain[] getDomains(IResource resource) ! throws ResourceException; ! ! /** Returns domain with given name associated with given resource. ! * ! * @param resource Resource instance. ! * @param name Domain name. ! * @return Domain instance. ! * @throws DomainException If domain is not associated with given ! * resource. ! * @throws ResourceException If resource is not registered. ! */ ! public IDomain getDomainByName(IResource resource, String name) ! throws DomainException, ResourceException; ! ! /** Destroy association of resource with given domain. ! * ! * @param resource Resource instance. ! * @param dom Domain to release. ! * @throws DomainException If domain is not associated with given ! * resource. ! * @throws ResourceException If resource is not registered. ! */ ! public void releaseDomain(IResource resource, IDomain dom) ! throws DomainException, ResourceException; ! ! /** Creates and registers new resource. ! * ! * If this method suceede, resource can be used for SecurityData ! * instance and can be identified by name (returned by ! * {@link IResource#getName()} method). ! * There are no restrictions on given object (it can be null). User of ! * this class has to define logic for it and so use it in defined way. ! * SecurityData object doesn't use it internally. ! * ! * @param object Entity object. ! * @param name Name that will be used in SecurityData instance. ! * @return IResource instance. ! * @throws DomainException if name already exist or any other problem ! * occures during creation or registration. ! */ ! public IResource registerResource(Object object, String name) ! throws DomainException; ! ! /** Removes resource. ! * ! * Resource won't be available in futureure unless registerResource or ! * associateDomain (with this resource) is called again. ! * @param resource Resource to remove. ! * @throws ResourceException If given resource is not registered. ! */ ! public void removeResource(IResource resource) ! throws ResourceException; ! ! /** Returns all registered resources. ! * ! * @return An array of resource instances. ! */ ! public IResource[] getResources(); ! } --- 1,355 ---- ! /* ! * $RCSfile$ ! * * $Log$ ! * Revision 1.2 2005/12/28 16:45:40 mstsxfx ! * changes syncing ! * ! * Revision 1.1 2005/11/27 13:04:45 mstsxfx ! * security system interfaces and classes ! * ! */ ! package exfex.common.security; ! ! ! /** Interface for implementation independed repository of security data. ! * ! * <h3>Overview</h3> ! * Implementator is intended to collect data needed for authorization evaluation ! * done in {@link exfex.common.security.IAuthorizationManager} implementator. ! * Suggested but not mandatory is persistent model of this data, so user of ! * this class doesn't have to bother with persistency (suggested means that ! * implementator has to implement {@link #setPersistanceModel(PersistanceModel)} ! * and {@link #getPersistanceModel()}, but doesn't have to support all models ! * except {@link PersistanceModel#NONPERSISTANT} which has to be supported). ! * Each implementator is responsible to describe and enable setting of this ! * model. ! * Persistance doesn't mean configuration. It just keeps data stored in instance ! * in persistance storage from which can be rebuild (e.g. after accidental ! * system crash). User of this class is responsible for synchronization with ! * configuration (e.g. someone is member of certain system group etc.). ! * <br> ! * To be independed on concrete model of authorization process, it declares ! * hierarchy domain model with resources. This model can be adapted to almost ! * all athorization models (like unix owner, group, other permisions; ! * hierarchical - military; ACL etc.). Authorization managers can use this class ! * directly or can create helper adapters for desired model. ! * See Description part for more information. ! * <br> ! * Instance of this type is product of ! * {@link exfex.common.security.ISecurityDataFactory} plugin. Created instance ! * is not responsible for its initialization. User (Authorization manager or its ! * helper adapter; we will use evaluator in further text) is responsible to ! * understand specific security (persmission) model and initialize this ! * instance. However AuthorizationManagers are not forced to use this class at ! * all, it may be helpful, because it poses implementation independed and so one ! * implementator would be enought (except that we want some better ! * implementations - with respect to effectivness or speed or whatever). ! * Advantage is that when it is implemented and has clearly defined rules, ! * adapters for concrete permission system may be created and so authorization ! * managers can use just these adapters and doesn't keep much logic inside. ! * TODO schema ! * ! * <h3>Description</h3> ! * SecurityData are based on Domain model. <b>Domain</b> is intended to be basic ! * entity which is associated with certain resource (in shared case resources). ! * Each domain has: ! * <ul> ! * <li>Name - string name of domain used basicly to distinguish two domains in ! * one resource scope (name has to be unique in this scope). ! * <li>Member set - memebers of domain (this can involve users, groups, etc.). ! * Member is defined as integral number and evaluator has to maintain mapping to ! * real persons, groups or whatever. Each member may have defined security ! * context. ! * <li>Security context - ! * {@link exfex.common.security.SecurityContext restrictions} for domain. These ! * are used by evaluator as additional data. ! * <li>Subdomain set - children domains. ! * </ul> ! * ! * <h4>Rules</h4> ! * {@link exfex.common.security.IResource Resource} mapping to domains is m:n ! * relation (each resource can have multiple but at least 1 domain and domains ! * can be shared between resources, but no orphan domain is allowed). ! * <p> ! * Semantic of domain is given by evaluator (semantic means how evaluator uses ! * domain, what is the meaning and role - domain doesn't know anything about it). ! * Each domain can have its security context defined which can be used by ! * evaluator for more information about what all members of given domain are ! * allowed to do. If not specified (null value), evaluator can use full ! * qualified permissions defined for domain (by its semantic). ! * <br> ! * Domain doesn't have to understand details, but keeps this indormation and ! * returns them on demand. It is not responsible even to check or validate it. ! * Evaluator is responsible to keep the following rule: ! * Subdomain is allowed to, maximaly what its parent is allowed to (in top level ! * domain case - evaluator must provide logic). Maximaly means that it may ! * be restricted with respect to parent but is not allowed to be able to ! * anything that its parent is not allowed. Same rule works for each memeber of ! * domain: member is allowed to everything which its domain is. If user has ! * defined its security context this can may restrict default permissions (no ! * context defined means all permissions inherited from domain). ! * <br> ! * There are not allowed cycles in subdomains relations (domain's recursive ! * child is parent of domain is <b>forbidden</b>) and this class is responsible ! * to keep this invariant. This means that ! * {@link #associateDomain(IResource, IDomain)} may fail. ! * <br> ! * Members of domain are described by unique (in the system scope) number. ! * Domain doesn't have to know any details. Evaluator knows concrete entity ! * assigned to this number. ! * ! * <h4>Examples</h4> ! * To be more concrete, here are some examples how existing permission systems ! * can be defined with security data model. ! * ! * <h5>Unix permissions</h5> ! * Resource have 3 domains: ! * <ul> ! * <li>1st with name owner - member(s) is/are user(s) id(s) who owns this ! * resource (more than one is enhancement comparing to UNIX). Security context ! * contains <code>READ</code>, <code>WRITE</code>, <code>EXECUTE</code> elements ! * each with true/false value. ! * <li>2nd with name groups - member(s) is/are group(s) id(s) which are ! * associated with resource (more than one is enhancment comparing to UNIX). ! * Each member has security context which contains <code>READ</code>, ! * <code>WRITE</code>, <code>EXECUTE</code> elements each with true/false value. ! * Memebers of group have same permisions as its group. Evaluator has to ! * define logic which permission to use if user is memeber of multiple groups ! * and those are in members of this domain. ! * <li>3rd with name others - Security context contains <code>READ</code>, ! * <code>WRITE</code>, <code>EXECUTE</code> elements each with true/false value. ! * And everybody who is not memeber of previous domain has this permissions. ! * </ul> ! * Evaluator has to maintain/get user information (id) and groups-members ! * association (for intialization). ! * ! * <h5>ACL</h5> ! * Access control list are straight forward. Domain is ACL and members are users ! * (defined by its id). Security context can also be used as enhancement, but ! * ACL name is enough. Evalutor has to know all ACL and meaning of each with ! * its members (for intialization). ! * ! * <h5>Hierarchy-Military model</h5> ! * By hierarchy model, we means permission model, where each hierarchy stage is ! * allowed to perform some set of operation and this set of operations is ! * subset of superior stage and superset of stage under (similar to charges in ! * military system). Implementation using SecurityData is also straight forward. ! * Each resource is associated with predefined domains (each domain stands for ! * one hierarchy stage) and evaluator knows meaning, authority of each and its ! * members. Security context doesn't have to be used at all. ! * ! * <h5>Access cart model</h5> ! * By this model, we means permission model, where everbody who owns som public ! * secret in certain cathegory is allowed to perform an action in this cathegory. ! * For example, each resource can have 3 domains each with security context ! * containing <code>KEY</code> with key value: ! * <ul> ! * <il>full access - who knows (holds) same key is allowed to make all operations ! * on the resource. ! * <il>read only access - who knows (holds) same key is allowed to get all ! * information about resource (read its content or state or whatever, but is not ! * allowed to change it) ! * <il>write only access - who knows (holds) same key is allowed to change ! * resource's state or contente or whatever (but is not allowed to read changes) ! * </ul> ! * ! * <p> ! * <pre> ! * Changes: ! * 15.11.2005 msts - created ! * </pre> ! * ! * @author msts ! */ ! public interface ISecurityData ! { ! /** Persistance model of the SecurityData implementation. ! * ! * This enum contains constance which describes certain model of ! * persistance. ! * ! * <p> ! * <pre> ! * Changes: ! * 28.11.2005 msts - created ! * </pre> ! * ! * @author msts ! */ ! static public enum PersistanceModel ! { ! /** Implmentator provides no persistancy. ! * This means that all data stored in SecurityData implementator ! * are lost after instance stops existing. ! */ ! NONPERSISTANT, ! ! /** Implementator provides persistancy on demand. ! * This means that all data are stored on SecurityData instance ! * user demand (calls TODO method). ! */ ! CHECKPOINT, ! ! /** Implementator provides persistancy for all changes. ! * This means that each time data are changed SecurityData ! * instance will store data. ! */ ! CHANGEPERSISTANT ! } ! ! /** Sets magic number of instance. ! * ! * This can be used by user to associate instance with unique number. ! * If implemetation implements some persistence model, this value is ! * included in persistent data and when instance is reactivated from ! * persistent storage, user can check if instance contains data which ! * he needs. ! * ! * @param magic Number to be set as magic. ! */ ! public void setMagicNumber(long magic); ! ! /** Retursn magic number. ! * ! * @return Value of magic number. ! */ ! public long getMagicNumber(); ! ! /** Sets persistance model. ! * ! * Each implementator supports at least {@link PersistanceModel#NONPERSISTANT} ! * model. ! * ! * @param model Concrete persistance model. ! * @throws ModelNotSupportedException if given model is not supported ! * by implementator. ! */ ! public void setPersistanceModel(PersistanceModel model) ! throws ModelNotSupportedException; ! ! /** Gets actual persistance model. ! * ! * @return Model. ! */ ! public PersistanceModel getPersistanceModel(); ! ! /** Persists all data. ! * This method should be used primarily when persistance model is ! * {@link PersistanceModel#CHECKPOINT} and we wants to store actual ! * state of instance. When model is {@link PersistanceModel#CHANGEPERSISTANT} ! * it is done automaticaly, so there is no need to call this method. ! * Finally if model is {@link PersistanceModel#NONPERSISTANT}, ! * implementator should do nothing. ! * ! */ ! public void checkPoint(); ! ! /** Associate resource with given domain. ! * ! * If given resource is not registered yet, it will be registered using ! * {@link #createResource(Object, String)} method. ! * ! * @param resource Resource instance. ! * @param dom Domain to be associated. ! * @throws DomainException If problem occures during creation of ! * association (there already is such domain, etc.). ! * @throws ResourceException If resource is not valid. ! */ ! public void associateDomain(IResource resource, IDomain dom) ! throws DomainException, ResourceException; ! ! /** Factory method for domain creation. ! * ! * Use this method for domain creation instead of using <code>new</code> ! * operator if you want to add new domain. ! * ! * @param name Domain name. Must be non null. ! * @return Domain instance. ! * @throws DomainException If domain couldn't be created. ! */ ! public IDomain createDomain(String name) throws DomainException; ! ! /** Returns all domains associated with given resource. ! * ! * @param resource Resource instance. ! * @return An array of domains associated with resource added by ! * {@link #associateDomain(IResource, IDomain)} method. ! * @throws ResourceException if resource is not registered. ! */ ! public IDomain[] getDomains(IResource resource) ! throws ResourceException; ! ! /** Returns domain with given name associated with given resource. ! * ! * @param resource Resource instance. ! * @param name Domain name. ! * @return Domain instance. ! * @throws DomainException If domain is not associated with given ! * resource. ! * @throws ResourceException If resource is not registered. ! */ ! public IDomain getDomainByName(IResource resource, String name) ! throws DomainException, ResourceException; ! ! /** Destroy association of resource with given domain. ! * ! * @param resource Resource instance. ! * @param dom Domain to release. ! * @throws DomainException If domain is not associated with given ! * resource. ! * @throws ResourceException If resource is not registered. ! */ ! public void releaseDomain(IResource resource, IDomain dom) ! throws DomainException, ResourceException; ! ! /** Creates new resource. ! * ! * If this method suceede, resource can be used for SecurityData ! * instance and can be identified by name (returned by ! * {@link IResource#getName()} method). ! * There are no restrictions on given object (it can be null). User of ! * this class has to define logic for it and so use it in defined way. ! * SecurityData object doesn't use it internally. ! * ! * @param object Entity object. ! * @param name Name that will be used in SecurityData instance. ! * @return IResource instance. ! * @throws ResourceException if name already exist or any other problem ! * occures during creation or registration. ! */ ! public IResource createResource(Object object, String name) ! throws ResourceException; ! ! /** Removes resource. ! * ! * Resource won't be available in futureure unless registerResource or ! * associateDomain (with this resource) is called again. ! * @param resource Resource to remove. ! * @throws ResourceException If given resource is not registered. ! */ ! public void removeResource(IResource resource) ! throws ResourceException; ! ! /** Returns all registered resources. ! * ! * @return An array of resource instances. ! */ ! public IResource[] getResources(); ! ! /** Examines, if resource with given name is known. ! * ! * @param name Resource name. ! * @return true if method {@link #getResourceByName(String)} would ! * succeede. ! */ ! public boolean knowsResourceByName(String name); ! ! /** Returns resource by name. ! * ! * @param name Resource name. ! * @return Resource instance. ! * @throws ResourceException If given resource is not found. ! */ ! public IResource getResourceByName(String name)throws ResourceException; ! } |
From: Michal H. <ms...@us...> - 2005-12-28 16:45:28
|
Update of /cvsroot/exfex/exfex/source/exfex/common/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8395/source/exfex/common/security Added Files: ModelNotSupportedException.java SecurityContextException.java Log Message: new exceptions --- NEW FILE: ModelNotSupportedException.java --- /* * $RCSfile: ModelNotSupportedException.java,v $ * * $Log: ModelNotSupportedException.java,v $ * Revision 1.1 2005/12/28 16:45:17 mstsxfx * new exceptions * */ package exfex.common.security; /** Model is not supported exception. * * This exception should be thrown when certain model is requiered, but * implementator doesn't support it. * * <p> * <pre> * Changes: * </pre> * * @author msts */ public class ModelNotSupportedException extends Exception { static private final long serialVersionUID = 1L; /** Constructor with message. * * @param msg Message of the exception. */ public ModelNotSupportedException(String msg) { super(msg); } /** Constructor with message and cause. * * @param msg Message of the exception. * @param cause Lowlevel exception which caused this exception. */ public ModelNotSupportedException(String msg, Throwable cause) { super(msg,cause); } } --- NEW FILE: SecurityContextException.java --- /** * $RCSfile: SecurityContextException.java,v $ * * $Log: SecurityContextException.java,v $ * Revision 1.1 2005/12/28 16:45:17 mstsxfx * new exceptions * */ package exfex.common.security; /** Exception for Security context. * * This exception is thrown when incompatible security context is given or * security context doesn't contain or contain bad keys/values. * * <p> * <pre> * Changes: * 8.12.2005 msts - created * </pre> * * @author msts */ public class SecurityContextException extends Exception { static private final long serialVersionUID = 1L; /** Constructor with message. * * @param msg Message of the exception. */ public SecurityContextException(String msg) { super(msg); } /** Constructor with message and cause. * * @param msg Message of the exception. * @param cause Lowlevel exception which caused this exception. */ public SecurityContextException(String msg, Throwable cause) { super(msg,cause); } } |
From: Michal H. <ms...@us...> - 2005-12-28 16:45:10
|
Update of /cvsroot/exfex/exfex/source/exfex/common/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8194/source/exfex/common/security Added Files: User.java SecurityContext.java Log Message: classes (with implementation) instead of interfaces --- NEW FILE: SecurityContext.java --- /* * $RCSfile: SecurityContext.java,v $ * * $Log: SecurityContext.java,v $ * Revision 1.1 2005/12/28 16:44:58 mstsxfx * classes (with implementation) instead of interfaces * * Revision 1.1 2005/11/27 13:04:45 mstsxfx * security system interfaces and classes * */ package exfex.common.security; import java.io.Serializable; import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Set; import exfex.common.utils.CloneAble; /** Security context class. * * Context is described as string key and arbitrary object type value * pairs. User has to understand this association and use it properly. * <br> * Use {@link #add} and {@link #get} methods to manipulate context. * <br> * This class is just wraper to HashMap class and provides clonning and some * type checking. * <p> * <pre> * Changes: * 15.11.2005 msts - created * </pre> * * @author msts */ public class SecurityContext implements Serializable, CloneAble { static private final long serialVersionUID = 1L; /** Mapping of keys to values. */ private Map<String, Object> mapping=new HashMap<String, Object>(); /** Adds key, value pair to the context. * * If given key already is in the context, changes its value. * * @param key Key name. Must be non null. * @param value Value associated with the key. May have null value. * @return Previous associated value (may be null if either key, value * pair wasn't in the map or previous value was null. * @throws NullPointerException if key value is null string. */ public Object add(String key, Object value)throws NullPointerException { if(key==null) throw new NullPointerException("key is null"); return value.getClass().cast(mapping.put(key,value)); } /** Returns value associated with given key. * * Gets value associated with given key. If doesn't know key, throws * an exception. If type parameter is non null, uses it to cast value * associatedy with key. If value is not this type, throws an exception. * * <br> * Usage example: * <br> * <pre> * SecurityContext securityContext=... * * // Asks for integer value associated with int key * Integer value=securityContext.get("int",Integer.class); * </pre> * * @param key Key name. Must be non null. * @param type Type to be used for return value. Must be non null. * @param <T> Type of the return value. * @return instance associated with the key. * @throws SecurityContextException If key couldn't be found or value is * not type. * @throws NullPointerException if given key is null string or type is * null. */ public <T extends Object> T get(String key, Class<T> type) throws NullPointerException, SecurityContextException { if(key==null) throw new NullPointerException("key is null"); if(type==null) throw new NullPointerException("type is null"); // find out if key is in the mapping and if not throws an // exception if(!mapping.containsKey(key)) throw new SecurityContextException("No such resource: "+key); // key is int the mapping, so gets value and try to cast it // according value parameter. If value is null, returns it // directly Object v=mapping.get(key); if(v==null) return null; try { return type.cast(v); }catch(ClassCastException e) { // throw an exception throw new SecurityContextException("value is not "+ type+" type.",e); } } /** Returns set of entries. * * NOTE: Chnages made to this set affects instance content! * * @return Set of entries. */ public Set<Map.Entry<String,Object>> entrySet() { return mapping.entrySet(); } /** Returns all keys from context. * * @return Collection of string keys. */ public Collection<String> getKeys() { return mapping.keySet(); } /** Creates deep copy of this class. * * @return New instance of SecurityContext which has same content but * changes doesn't affect original instance. */ @Override public Object clone() { SecurityContext clone=new SecurityContext(); Set<Map.Entry<String,Object>> entries=mapping.entrySet(); // insert each pair with same key (both are supposed to be // immutable, so don't need clonning for(Map.Entry<String,Object> e : entries) clone.add(e.getKey(),e.getValue()); return clone; } /** Equals method. * * Delegates to the {@link #mapping}. */ @Override public boolean equals(Object o) { return mapping.equals(o); } /** hashCode method. * * Delegates to the {@link #mapping}. */ @Override public int hashCode() { return mapping.hashCode(); } } --- NEW FILE: User.java --- /** * $RCSfile: User.java,v $ * * $Log: User.java,v $ * Revision 1.1 2005/12/28 16:44:58 mstsxfx * classes (with implementation) instead of interfaces * */ package exfex.common.security; import java.util.Hashtable; /** Class for user profile information. * * This class offers information independed on security system * implementation: * <ul> * <li>name - user name. This is unique in maintainig aplication scope. * <li>UID - user unified identificator. This number is assigned by system when * user account is created. When migrating to the new system, it is very * propable that this number will change while name would keep (if can be * accepted - may fail because of name clash). * <li>profileInfo - additional information for this user. It contains key, * value pairs, where key identifies and value represents this information. * This is used for advanced manipulation with user profile. * </ul> * <br> * NOTE that this class doesn't use any synchornization mechanism, because it * contains only constant data initialized in constructor. * To prevent race conditions in profile, uses Hashtable as a storage for it and * this class is synchronized. * <br> * Class implements TODO * * <p> * <pre> * Changes: * 16.12.2005 msts - created (User interface is removed and just this * implementation is used) * </pre> * * @author msts */ public class User { /** User name. * */ private String name; /** User identifier. */ private Integer uid; /** User profile. * * Mapping from names to values which represents user profile * information. User of this is responsible to know correct types * of values stored in this mapping. */ private Hashtable<String, Object> profile=new Hashtable<String, Object>(); /** Empty constructor. * * This contructor is disabled to prevent from uninitialized instances. */ private User() {} /** Initializating constructor. * * Sets name and uid fields. * * @param name Name of the user. Must be non null. * @param uid User identifier. Must be non null. * @throws NullPointerException If at least one parameter is null. */ public User(String name, Integer uid) throws NullPointerException { // parameters checking if(name==null) throw new NullPointerException("name is null"); if(uid==null) throw new NullPointerException("uid is null"); this.name=name; this.uid=uid; } /** Returns user name. * * @return Name of the user. */ public String getName() { return name; } /** Returns user identification number. * * Each user has unique identification number assigned when it is c * reated and this number doesn't change during whole user account * exists. * * @return Identification number. */ public Integer getUID() { return uid; } /** Returns profile information associated with given key. * * @param key Name of the information. * @return Value associated with given key. If given assocociation * doesn't exist, returns null. */ public Object getProfileInfo(String key) { return profile.get(key); } /** Sets new value for given key. * * Add or chnage association. * * @param key Name of the information. * @param value Value of the information. * @return Old value of the information (it can be null if either old * value was null or given association didn't exist). */ public Object setProfileInfo(String key, Object value) { return profile.put(key, value); } /** Equals method. * * Compares given object to this instance. * <br> * Given object equals to this instance iff: * <ul> * <li>o is non null * <li>o is instance of User class * <li>o has same name and identifier as this instance * </ul> */ @Override public boolean equals(Object o) { if(!(o instanceof User)) return false; User uo=(User)o; // identifiers has to be same if(!uid.equals(uo.getUID())) return false; // names has to be same if(!name.equals(uo.getName())) return false; // everything is ok return true; } @Override public int hashCode() { int result=19; result=37*result+name.hashCode(); result=37*result+uid.hashCode(); return result; } @Override public String toString() { return "User=[ name=\""+name+"\" uid="+uid+"]"; } } |
From: Michal H. <ms...@us...> - 2005-12-28 16:44:27
|
Update of /cvsroot/exfex/exfex/source/exfex/common/security In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8075/source/exfex/common/security Removed Files: IUser.java ISecurityContext.java Log Message: replaced by classes (interface removed) --- IUser.java DELETED --- --- ISecurityContext.java DELETED --- |
From: Pavel O. <pa...@us...> - 2005-12-08 21:37:01
|
Update of /cvsroot/exfex/exfex/source/exfex/common/utils In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2132 Added Files: LineReader.java Log Message: Basic version --- NEW FILE: LineReader.java --- /* * $RCSfile: LineReader.java,v $ * * $Log: LineReader.java,v $ * Revision 1.1 2005/12/08 21:36:44 pavel_o * Basic version * * */ package exfex.common.utils; import java.io.*; /** * The LineReader class provides basic reading functionality over text files. * Class implementation is based on line processing. * * @author <a href="mailto:ml...@se...">Pavel Ondrousek</a> * @version 0.1 */ public class LineReader { // member variables LineNumberReader m_sourceFile = null; String m_lineBuffer = null; int m_position; java.util.TreeMap m_lines = null; // // methods //---------------------------------------------------------------------- /** * TextReader class constructor. * @param filename name of source text file * @throws Exception if opening file has failed */ public LineReader(String filename) //throws ReposException { try { m_sourceFile = new LineNumberReader( new FileReader( filename )); m_position = 0; } catch (FileNotFoundException e) { //throw new ReposException( "TextReader - Unable to open file \"" + m_sourceFile + "\" for reading."); }; m_lines = new java.util.TreeMap(); } /** * TextReader class constructor. * @param filename name of source text file * @throws Exception if opening file has failed */ public LineReader(byte [] buff) //throws ReposException { try { m_sourceFile = new LineNumberReader( new InputStreamReader(new ByteArrayInputStream( buff ))); m_position = 0; } catch (Exception e) { //throw new ReposException( "TextReader - Unable to read data."); }; m_lines = new java.util.TreeMap(); } //---------------------------------------------------------------------- public boolean hasNextLine() { boolean retval = true; try { m_lineBuffer = m_sourceFile.readLine(); m_lines.put( new Integer(m_position), m_lineBuffer); m_position++; } catch (IOException e) { retval = false; //TODO - close source //m_sourceFile.close(); } return retval; } //---------------------------------------------------------------------- public String getLine() { return m_lineBuffer; } //---------------------------------------------------------------------- public String getLinePosition() { return Integer.toString(m_position); } //---------------------------------------------------------------------- public String getLine( int position ) { if ( position < m_position ) return m_lines.get( new Integer(position) ).toString(); while ( m_position <= position ) { try { m_lineBuffer = m_sourceFile.readLine(); m_lines.put( new Integer (m_position), m_lineBuffer); m_position++; } catch (IOException e) { return null; } } return m_lineBuffer; } } |