unstick r1872712

Revision 1872712

Date:
2020/01/13 15:34:31
Author:
gk
Revision Log:
- removed id-check in group/permission/role spi managers - hibernate, mysql and other databases may use native generator/autoincrement (effectively the old implementation had implicitely the same result with it's faulty exception condition)
- updated api tests to JUnit5
- Torque added new Test TurbineACLFactoryTest.java
- Torque: moved in torque new model + old model test into package model
- Torque: fixed missing interface for Role/Group/Permission DefaultAbstractTurbine*Managers by applying existing TurbineUserGroupRoleModelPeerMapper and adding new interface TurbineRolePermissionPeerMapper.
- Updated changes.xml
Files:

Legend:

 
Added
 
Removed
 
Modified
  • turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractGroupManager.java

     
    155 155 {
    156 156 throw new DataBackendException("Could not create a group with empty name!");
    157 157 }
    158 if (group.getId() != null)
    159 {
    160 throw new DataBackendException("Could not create a group with an id of null!");
    161 }
    158 // if (group.getId() == null)
    159 // {
    160 // throw new DataBackendException("Could not create a group with an id of null!");
    161 // }
    162 162 groupExists = checkExists(group);
    163 163 if (!groupExists)
    164 164 {
  • turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractPermissionManager.java

     
    35 35 */
    36 36 public abstract class AbstractPermissionManager extends AbstractEntityManager implements PermissionManager
    37 37 {
    38 /**
    39 *
    40 */
    41 private static final long serialVersionUID = 1L;
    42
    38 43 protected abstract <T extends Permission> T persistNewPermission(T permission) throws DataBackendException;
    39 44
    40 45 /**
     
    150 155 {
    151 156 throw new DataBackendException("Could not create a permission with empty name!");
    152 157 }
    153 if (permission.getId() != null)
    154 {
    155 throw new DataBackendException("Could not create a permission with an id of null!");
    156 }
    158 // if (permission.getId() == null)
    159 // {
    160 // throw new DataBackendException("Could not create a permission with an id of null!");
    161 // }
    157 162 try
    158 163 {
    159 164 permissionExists = checkExists(permission);
  • turbine/fulcrum/trunk/security/api/src/java/org/apache/fulcrum/security/spi/AbstractRoleManager.java

     
    162 162 {
    163 163 throw new DataBackendException("Could not create a role with empty name!");
    164 164 }
    165 if (role.getId() != null)
    166 {
    167 throw new DataBackendException("Could not create a role with an id of null!");
    168 }
    165 // if (role.getId() == null)
    166 // {
    167 // throw new DataBackendException("Could not create a role with an id of null!");
    168 // }
    169 169 try
    170 170 {
    171 171 roleExists = checkExists(role);
  • turbine/fulcrum/trunk/security/api/src/test/org/apache/fulcrum/security/authenticator/CryptoAuthenticatorTest.java

     
    23 23
    24 24 import org.apache.fulcrum.security.entity.User;
    25 25 import org.apache.fulcrum.security.model.dynamic.entity.impl.DynamicUserImpl;
    26 import org.apache.fulcrum.testcontainer.BaseUnit4Test;
    27 import org.junit.Before;
    28 import org.junit.Test;
    26 import org.apache.fulcrum.testcontainer.BaseUnit5Test;
    29 27
    28 import org.junit.jupiter.api.BeforeEach;
    29 import org.junit.jupiter.api.Test;
    30
    30 31 /**
    31 32 *
    32 33 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    33 34 * @version $Id$
    34 35 */
    35 public class CryptoAuthenticatorTest extends BaseUnit4Test
    36 public class CryptoAuthenticatorTest extends BaseUnit5Test
    36 37
    37 38 {
    38 39 private static final String preDefinedInput = "Oeltanks";
    39 40 private static final String preDefinedResult = "XBSqev4ilv7P7852G2rL5WgX3FLy8VzfOY+tVq+xjek=";
    40 41
    41 42
    42 @Before
    43 @BeforeEach
    43 44 public void setUp()
    44 45 {
    45 46 try
  • turbine/fulcrum/trunk/security/api/src/test/org/apache/fulcrum/security/authenticator/NoOpAuthenticatorTest.java

     
    1 1 package org.apache.fulcrum.security.authenticator;
    2 2
    3 import static org.junit.jupiter.api.Assertions.assertTrue;
    4
    3 5 /*
    4 6 * Licensed to the Apache Software Foundation (ASF) under one
    5 7 * or more contributor license agreements. See the NOTICE file
     
    22 24
    23 25 import org.apache.fulcrum.security.entity.User;
    24 26 import org.apache.fulcrum.security.model.dynamic.entity.impl.DynamicUserImpl;
    27 import org.junit.jupiter.api.Test;
    25 28
    26 import static org.junit.Assert.*;
    27 import org.junit.Test;
    28 29
    29 30 /**
    30 31 *
  • turbine/fulcrum/trunk/security/api/src/test/org/apache/fulcrum/security/authenticator/TextMatchAuthenticatorTest.java

     
    1 1 package org.apache.fulcrum.security.authenticator;
    2 2
    3 import static org.junit.jupiter.api.Assertions.assertFalse;
    4 import static org.junit.jupiter.api.Assertions.assertTrue;
    5
    3 6 /*
    4 7 * Licensed to the Apache Software Foundation (ASF) under one
    5 8 * or more contributor license agreements. See the NOTICE file
     
    22 25
    23 26 import org.apache.fulcrum.security.entity.User;
    24 27 import org.apache.fulcrum.security.model.dynamic.entity.impl.DynamicUserImpl;
    28 import org.junit.jupiter.api.Test;
    25 29
    26 import static org.junit.Assert.*;
    27 import org.junit.Test;
    28 30
    29 31 /**
    30 32 *
  • turbine/fulcrum/trunk/security/api/src/test/org/apache/fulcrum/security/entity/impl/SecurityEntityImplTest.java

     
    1 1 package org.apache.fulcrum.security.entity.impl;
    2 2
    3 import static org.junit.jupiter.api.Assertions.assertEquals;
    4 import static org.junit.jupiter.api.Assertions.fail;
    5
    3 6 /*
    4 7 * Licensed to the Apache Software Foundation (ASF) under one
    5 8 * or more contributor license agreements. See the NOTICE file
     
    20 23 */
    21 24
    22 25 import org.apache.fulcrum.security.entity.SecurityEntity;
    23 import static org.junit.Assert.*;
    24 import org.junit.Test;
    26 import org.junit.jupiter.api.Test;
    25 27
    26 28 /**
    27 29 * Test the SecurityEntityImple
  • turbine/fulcrum/trunk/security/api/src/test/org/apache/fulcrum/security/model/ACLFactoryTest.java

     
    46 46 import org.apache.fulcrum.security.model.turbine.entity.impl.TurbinePermissionImpl;
    47 47 import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineRoleImpl;
    48 48 import org.apache.fulcrum.security.model.turbine.entity.impl.TurbineUserImpl;
    49 import org.apache.fulcrum.testcontainer.BaseUnitTest;
    49 import org.apache.fulcrum.testcontainer.BaseUnit5Test;
    50 50
    51 import static org.junit.jupiter.api.Assertions.assertTrue;
    52 import org.junit.jupiter.api.Test;
    53
    51 54 /**
    52 55 *
    53 56 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
    54 57 * @version $Id$
    55 58 */
    56 public class ACLFactoryTest extends BaseUnitTest
    59 public class ACLFactoryTest extends BaseUnit5Test
    57 60 {
    58 61
    59 public ACLFactoryTest(String arg0)
    62 public ACLFactoryTest()
    60 63 {
    61 super(arg0);
    62 64 }
    63 65
    66 @Test
    64 67 public void testCreatingTurbineACLandModel() throws Exception
    65 68 {
    66 69 this.setRoleFileName("src/test/TurbineACLRoleModelConfig.xml");
     
    96 99 assertTrue(tacl.hasPermission(permission, group));
    97 100 }
    98 101
    102 @Test
    99 103 public void testCreatingDynamicACL() throws Exception
    100 104 {
    101 105 this.setRoleFileName("src/test/DynamicACLRoleConfig.xml");
     
    127 131 assertTrue(dacl.hasPermission(permission));
    128 132 }
    129 133
    134 @Test
    130 135 public void testCreatingBasicACL() throws Exception
    131 136 {
    132 137 this.setRoleFileName("src/test/BasicACLRoleConfig.xml");
  • turbine/fulcrum/trunk/security/api/src/test/org/apache/fulcrum/security/model/turbine/test/AbstractTurbineModelManagerTest.java

     
    92 92 permission.setName("ANSWER_PHONE");
    93 93 permissionManager.addPermission(permission);
    94 94 role = roleManager.getRoleInstance("RECEPTIONIST");
    95 //role.setId(new Integer(1));
    95 96 roleManager.addRole(role);
    96 97 modelManager.grant(role, permission);
    97 98 role = roleManager.getRoleById(role.getId());
     
    105 106 Permission permission = securityService.getPermissionManager().getPermissionInstance();
    106 107 permission.setName("ANSWER_FAX");
    107 108 securityService.getPermissionManager().addPermission(permission);
    108 role = roleManager.getRoleInstance("SECRETARY");
    109 role = roleManager.getRoleInstance("SECRETARY");
    110 //role.setId(new Integer(1));
    109 111 roleManager.addRole(role);
    110 112 modelManager.grant(role, permission);
    111 113 role = roleManager.getRoleById(role.getId());
     
    128 130 permission = securityService.getPermissionManager().addPermission(permission);
    129 131 permission2 = securityService.getPermissionManager().addPermission(permission2);
    130 132 role = roleManager.getRoleInstance("ANOTHERSECRETARY");
    133 //role.setId(new Integer(1));
    131 134 role = roleManager.addRole(role);
    132 135 modelManager.grant(role, permission);
    133 136 modelManager.grant(role, permission2);
     
    154 157 securityService.getPermissionManager().addPermission(permission);
    155 158 securityService.getPermissionManager().addPermission(permission2);
    156 159 role = roleManager.getRoleInstance("HELPER");
    160 //role.setId(new Integer(1));
    157 161 roleManager.addRole(role);
    158 162 modelManager.grant(role, permission);
    159 163 modelManager.grant(role, permission2);
     
    173 177 securityService.getGroupManager().addGroup(group);
    174 178 Role role = securityService.getRoleManager().getRoleInstance();
    175 179 role.setName("TEST_REVOKEALLUSER_ROLE");
    180 //role.setId(new Integer(1));
    176 181 role = securityService.getRoleManager().addRole(role);
    177 182
    178 183 Group group2 = securityService.getGroupManager().getGroupInstance();
    179 184 group2.setName("TEST_REVOKEALLUSER_GROUP2");
    185 //group2.setId(new Integer(1));
    180 186 securityService.getGroupManager().addGroup(group2);
    181 187 Role role2 = securityService.getRoleManager().getRoleInstance();
    182 188 role2.setName("TEST_REVOKEALLUSER_ROLE2");
    189 //role2.setId(new Integer(2));
    183 190 role2 = securityService.getRoleManager().addRole(role2);
    184 191
    185 192 String username = "calvin";
     
    281 288 {
    282 289 Permission permission = permissionManager.getPermissionInstance();
    283 290 permission.setName("ANSWER_PHONE__");
    291 //permission.setId(new Integer (1));
    284 292 permissionManager.addPermission(permission);
    285 293
    286 294 Permission permission2 = permissionManager.getPermissionInstance();
    287 295 permission2.setName("ANSWER_PHONE__2");
    296 // TurbineHibernate.hbm.xml has <generator class="native" for id, throws org.hibernate.HibernateException:
    297 // identifier of an instance of org.apache.fulcrum.security.model.turbine.entity.impl.TurbinePermissionImpl was altered from 1 to 2
    298 //permission.setId(new Integer (2));
    288 299 permissionManager.addPermission(permission2);
    289 300
    290 301 role = roleManager.getRoleInstance("RECEPTIONIST__");
     
    292 303
    293 304 Group group = securityService.getGroupManager().getGroupInstance();
    294 305 group.setName("TEST_GROUP__");
    306 //group.setId(new Integer(1));
    295 307 securityService.getGroupManager().addGroup(group);
    296 308 Role role = roleManager.getRoleInstance();
    309
    297 310 role.setName("TEST_Role__");
    311 //role.setId(new Integer(1));
    298 312 roleManager.addRole(role);
    299 313 User user = userManager.getUserInstance("Clint__");
    300 314 userManager.addUser(user, "clint");
  • turbine/fulcrum/trunk/security/src/changes/changes.xml

     
    23 23 <author email="epugh@upstate.com">Eric Pugh</author>
    24 24 </properties>
    25 25 <body>
    26 <release version="1.1.3" date="in Subversion">
    26 <release version="2.0.0" date="in Subversion">
    27 <action type="update" dev="gk">
    28 Torque sub project:
    29 - Update to Torque 4.1, using PeerInterface in schema, removed classes as now generated with PeerInterface.
    30 - add TorqueException to method (TODO DataBackendException wanted)
    31 - Dbcp2 update to v2.7.0
    32 </action>
    33 <action type="update" dev="gk">
    34 - log4j2 (hibernate needs mapping 1.2 to 2)
    35 </action>
    36 </release>
    37 <release version="1.1.3" date="2019-02-23">
    27 38 <action type="update" dev="jp">
    28 39 Update to commons-lang3, Java 8 by default
    29 40 </action>
  • turbine/fulcrum/trunk/security/torque/schema/fulcrum-turbine-default-schema.xml

     
    30 30 defaultIdMethod="none" defaultJavaType="object"
    31 31 xmlns="http://db.apache.org/torque/4.0/templates/database"
    32 32 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    33 xsi:schemaLocation="http://db.apache.org/torque/4.0/templates/database
    34 http://db.apache.org/torque/4.0/templates/database.xsd">
    33 xsi:schemaLocation="http://db.apache.org/torque/4.1/templates/database
    34 http://db.apache.org/torque/4.1/templates/database.xsd">
    35 35
    36 36 <!--
    37 after Torque 4.1 is released, add attribute peerInterface="org.apache.fulcrum.security.torque.peer.TorqueTurbinePeer"
    37 added after Torque 4.1 release attribute peerInterface="org.apache.fulcrum.security.torque.peer.TorqueTurbinePeer"
    38 38 to tables TURBINE_PERMISSION,TURBINE_ROLE,TURBINE_GROUP,TURBINE_USER, cft. https://issues.apache.org/jira/browse/TRB-92 and https://issues.apache.org/jira/browse/TORQUE-309.
    39 39 -->
    40 40 <table name="TURBINE_PERMISSION" javaName="TurbinePermission" idMethod="native"
     
    91 91 </table>
    92 92
    93 93 <!-- Turbine Security Model -->
    94 <table name="TURBINE_ROLE_PERMISSION" javaName="TurbineRolePermission" idMethod="none">
    94 <table name="TURBINE_ROLE_PERMISSION" javaName="TurbineRolePermission" idMethod="none"
    95 interface="org.apache.fulcrum.security.torque.peer.TurbineRolePermissionPeerMapper">
    95 96 <column name="ROLE_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
    96 97 <column name="PERMISSION_ID" required="true" primaryKey="true" type="INTEGER" javaType="object"/>
    97 98
  • turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/peer/TurbineRolePermissionPeerMapper.java

     
    1 package org.apache.fulcrum.security.torque.peer;
    2 /*
    3 * Licensed to the Apache Software Foundation (ASF) under one
    4 * or more contributor license agreements. See the NOTICE file
    5 * distributed with this work for additional information
    6 * regarding copyright ownership. The ASF licenses this file
    7 * to you under the Apache License, Version 2.0 (the
    8 * "License"); you may not use this file except in compliance
    9 * with the License. You may obtain a copy of the License at
    10 *
    11 * http://www.apache.org/licenses/LICENSE-2.0
    12 *
    13 * Unless required by applicable law or agreed to in writing,
    14 * software distributed under the License is distributed on an
    15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16 * KIND, either express or implied. See the License for the
    17 * specific language governing permissions and limitations
    18 * under the License.
    19 */
    20 import java.sql.Connection;
    21
    22 import org.apache.fulcrum.security.entity.Permission;
    23 import org.apache.fulcrum.security.entity.Role;
    24 import org.apache.fulcrum.security.torque.om.TurbinePermission;
    25 import org.apache.torque.TorqueException;
    26
    27 /**
    28 * This extension to the marker interface {@linkplain Peer} is to allow for swappable Peer implementations
    29 * in Turbine Torque Manager Implementations.
    30 *
    31 * @param <T> The data object type used by the Torque PeerImpl class.
    32 *
    33 * @author <a href="mailto:gk@apache.org">Georg Kallidis</a>
    34 * @version $Id$
    35 */
    36 public interface TurbineRolePermissionPeerMapper
    37
    38 {
    39
    40 /**
    41 * Returns the associated TurbineRole object.
    42 * If it was not retrieved before, the object is retrieved from
    43 * the database
    44 *
    45 * @return the associated TurbineRole object
    46 * @throws TorqueException if any database error occurs when reading from the database fails.
    47 */
    48 Role getTurbineRole()
    49 throws TorqueException;
    50
    51 /**
    52 * Return the associated TurbineRole object
    53 * If it was not retrieved before, the object is retrieved from
    54 * the database using the passed connection
    55 *
    56 * @param connection the connection used to retrieve the associated object
    57 * from the database, if it was not retrieved before
    58 * @return the associated TurbineRole object
    59 * @throws TorqueException if any database error occurs
    60 */
    61 Role getTurbineRole( Connection connection )
    62 throws TorqueException;
    63
    64 /**
    65 * Returns the associated TurbinePermission object.
    66 * If it was not retrieved before, the object is retrieved from
    67 * the database
    68 *
    69 * @return the associated TurbinePermission object
    70 * @throws TorqueException when reading from the database fails.
    71 */
    72 Permission getTurbinePermission() throws TorqueException;
    73
    74 /**
    75 * Return the associated TurbinePermission object
    76 * If it was not retrieved before, the object is retrieved from
    77 * the database using the passed connection
    78 *
    79 * @param connection the connection used to retrieve the associated object
    80 * from the database, if it was not retrieved before
    81 * @return the associated TurbinePermission object
    82 * @throws TorqueException If a problem occurs with the get[$filedType] method.
    83 */
    84 public TurbinePermission getTurbinePermission(Connection connection)
    85 throws TorqueException;
    86
    87 }
  • turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/peer/TurbineUserGroupRoleModelPeerMapper.java

     
    25 25 import org.apache.torque.TorqueException;
    26 26
    27 27 /**
    28 * This interface allows to retrieve user, group, role relationships either from custom or the default OM in @link org.apache.fulcrum.security.torque.om.
    28 * This interface allows to retrieve user, group, role relationships either from custom or the default OM in
    29 29 *
    30 * @author gkallidis
    30 * @link org.apache.fulcrum.security.torque.om.
    31 *
    32 * @author gk
    33 * @Id $Id$
    31 34 *
    32 35 */
    33 36 public interface TurbineUserGroupRoleModelPeerMapper
  • turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/DefaultAbstractTurbineGroup.java

     
    26 26 import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole;
    27 27 import org.apache.fulcrum.security.torque.om.TurbineGroupPeer;
    28 28 import org.apache.fulcrum.security.torque.om.TurbineUserGroupRolePeer;
    29 import org.apache.fulcrum.security.torque.peer.TurbineUserGroupRoleModelPeerMapper;
    29 30 import org.apache.fulcrum.security.torque.security.turbine.TorqueAbstractTurbineTurbineSecurityEntity;
    30 31 import org.apache.fulcrum.security.util.DataBackendException;
    31 32 import org.apache.torque.TorqueException;
     
    56 57 *
    57 58 * @return a list of User/Group/Role relations
    58 59 */
    59 protected List<org.apache.fulcrum.security.torque.om.TurbineUserGroupRole> getTurbineUserGroupRolesJoinTurbineRole(Criteria criteria, Connection con)
    60 throws TorqueException
    60 protected <T extends TurbineUserGroupRoleModelPeerMapper> List<T> getTurbineUserGroupRolesJoinTurbineRole(Criteria criteria, Connection con)
    61 throws TorqueException, DataBackendException
    61 62 {
    62 63 criteria.and(TurbineUserGroupRolePeer.GROUP_ID, getEntityId() );
    63 return TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria, con);
    64 return (List<T>) TurbineUserGroupRolePeer.doSelectJoinTurbineRole(criteria, con);
    64 65 }
    65 66
    66 67 @Override
     
    79 80 try {
    80 81 if (!lazy) {
    81 82 Set<TurbineUserGroupRole> userGroupRoleSet = new HashSet<TurbineUserGroupRole>();
    82
    83 List<org.apache.fulcrum.security.torque.om.TurbineUserGroupRole> ugrs = getTurbineUserGroupRolesJoinTurbineRole(new Criteria(), con);
    83
    84 List<TurbineUserGroupRoleModelPeerMapper> ugrs = getTurbineUserGroupRolesJoinTurbineRole(new Criteria(), con);
    84 85
    85 for (org.apache.fulcrum.security.torque.om.TurbineUserGroupRole ttugr : ugrs)
    86 for (TurbineUserGroupRoleModelPeerMapper ttugr : ugrs)
    86 87 {
    87 88 TurbineUserGroupRole ugr = new TurbineUserGroupRole();
    88 89 ugr.setGroup(this);
  • turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/DefaultAbstractTurbinePermission.java

     
    26 26 import org.apache.fulcrum.security.torque.om.TurbinePermissionPeer;
    27 27 import org.apache.fulcrum.security.torque.om.TurbineRolePermission;
    28 28 import org.apache.fulcrum.security.torque.om.TurbineRolePermissionPeer;
    29 import org.apache.fulcrum.security.torque.peer.TurbineRolePermissionPeerMapper;
    29 30 import org.apache.fulcrum.security.torque.security.TorqueAbstractSecurityEntity;
    30 31 import org.apache.fulcrum.security.util.DataBackendException;
    31 32 import org.apache.fulcrum.security.util.RoleSet;
     
    59 60 *
    60 61 * @return a list of Role/Permission relations
    61 62 */
    62 protected List<TurbineRolePermission> getTurbineRolePermissionsJoinTurbineRole(Criteria criteria, Connection con)
    63 protected <T extends TurbineRolePermissionPeerMapper> List<T> getTurbineRolePermissionsJoinTurbineRole(Criteria criteria, Connection con)
    63 64 throws TorqueException
    64 65 {
    65 66 criteria.and(TurbineRolePermissionPeer.PERMISSION_ID, getEntityId() );
    66 return TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria, con);
    67 return (List<T>) TurbineRolePermissionPeer.doSelectJoinTurbineRole(criteria, con);
    67 68 }
    68 69
    69 70 /**
     
    155 156
    156 157 this.roleSet = new RoleSet();
    157 158
    158 List<TurbineRolePermission> rolepermissions = getTurbineRolePermissionsJoinTurbineRole(new Criteria(), con);
    159 List<TurbineRolePermissionPeerMapper> rolepermissions = getTurbineRolePermissionsJoinTurbineRole(new Criteria(), con);
    159 160
    160 for (TurbineRolePermission ttrp : rolepermissions)
    161 for (TurbineRolePermissionPeerMapper ttrp : rolepermissions)
    161 162 {
    162 163 roleSet.add(ttrp.getTurbineRole());
    163 164 }
  • turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/DefaultAbstractTurbineRole.java

     
    29 29 import org.apache.fulcrum.security.torque.om.TurbineRolePermission;
    30 30 import org.apache.fulcrum.security.torque.om.TurbineRolePermissionPeer;
    31 31 import org.apache.fulcrum.security.torque.om.TurbineUserGroupRolePeer;
    32 import org.apache.fulcrum.security.torque.peer.TurbineRolePermissionPeerMapper;
    33 import org.apache.fulcrum.security.torque.peer.TurbineUserGroupRoleModelPeerMapper;
    32 34 import org.apache.fulcrum.security.torque.security.turbine.TorqueAbstractTurbineTurbineSecurityEntity;
    33 35 import org.apache.fulcrum.security.util.DataBackendException;
    34 36 import org.apache.fulcrum.security.util.PermissionSet;
     
    63 65 *
    64 66 * @return a list of Role/Permission relations
    65 67 */
    66 protected List<TurbineRolePermission> getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria, Connection con)
    68 protected <T extends TurbineRolePermissionPeerMapper> List<T> getTurbineRolePermissionsJoinTurbinePermission(Criteria criteria, Connection con)
    67 69 throws TorqueException
    68 70 {
    69 71 criteria.and(TurbineRolePermissionPeer.ROLE_ID, getEntityId() );
    70 return TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria, con);
    72 return (List<T>) TurbineRolePermissionPeer.doSelectJoinTurbinePermission(criteria, con);
    71 73 }
    72 74
    73 75 /**
     
    82 84 *
    83 85 * @return a list of User/Group/Role relations
    84 86 */
    85 protected List<org.apache.fulcrum.security.torque.om.TurbineUserGroupRole> getTurbineUserGroupRolesJoinTurbineGroup(Criteria criteria, Connection con)
    86 throws TorqueException
    87 protected <T extends TurbineUserGroupRoleModelPeerMapper> List<T> getTurbineUserGroupRolesJoinTurbineGroup(Criteria criteria, Connection con)
    88 throws TorqueException, DataBackendException
    87 89 {
    88 90 criteria.and(TurbineUserGroupRolePeer.ROLE_ID, getEntityId() );
    89 return TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(criteria, con);
    91 return (List<T>) TurbineUserGroupRolePeer.doSelectJoinTurbineGroup(criteria, con);
    90 92 }
    91 93
    92 94 /**
     
    178 180 this.permissionSet = new PermissionSet();
    179 181
    180 182 try {
    181 List<TurbineRolePermission> rolepermissions = getTurbineRolePermissionsJoinTurbinePermission(new Criteria(), con);
    183 List<TurbineRolePermissionPeerMapper> rolepermissions = getTurbineRolePermissionsJoinTurbinePermission(new Criteria(), con);
    182 184
    183 for (TurbineRolePermission ttrp : rolepermissions)
    185 for (TurbineRolePermissionPeerMapper ttrp : rolepermissions)
    184 186 {
    185 187 permissionSet.add(ttrp.getTurbinePermission());
    186 188 }
     
    188 190 if (!lazy) {
    189 191 Set<TurbineUserGroupRole> userGroupRoleSet = new HashSet<TurbineUserGroupRole>();
    190 192
    191 List<org.apache.fulcrum.security.torque.om.TurbineUserGroupRole> ugrs = getTurbineUserGroupRolesJoinTurbineGroup(new Criteria(), con);
    193 List<TurbineUserGroupRoleModelPeerMapper> ugrs = getTurbineUserGroupRolesJoinTurbineGroup(new Criteria(), con);
    192 194
    193 for (org.apache.fulcrum.security.torque.om.TurbineUserGroupRole ttugr : ugrs)
    195 for (TurbineUserGroupRoleModelPeerMapper ttugr : ugrs)
    194 196 {
    195 197 TurbineUserGroupRole ugr = new TurbineUserGroupRole();
    196 198 ugr.setRole(this);
  • turbine/fulcrum/trunk/security/torque/src/java/org/apache/fulcrum/security/torque/turbine/DefaultAbstractTurbineUser.java

     
    120 120 public void retrieveAttachedObjects( Connection con )
    121 121 throws DataBackendException, TorqueException
    122 122 {
    123 retrieveAttachedObjects( con, false ); //false
    123 retrieveAttachedObjects( con, false );
    124 124 }
    125 125
    126 126 /* (non-Javadoc)
  • turbine/fulcrum/trunk/security/torque/src/test/log4j2-test.xml

     
    22 22 <Console name="console" target="SYSTEM_OUT">
    23 23 <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
    24 24 </Console>
    25 <File name="fulcrum" fileName="target/fulcrum.log">
    25 <File name="fulcrum" fileName="./target/fulcrum.log">
    26 26 <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
    27 27 </File>
    28 <File name="torque" fileName="target/torque.log">
    28 <File name="torque" fileName="./target/torque.log">
    29 29 <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
    30 30 </File>
    31 <File name="avalon" fileName="target/avalon.log">
    31 <File name="avalon" fileName="./target/avalon.log">
    32 32 <PatternLayout pattern="%d [%t] %-5p %c - %m%n"/>
    33 33 </File>
    34 34 </Appenders>
  • turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/turbine/model/TorquePeerTurbineModelManagerTest.java

     
    1 package org.apache.fulcrum.security.torque.turbine.model;
    2 /*
    3 * Licensed to the Apache Software Foundation (ASF) under one
    4 * or more contributor license agreements. See the NOTICE file
    5 * distributed with this work for additional information
    6 * regarding copyright ownership. The ASF licenses this file
    7 * to you under the Apache License, Version 2.0 (the
    8 * "License"); you may not use this file except in compliance
    9 * with the License. You may obtain a copy of the License at
    10 *
    11 * http://www.apache.org/licenses/LICENSE-2.0
    12 *
    13 * Unless required by applicable law or agreed to in writing,
    14 * software distributed under the License is distributed on an
    15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16 * KIND, either express or implied. See the License for the
    17 * specific language governing permissions and limitations
    18 * under the License.
    19 */
    20
    21 import static org.junit.jupiter.api.Assertions.assertNotNull;
    22 import static org.junit.jupiter.api.Assertions.assertTrue;
    23 import static org.junit.jupiter.api.Assertions.fail;
    24
    25 import org.apache.fulcrum.security.SecurityService;
    26 import org.apache.fulcrum.security.model.turbine.test.AbstractTurbineModelManagerTest;
    27 import org.apache.fulcrum.security.torque.HsqlDB;
    28 import org.apache.fulcrum.security.torque.TorqueAbstractGroupManager;
    29 import org.apache.fulcrum.security.torque.TorqueAbstractPermissionManager;
    30 import org.apache.fulcrum.security.torque.TorqueAbstractRoleManager;
    31 import org.apache.fulcrum.security.torque.TorqueAbstractUserManager;
    32 import org.apache.fulcrum.security.torque.om.TorqueTurbineGroupPeer;
    33 import org.apache.fulcrum.security.torque.om.TorqueTurbinePermissionPeer;
    34 import org.apache.fulcrum.security.torque.om.TorqueTurbineRolePeer;
    35 import org.apache.fulcrum.security.torque.om.TorqueTurbineRolePermissionPeer;
    36 import org.apache.fulcrum.security.torque.om.TorqueTurbineUserGroupRolePeer;
    37 import org.apache.fulcrum.security.torque.om.TorqueTurbineUserPeer;
    38 import org.apache.fulcrum.security.torque.peer.PeerManagable;
    39 import org.apache.fulcrum.security.torque.peer.managers.PeerGroupManager;
    40 import org.apache.fulcrum.security.torque.peer.managers.PeerPermissionManager;
    41 import org.apache.fulcrum.security.torque.peer.managers.PeerRoleManager;
    42 import org.apache.fulcrum.security.torque.peer.managers.PeerUserManager;
    43 import org.apache.torque.TorqueException;
    44 import org.apache.torque.criteria.Criteria;
    45 import org.junit.jupiter.api.AfterEach;
    46 import org.junit.jupiter.api.BeforeEach;
    47 import org.junit.jupiter.api.Test;
    48
    49 /**
    50 * Test with @link {@link #customPeers} requires at least Torque version 4.1.
    51 *
    52 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
    53 * @author <a href="jh@byteaction.de">J&#252;rgen Hoffmann</a>
    54 * @version $Id$
    55 */
    56 public class TorquePeerTurbineModelManagerTest
    57 extends AbstractTurbineModelManagerTest
    58 {
    59 protected static HsqlDB hsqlDB = null;
    60
    61 public static boolean customPeers = false;
    62
    63 @BeforeEach
    64 public void setUp()
    65 throws Exception
    66 {
    67 try
    68 {
    69 hsqlDB = new HsqlDB( "src/test/fulcrum-turbine-schema.sql" );
    70 hsqlDB.addSQL( "src/test/id-table-schema.sql" );
    71 hsqlDB.addSQL( "src/test/fulcrum-turbine-schema-idtable-init.sql" );
    72
    73 this.setRoleFileName( "src/test/TurbineTorqueRoleConfig.xml" );
    74
    75 if ( customPeers )
    76 this.setConfigurationFileName( "src/test/TurbineTorqueWithPeersComponentConfig.xml" );
    77 else
    78 this.setConfigurationFileName( "src/test/TurbineTorqueComponentConfig.xml" );
    79
    80 // The successful Test requires that the PeerImpl classes (in configuration file) implement the interface
    81 // TorqueTurbinePeer,
    82 // cft. ClassCastException messages.
    83 // (interfaces could not yet automatically generated into Peers with Torque, cft JIRA Issue TORQUE-309).
    84
    85 securityService = (SecurityService) lookup( SecurityService.ROLE );
    86 super.setUp();
    87 }
    88 catch ( Exception e )
    89 {
    90 fail( e.toString() );
    91 }
    92
    93 }
    94
    95 @Test
    96 public void testCustomPeerSet()
    97 {
    98 if ( roleManager instanceof TorqueAbstractRoleManager )
    99 {
    100 assertTrue( ( (PeerRoleManager) roleManager ).getCustomPeer() == customPeers,
    101 "If a custom Peer for RoleManager should be tested, a peerClassName element should be set in the configuration file for roleManager." );
    102 }
    103 if ( roleManager instanceof PeerManagable )
    104 {
    105 assertNotNull( ( (PeerManagable) roleManager ).getPeerManager() );
    106 }
    107 if ( userManager instanceof TorqueAbstractUserManager )
    108 {
    109 assertTrue( ( (PeerUserManager) userManager ).getCustomPeer() == customPeers,
    110 "If a custom Peer for UserManager should be tested, a peerClassName element should be set in the configuration file for userManager." );
    111 }
    112 if ( userManager instanceof PeerManagable )
    113 {
    114 assertNotNull( ( (PeerManagable) userManager ).getPeerManager() );
    115 }
    116 if ( groupManager instanceof TorqueAbstractGroupManager )
    117 {
    118 assertTrue( ( (PeerGroupManager) groupManager ).getCustomPeer() == customPeers,
    119 "If a custom Peer for GroupManager should be tested, a peerClassName element should be set in the configuration file for groupManager." );
    120 }
    121 if ( groupManager instanceof PeerManagable )
    122 {
    123 assertNotNull( ( (PeerManagable) groupManager ).getPeerManager() );
    124 }
    125 if ( permissionManager instanceof TorqueAbstractPermissionManager )
    126 {
    127 assertTrue( ( (PeerPermissionManager) permissionManager ).getCustomPeer() == customPeers,
    128 "If a custom Peer for PermissionManager should be tested, a peerClassName element should be set in the configuration file for permissionManager." );
    129 }
    130 if ( permissionManager instanceof PeerManagable )
    131 {
    132 assertNotNull( ( (PeerManagable) permissionManager ).getPeerManager() );
    133 }
    134 }
    135
    136 @AfterEach
    137 public void tearDown()
    138 {
    139 // cleanup tables
    140 try
    141 {
    142 Criteria criteria = new Criteria();
    143 criteria.where( TorqueTurbineUserGroupRolePeer.USER_ID, -1, Criteria.GREATER_THAN );
    144 TorqueTurbineUserGroupRolePeer.doDelete( criteria );
    145
    146 criteria = new Criteria();
    147 criteria.where( TorqueTurbineRolePermissionPeer.ROLE_ID, 0, Criteria.GREATER_THAN );
    148 TorqueTurbineRolePermissionPeer.doDelete( criteria );
    149
    150 criteria = new Criteria();
    151 criteria.where( TorqueTurbineUserPeer.USER_ID, 0, Criteria.GREATER_THAN );
    152 TorqueTurbineUserPeer.doDelete( criteria );
    153
    154 criteria = new Criteria();
    155 criteria.where( TorqueTurbineGroupPeer.GROUP_ID, 0, Criteria.GREATER_THAN );
    156 TorqueTurbineGroupPeer.doDelete( criteria );
    157
    158 criteria = new Criteria();
    159 criteria.where( TorqueTurbineRolePeer.ROLE_ID, 0, Criteria.GREATER_THAN );
    160 TorqueTurbineRolePeer.doDelete( criteria );
    161
    162 criteria = new Criteria();
    163 criteria.where( TorqueTurbinePermissionPeer.PERMISSION_ID, 0, Criteria.GREATER_THAN );
    164 TorqueTurbinePermissionPeer.doDelete( criteria );
    165 }
    166 catch ( TorqueException e )
    167 {
    168 fail( e.toString() );
    169 }
    170
    171 modelManager = null;
    172 securityService = null;
    173 }
    174
    175 }
  • turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/turbine/model/TorqueTurbineModelManagerTest.java

     
    1 package org.apache.fulcrum.security.torque.turbine.model;
    2 /*
    3 * Licensed to the Apache Software Foundation (ASF) under one
    4 * or more contributor license agreements. See the NOTICE file
    5 * distributed with this work for additional information
    6 * regarding copyright ownership. The ASF licenses this file
    7 * to you under the Apache License, Version 2.0 (the
    8 * "License"); you may not use this file except in compliance
    9 * with the License. You may obtain a copy of the License at
    10 *
    11 * http://www.apache.org/licenses/LICENSE-2.0
    12 *
    13 * Unless required by applicable law or agreed to in writing,
    14 * software distributed under the License is distributed on an
    15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16 * KIND, either express or implied. See the License for the
    17 * specific language governing permissions and limitations
    18 * under the License.
    19 */
    20
    21
    22 import static org.junit.jupiter.api.Assertions.fail;
    23
    24 import org.apache.fulcrum.security.SecurityService;
    25 import org.apache.fulcrum.security.model.turbine.test.AbstractTurbineModelManagerTest;
    26 import org.apache.fulcrum.security.torque.HsqlDB;
    27 import org.apache.fulcrum.security.torque.om.TorqueTurbineGroupPeer;
    28 import org.apache.fulcrum.security.torque.om.TorqueTurbinePermissionPeer;
    29 import org.apache.fulcrum.security.torque.om.TorqueTurbineRolePeer;
    30 import org.apache.fulcrum.security.torque.om.TorqueTurbineRolePermissionPeer;
    31 import org.apache.fulcrum.security.torque.om.TorqueTurbineUserGroupRolePeer;
    32 import org.apache.fulcrum.security.torque.om.TorqueTurbineUserPeer;
    33 import org.apache.torque.TorqueException;
    34 import org.apache.torque.criteria.Criteria;
    35 import org.junit.jupiter.api.AfterEach;
    36 import org.junit.jupiter.api.BeforeEach;
    37
    38 /**
    39 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
    40 * @author <a href="jh@byteaction.de">J&#252;rgen Hoffmann</a>
    41 * @version $Id:$
    42 */
    43 public class TorqueTurbineModelManagerTest
    44 extends AbstractTurbineModelManagerTest
    45 {
    46 protected static HsqlDB hsqlDB = null;
    47
    48 @BeforeEach
    49 public void setUp() throws Exception
    50 {
    51 try
    52 {
    53 hsqlDB = new HsqlDB("src/test/fulcrum-turbine-schema.sql");
    54 hsqlDB.addSQL("src/test/id-table-schema.sql");
    55 hsqlDB.addSQL("src/test/fulcrum-turbine-schema-idtable-init.sql");
    56
    57 this.setRoleFileName("src/test/TurbineTorqueRoleConfig.xml");
    58 this.setConfigurationFileName("src/test/TurbineTorqueComponentConfig.xml");
    59 securityService = (SecurityService) lookup(SecurityService.ROLE);
    60 super.setUp();
    61 }
    62 catch (Exception e)
    63 {
    64 fail(e.toString());
    65 }
    66
    67 }
    68
    69 @AfterEach
    70 public void tearDown()
    71 {
    72 // cleanup tables
    73 try
    74 {
    75 Criteria criteria = new Criteria();
    76 criteria.where(TorqueTurbineUserGroupRolePeer.USER_ID, -1, Criteria.GREATER_THAN);
    77 TorqueTurbineUserGroupRolePeer.doDelete(criteria);
    78
    79 criteria = new Criteria();
    80 criteria.where(TorqueTurbineRolePermissionPeer.ROLE_ID, 0, Criteria.GREATER_THAN);
    81 TorqueTurbineRolePermissionPeer.doDelete(criteria);
    82
    83 criteria = new Criteria();
    84 criteria.where(TorqueTurbineUserPeer.USER_ID, 0, Criteria.GREATER_THAN);
    85 TorqueTurbineUserPeer.doDelete(criteria);
    86
    87 criteria = new Criteria();
    88 criteria.where(TorqueTurbineGroupPeer.GROUP_ID, 0, Criteria.GREATER_THAN);
    89 TorqueTurbineGroupPeer.doDelete(criteria);
    90
    91 criteria = new Criteria();
    92 criteria.where(TorqueTurbineRolePeer.ROLE_ID, 0, Criteria.GREATER_THAN);
    93 TorqueTurbineRolePeer.doDelete(criteria);
    94
    95 criteria = new Criteria();
    96 criteria.where(TorqueTurbinePermissionPeer.PERMISSION_ID, 0, Criteria.GREATER_THAN);
    97 TorqueTurbinePermissionPeer.doDelete(criteria);
    98 }
    99 catch (TorqueException e)
    100 {
    101 fail(e.toString());
    102 }
    103
    104 modelManager = null;
    105 securityService = null;
    106 }
    107
    108 }
  • turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/turbine/model/TurbineACLFactoryTest.java

     
    1 package org.apache.fulcrum.security.torque.turbine.model;
    2 /*
    3 * Licensed to the Apache Software Foundation (ASF) under one
    4 * or more contributor license agreements. See the NOTICE file
    5 * distributed with this work for additional information
    6 * regarding copyright ownership. The ASF licenses this file
    7 * to you under the Apache License, Version 2.0 (the
    8 * "License"); you may not use this file except in compliance
    9 * with the License. You may obtain a copy of the License at
    10 *
    11 * http://www.apache.org/licenses/LICENSE-2.0
    12 *
    13 * Unless required by applicable law or agreed to in writing,
    14 * software distributed under the License is distributed on an
    15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16 * KIND, either express or implied. See the License for the
    17 * specific language governing permissions and limitations
    18 * under the License.
    19 */
    20
    21 import static org.junit.jupiter.api.Assertions.assertTrue;
    22
    23 import org.apache.fulcrum.security.SecurityService;
    24 import org.apache.fulcrum.security.acl.AccessControlList;
    25 import org.apache.fulcrum.security.entity.Group;
    26 import org.apache.fulcrum.security.model.ACLFactory;
    27 import org.apache.fulcrum.security.model.ACLFactoryTest;
    28 import org.apache.fulcrum.security.model.turbine.TurbineAccessControlList;
    29 import org.apache.fulcrum.security.model.turbine.TurbineModelManager;
    30 import org.apache.fulcrum.security.model.turbine.entity.TurbineGroup;
    31 import org.apache.fulcrum.security.model.turbine.entity.TurbinePermission;
    32 import org.apache.fulcrum.security.model.turbine.entity.TurbineRole;
    33 import org.apache.fulcrum.security.model.turbine.entity.TurbineUser;
    34 import org.apache.fulcrum.security.model.turbine.entity.TurbineUserGroupRole;
    35 import org.apache.fulcrum.security.torque.HsqlDB;
    36 import org.apache.fulcrum.testcontainer.BaseUnit5Test;
    37 import org.junit.jupiter.api.BeforeEach;
    38 import org.junit.jupiter.api.Test;
    39
    40 /**
    41 * Test user with attached object (user-role-goup relationship)
    42 *
    43 * Compare difference to {@link ACLFactoryTest}.
    44 *
    45 * @author <a href="mailto:gk@apache.org">Georg Kallidis</a>
    46 * @version $Id$
    47 */
    48 public class TurbineACLFactoryTest extends BaseUnit5Test
    49
    50 {
    51 protected static HsqlDB hsqlDB = null;
    52
    53 protected SecurityService securityService;
    54
    55 @BeforeEach
    56 public void setup() throws Exception {
    57
    58 hsqlDB = new HsqlDB( "src/test/fulcrum-turbine-default-schema.sql" );
    59
    60 this.setRoleFileName( "src/test/TurbineTorqueRoleConfig.xml" );
    61 this.setConfigurationFileName( "src/test/TurbineDefaultWithPeersComponentConfig.xml" );
    62
    63 securityService = (SecurityService) lookup( SecurityService.ROLE );
    64
    65 }
    66
    67 @Test
    68 public void testCreatingTurbineACLandModel() throws Exception
    69 {
    70
    71 ACLFactory factory = (ACLFactory) lookup(ACLFactory.ROLE);
    72
    73 TurbineModelManager modelManager = (TurbineModelManager) lookup(TurbineModelManager.ROLE);
    74 assertTrue(modelManager.getGlobalGroupName().equals("global"));
    75
    76 Group global = securityService.getGroupManager().getGroupInstance("global");
    77 global.setId(new Integer(1));
    78 securityService.getGroupManager().addGroup(global);
    79
    80 TurbineUser user = securityService.getUserManager().getUserInstance("Bob");
    81 user.setId(new Integer(1));
    82 securityService.getUserManager().addUser(user, "mypw");
    83
    84 TurbineGroup group = securityService.getGroupManager().getGroupInstance("group1");
    85 group.setId(new Integer(2));
    86 securityService.getGroupManager().addGroup(group);
    87
    88 TurbineRole role = securityService.getRoleManager().getRoleInstance();
    89 role.setName("role1");
    90 role.setId(new Integer(1));
    91 securityService.getRoleManager().addRole( role );
    92
    93 TurbinePermission permission = securityService.getPermissionManager().getPermissionInstance();
    94 permission.setName("permission1");
    95 permission.setId(new Integer(1));
    96 securityService.getPermissionManager().addPermission(permission);
    97
    98 role.addPermission(permission);
    99
    100 // need to save it as TurbineAccessControlListImpl refreshes role permission set!
    101 securityService.<TurbineModelManager> getModelManager().grant(role, permission);
    102
    103 TurbineUserGroupRole ugr = new TurbineUserGroupRole();
    104 ugr.setGroup(group);
    105 ugr.setRole(role);
    106 ugr.setUser(user);
    107 user.addUserGroupRole(ugr);
    108
    109 securityService.<TurbineModelManager> getModelManager().grant( user, group, role );
    110
    111 //securityService.getUserManager().saveUser(user);
    112
    113 AccessControlList acl = factory.getAccessControlList(user);
    114
    115 assertTrue(acl instanceof TurbineAccessControlList);
    116
    117 TurbineAccessControlList tacl = (TurbineAccessControlList) acl;
    118
    119 assertTrue(tacl.hasPermission(permission, group));
    120 }
    121
    122 }
  • turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/turbine/model/TurbineDefaultModelManagerLazyTest.java

     
    1 package org.apache.fulcrum.security.torque.turbine.model;
    2 /*
    3 * Licensed to the Apache Software Foundation (ASF) under one
    4 * or more contributor license agreements. See the NOTICE file
    5 * distributed with this work for additional information
    6 * regarding copyright ownership. The ASF licenses this file
    7 * to you under the Apache License, Version 2.0 (the
    8 * "License"); you may not use this file except in compliance
    9 * with the License. You may obtain a copy of the License at
    10 *
    11 * http://www.apache.org/licenses/LICENSE-2.0
    12 *
    13 * Unless required by applicable law or agreed to in writing,
    14 * software distributed under the License is distributed on an
    15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16 * KIND, either express or implied. See the License for the
    17 * specific language governing permissions and limitations
    18 * under the License.
    19 */
    20
    21 import static org.junit.jupiter.api.Assertions.fail;
    22
    23 import java.sql.Connection;
    24 import java.sql.SQLException;
    25
    26 import org.apache.fulcrum.security.SecurityService;
    27 import org.apache.fulcrum.security.model.turbine.test.AbstractTurbineModelManagerTest;
    28 import org.apache.fulcrum.security.torque.HsqlDB;
    29 import org.apache.fulcrum.security.torque.om.TurbineGroupPeer;
    30 import org.apache.fulcrum.security.torque.om.TurbinePermissionPeer;
    31 import org.apache.fulcrum.security.torque.om.TurbineRolePeer;
    32 import org.apache.fulcrum.security.torque.om.TurbineRolePermissionPeer;
    33 import org.apache.fulcrum.security.torque.om.TurbineUserGroupRolePeer;
    34 import org.apache.fulcrum.security.torque.om.TurbineUserPeer;
    35 import org.apache.torque.TorqueException;
    36 import org.apache.torque.criteria.Criteria;
    37 import org.apache.torque.util.Transaction;
    38 import org.junit.jupiter.api.AfterEach;
    39 import org.junit.jupiter.api.BeforeEach;
    40
    41 /**
    42 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
    43 * @author <a href="jh@byteaction.de">J&#252;rgen Hoffmann</a>
    44 * @version $Id$
    45 */
    46 public class TurbineDefaultModelManagerLazyTest
    47 extends AbstractTurbineModelManagerTest
    48 {
    49 protected static HsqlDB hsqlDB = null;
    50
    51 @BeforeEach
    52 public void setUp()
    53 throws Exception
    54 {
    55
    56 try
    57 {
    58 hsqlDB = new HsqlDB( "src/test/fulcrum-turbine-default-schema.sql" );
    59 // we do not need id-broker,set native in schema and added identity in hsql
    60 // same for both flavors
    61 this.setRoleFileName( "src/test/TurbineTorqueRoleConfig.xml" );
    62 // we have to use declared peers
    63 this.setConfigurationFileName( "src/test/TurbineDefaultLazyWithPeersComponentConfig.xml" );
    64 securityService = (SecurityService) lookup( SecurityService.ROLE );
    65 super.setUp();
    66 }
    67 catch ( Exception e )
    68 {
    69 fail( e.toString() );
    70 }
    71
    72 }
    73
    74 @AfterEach
    75 public void tearDown()
    76 {
    77 // cleanup tables
    78 Connection con = null;
    79 try
    80 {
    81 con = Transaction.begin();// "default"
    82
    83 Criteria criteria = new Criteria();
    84 criteria.where( TurbineUserGroupRolePeer.USER_ID, -1, Criteria.GREATER_THAN );
    85
    86 TurbineUserGroupRolePeer.doDelete( criteria, con );
    87
    88 criteria = new Criteria();
    89 criteria.where( TurbineRolePermissionPeer.ROLE_ID, -1, Criteria.GREATER_THAN );
    90 TurbineRolePermissionPeer.doDelete( criteria, con );
    91
    92 criteria = new Criteria();
    93 criteria.where( TurbineUserPeer.USER_ID, 0, Criteria.GREATER_THAN );
    94 TurbineUserPeer.doDelete( criteria, con );
    95
    96 criteria = new Criteria();
    97 criteria.where( TurbineGroupPeer.GROUP_ID, 0, Criteria.GREATER_THAN );
    98 TurbineGroupPeer.doDelete( criteria, con );
    99
    100 criteria = new Criteria();
    101 criteria.where( TurbineRolePeer.ROLE_ID, 0, Criteria.GREATER_THAN );
    102 TurbineRolePeer.doDelete( criteria, con );
    103
    104 criteria = new Criteria();
    105 criteria.where( TurbinePermissionPeer.PERMISSION_ID, 0, Criteria.GREATER_THAN );
    106 TurbinePermissionPeer.doDelete( criteria, con );
    107
    108 con.commit();
    109 con = null;
    110
    111 super.tearDown();
    112 }
    113 catch ( TorqueException e )
    114 {
    115 fail( e.toString() );
    116 }
    117 catch ( SQLException e )
    118 {
    119 if ( con != null )
    120 {
    121 Transaction.safeRollback( con );
    122 }
    123 fail( e.toString() );
    124 }
    125
    126 modelManager = null;
    127 securityService = null;
    128 }
    129
    130 }
  • turbine/fulcrum/trunk/security/torque/src/test/org/apache/fulcrum/security/torque/turbine/model/TurbineDefaultModelManagerTest.java

     
    1 package org.apache.fulcrum.security.torque.turbine.model;
    2 /*
    3 * Licensed to the Apache Software Foundation (ASF) under one
    4 * or more contributor license agreements. See the NOTICE file
    5 * distributed with this work for additional information
    6 * regarding copyright ownership. The ASF licenses this file
    7 * to you under the Apache License, Version 2.0 (the
    8 * "License"); you may not use this file except in compliance
    9 * with the License. You may obtain a copy of the License at
    10 *
    11 * http://www.apache.org/licenses/LICENSE-2.0
    12 *
    13 * Unless required by applicable law or agreed to in writing,
    14 * software distributed under the License is distributed on an
    15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16 * KIND, either express or implied. See the License for the
    17 * specific language governing permissions and limitations
    18 * under the License.
    19 */
    20
    21 import static org.junit.jupiter.api.Assertions.fail;
    22
    23 import java.sql.Connection;
    24 import java.sql.SQLException;
    25
    26 import org.apache.fulcrum.security.SecurityService;
    27 import org.apache.fulcrum.security.model.turbine.test.AbstractTurbineModelManagerTest;
    28 import org.apache.fulcrum.security.torque.HsqlDB;
    29 import org.apache.fulcrum.security.torque.om.TurbineGroupPeer;
    30 import org.apache.fulcrum.security.torque.om.TurbinePermissionPeer;
    31 import org.apache.fulcrum.security.torque.om.TurbineRolePeer;
    32 import org.apache.fulcrum.security.torque.om.TurbineRolePermissionPeer;
    33 import org.apache.fulcrum.security.torque.om.TurbineUserGroupRolePeer;
    34 import org.apache.fulcrum.security.torque.om.TurbineUserPeer;
    35 import org.apache.torque.TorqueException;
    36 import org.apache.torque.criteria.Criteria;
    37 import org.apache.torque.util.Transaction;
    38 import org.junit.jupiter.api.AfterEach;
    39 import org.junit.jupiter.api.BeforeEach;
    40
    41 /**
    42 * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
    43 * @author <a href="jh@byteaction.de">J&#252;rgen Hoffmann</a>
    44 * @version $Id$
    45 */
    46 public class TurbineDefaultModelManagerTest
    47 extends AbstractTurbineModelManagerTest
    48 {
    49 protected static HsqlDB hsqlDB = null;
    50
    51 @Override
    52 @BeforeEach
    53 public void setUp()
    54 throws Exception
    55 {
    56 try
    57 {
    58 hsqlDB = new HsqlDB( "src/test/fulcrum-turbine-default-schema.sql" );
    59 // we do not need id-broker,set native in schema and added identity in hsql
    60 // same for both flavors
    61 this.setRoleFileName( "src/test/TurbineTorqueRoleConfig.xml" );
    62 // we have to use declared peers
    63 this.setConfigurationFileName( "src/test/TurbineDefaultWithPeersComponentConfig.xml" );
    64 securityService = (SecurityService) lookup( SecurityService.ROLE );
    65
    66 super.setUp();
    67 }
    68 catch ( Exception e )
    69 {
    70 fail( e.toString() );
    71 }
    72
    73 }
    74
    75 @Override
    76 @AfterEach
    77 public void tearDown()
    78 {
    79 // cleanup tables
    80 Connection con = null;
    81 try
    82 {
    83 con = Transaction.begin();// "default"
    84
    85 Criteria criteria = new Criteria();
    86 criteria.where( TurbineUserGroupRolePeer.USER_ID, -1, Criteria.GREATER_THAN );
    87
    88 TurbineUserGroupRolePeer.doDelete( criteria, con );
    89
    90 criteria = new Criteria();
    91 criteria.where( TurbineRolePermissionPeer.ROLE_ID, 0, Criteria.GREATER_THAN );
    92 TurbineRolePermissionPeer.doDelete( criteria, con );
    93
    94 criteria = new Criteria();
    95 criteria.where( TurbineUserPeer.USER_ID, 0, Criteria.GREATER_THAN );
    96 TurbineUserPeer.doDelete( criteria, con );
    97
    98 criteria = new Criteria();
    99 criteria.where( TurbineGroupPeer.GROUP_ID, 0, Criteria.GREATER_THAN );
    100 TurbineGroupPeer.doDelete( criteria, con );
    101
    102 criteria = new Criteria();
    103 criteria.where( TurbineRolePeer.ROLE_ID, 0, Criteria.GREATER_THAN );
    104 TurbineRolePeer.doDelete( criteria, con );
    105
    106 criteria = new Criteria();
    107 criteria.where( TurbinePermissionPeer.PERMISSION_ID, 0, Criteria.GREATER_THAN );
    108 TurbinePermissionPeer.doDelete( criteria, con );
    109
    110 con.commit();
    111 con = null;
    112
    113 super.tearDown();
    114 }
    115 catch ( TorqueException e )
    116 {
    117 e.printStackTrace();
    118 fail( e.getMessage() );
    119 }
    120 catch ( SQLException e )
    121 {
    122 if ( con != null )
    123 {
    124 Transaction.safeRollback( con );
    125 }
    126 fail( e.toString() );
    127 }
    128
    129 modelManager = null;
    130 securityService = null;
    131 }
    132
    133 }