| 1 | Index: server/test/ome/server/itests/AbstractManagedContextTest.java |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- server/test/ome/server/itests/AbstractManagedContextTest.java (revision 1027) |
|---|
| 4 | +++ server/test/ome/server/itests/AbstractManagedContextTest.java (working copy) |
|---|
| 5 | @@ -22,6 +22,7 @@ |
|---|
| 6 | import ome.api.local.LocalQuery; |
|---|
| 7 | import ome.api.local.LocalUpdate; |
|---|
| 8 | import ome.model.meta.Experimenter; |
|---|
| 9 | +import ome.model.meta.ExperimenterGroup; |
|---|
| 10 | import ome.security.SecuritySystem; |
|---|
| 11 | import ome.system.OmeroContext; |
|---|
| 12 | import ome.system.Principal; |
|---|
| 13 | @@ -112,7 +113,12 @@ |
|---|
| 14 | e.setFirstName("New"); |
|---|
| 15 | e.setLastName("User"); |
|---|
| 16 | e.setOmeName(uuid); |
|---|
| 17 | - iAdmin.createUser(e); |
|---|
| 18 | + e = new Experimenter( iAdmin.createUser(e), false ); |
|---|
| 19 | + ExperimenterGroup g = new ExperimenterGroup(); |
|---|
| 20 | + g.setName(uuid); |
|---|
| 21 | + g = new ExperimenterGroup( iAdmin.createGroup(g), false ); |
|---|
| 22 | + iAdmin.addGroups(e,g); |
|---|
| 23 | + iAdmin.setDefaultGroup(e, g); |
|---|
| 24 | loginUser(uuid); |
|---|
| 25 | } |
|---|
| 26 | |
|---|
| 27 | Index: server/src/ome/security/basic/BasicSecuritySystem.java |
|---|
| 28 | =================================================================== |
|---|
| 29 | --- server/src/ome/security/basic/BasicSecuritySystem.java (revision 1032) |
|---|
| 30 | +++ server/src/ome/security/basic/BasicSecuritySystem.java (working copy) |
|---|
| 31 | @@ -69,6 +69,7 @@ |
|---|
| 32 | import ome.model.meta.ExperimenterGroup; |
|---|
| 33 | import ome.model.meta.ExternalInfo; |
|---|
| 34 | import ome.model.meta.GroupExperimenterMap; |
|---|
| 35 | +import ome.parameters.Parameters; |
|---|
| 36 | import ome.security.ACLVoter; |
|---|
| 37 | import ome.security.AdminAction; |
|---|
| 38 | import ome.security.SecureAction; |
|---|
| 39 | @@ -1032,7 +1033,8 @@ |
|---|
| 40 | } |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | - private Principal clearAndCheckPrincipal() { |
|---|
| 44 | + private Principal clearAndCheckPrincipal() |
|---|
| 45 | + { |
|---|
| 46 | // clear even if this fails. (make SecuritySystem unusable) |
|---|
| 47 | cd.clear(); |
|---|
| 48 | |
|---|
| 49 | @@ -1053,6 +1055,35 @@ |
|---|
| 50 | if (p.getEventType() == null) |
|---|
| 51 | throw new InternalException( |
|---|
| 52 | "Principal.eventType is null in EventContext. Security system failure."); |
|---|
| 53 | + |
|---|
| 54 | + // ticket:404 -- preventing users from logging into "user" group |
|---|
| 55 | + if ( roles.getUserGroupName().equals( p.getGroup() )) |
|---|
| 56 | + { |
|---|
| 57 | + List<ExperimenterGroup> groups = |
|---|
| 58 | + sf.getQueryService().findAllByQuery( |
|---|
| 59 | + "select g from ExperimenterGroup g " + |
|---|
| 60 | + "join g.groupExperimenterMap as m " + |
|---|
| 61 | + "join m.child as u " + |
|---|
| 62 | + "where g.name != :userGroup and " + |
|---|
| 63 | + "u.omeName = :userName", |
|---|
| 64 | + new Parameters() |
|---|
| 65 | + .addString("userGroup",roles.getUserGroupName()) |
|---|
| 66 | + .addString("userName", p.getName())); |
|---|
| 67 | + |
|---|
| 68 | + if ( groups.size() != 1 ) |
|---|
| 69 | + { |
|---|
| 70 | + throw new SecurityViolation(String.format( |
|---|
| 71 | + "User %s attempted to login to user group \"%s\". When " + |
|---|
| 72 | + "doing so, there must be EXACTLY one default group for " + |
|---|
| 73 | + "that user and not %d", p.getName(), |
|---|
| 74 | + roles.getUserGroupName(), groups.size())); |
|---|
| 75 | + } |
|---|
| 76 | + |
|---|
| 77 | + final Principal updated = new Principal( |
|---|
| 78 | + p.getName(),groups.get(0).getName(),p.getEventType()); |
|---|
| 79 | + principalHolder.set( p ); |
|---|
| 80 | + return updated; |
|---|
| 81 | + } |
|---|
| 82 | return p; |
|---|
| 83 | } |
|---|
| 84 | |
|---|
| 85 | Index: server/src/ome/tools/hibernate/HibernateUtils.java |
|---|
| 86 | =================================================================== |
|---|
| 87 | --- server/src/ome/tools/hibernate/HibernateUtils.java (revision 1027) |
|---|
| 88 | +++ server/src/ome/tools/hibernate/HibernateUtils.java (working copy) |
|---|
| 89 | @@ -166,16 +166,23 @@ |
|---|
| 90 | if ( t.isCollectionType() && null == currentState[i] ) |
|---|
| 91 | { |
|---|
| 92 | Object previous = previousState[i]; |
|---|
| 93 | - if ( ! (previous instanceof Collection) ) // implies not null |
|---|
| 94 | + if ( previous == null ) |
|---|
| 95 | { |
|---|
| 96 | + // ignore. If the system gave it to us, it can handle it. |
|---|
| 97 | + } |
|---|
| 98 | + else if ( ! (previous instanceof Collection) ) |
|---|
| 99 | + { |
|---|
| 100 | throw new InternalException(String.format( |
|---|
| 101 | "Invalid collection found for null " + |
|---|
| 102 | "field %s in previous state for %s", |
|---|
| 103 | propertyNames[i],entity)); |
|---|
| 104 | } |
|---|
| 105 | - log("Copying nulled collection ",propertyNames[i]); |
|---|
| 106 | - Collection copy = copy(((PersistentCollection)previous)); |
|---|
| 107 | - persister.setPropertyValue(entity,i,copy,source.getEntityMode()); |
|---|
| 108 | + else |
|---|
| 109 | + { |
|---|
| 110 | + log("Copying nulled collection ",propertyNames[i]); |
|---|
| 111 | + Collection copy = copy(((PersistentCollection)previous)); |
|---|
| 112 | + persister.setPropertyValue(entity,i,copy,source.getEntityMode()); |
|---|
| 113 | + } |
|---|
| 114 | } |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | Index: client/build.xml |
|---|
| 118 | =================================================================== |
|---|
| 119 | --- client/build.xml (revision 1033) |
|---|
| 120 | +++ client/build.xml (working copy) |
|---|
| 121 | @@ -56,4 +56,23 @@ |
|---|
| 122 | </groovy> |
|---|
| 123 | </target> |
|---|
| 124 | |
|---|
| 125 | + <target name="addtogroup" depends="prepare,load-groovy"> |
|---|
| 126 | + <groovy> |
|---|
| 127 | + if (properties["omero.rootpass"]==null) ant.fail("No root password defined. See etc/local.properties"); |
|---|
| 128 | + e = new ome.model.meta.Experimenter() |
|---|
| 129 | + g = new ome.model.meta.ExperimenterGroup() |
|---|
| 130 | + user = System.getProperty("user.name") |
|---|
| 131 | + println "Please enter login name: [${user}]" |
|---|
| 132 | + e.omeName = System.in.readLine() |
|---|
| 133 | + if (e.omeName == null || e.omeName.length() == 0) e.omeName = user |
|---|
| 134 | + println "Please enter target group:" |
|---|
| 135 | + g.name = System.in.readLine() |
|---|
| 136 | + l = new ome.system.Login("root",properties["omero.rootpass"]) |
|---|
| 137 | + sf = new ome.system.ServiceFactory(l) |
|---|
| 138 | + e = sf.getQueryService().findByExample(e) |
|---|
| 139 | + g = sf.getQueryService().findByExample(g) |
|---|
| 140 | + sf.getAdminService().addGroups(e,[g] as Object[]) |
|---|
| 141 | + </groovy> |
|---|
| 142 | + </target> |
|---|
| 143 | + |
|---|
| 144 | </project> |
|---|