Setting database schema names from JDO
This commit is contained in:
parent
9e09e8f0cf
commit
f3bcedfdf8
@ -75,7 +75,6 @@ private EntityManager getEm() {
|
||||
|
||||
@Override
|
||||
public User createUser(String username, String fullName, String emailAddress) throws UserManagerException {
|
||||
|
||||
JpaUser user = new JpaUser();
|
||||
user.setUsername(username);
|
||||
user.setFullName(fullName);
|
||||
@ -270,6 +269,27 @@ public void deleteUser(String username) throws UserNotFoundException, UserManage
|
||||
|
||||
@Override
|
||||
public void addUserUnchecked(User user) throws UserManagerException {
|
||||
log.info("addUserUnchecked "+user.getUsername());
|
||||
if ( !( user instanceof JpaUser ) )
|
||||
{
|
||||
throw new UserManagerException( "Unable to Add User. User object " + user.getClass().getName() +
|
||||
" is not an instance of " + JpaUser.class.getName() );
|
||||
}
|
||||
|
||||
if ( org.codehaus.plexus.util.StringUtils.isEmpty( user.getUsername() ) )
|
||||
{
|
||||
throw new IllegalStateException(
|
||||
Messages.getString( "user.manager.cannot.add.user.without.username" ) ); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
em.getTransaction().begin();
|
||||
TypedQuery<JpaUser> q = em.createQuery("SELECT u FROM JpaUser u", JpaUser.class);
|
||||
for (JpaUser u : q.getResultList()) {
|
||||
log.info("USER FOUND: "+u.getUsername());
|
||||
}
|
||||
log.info("NEW USER "+user.getUsername());
|
||||
em.persist((JpaUser)user);
|
||||
em.getTransaction().commit();
|
||||
|
||||
}
|
||||
|
||||
@ -277,9 +297,16 @@ public void addUserUnchecked(User user) throws UserManagerException {
|
||||
public void eraseDatabase() {
|
||||
EntityManager em = getEm();
|
||||
em.getTransaction().begin();
|
||||
Query q = em.createQuery("DELETE FROM JpaUser u");
|
||||
q.executeUpdate();
|
||||
TypedQuery<JpaUser> q = em.createQuery("SELECT u FROM JpaUser u", JpaUser.class);
|
||||
for (JpaUser u : q.getResultList()) {
|
||||
u.getPreviousEncodedPasswords().clear();
|
||||
}
|
||||
em.flush();
|
||||
Query qd = em.createQuery("DELETE FROM JpaUser u");
|
||||
qd.executeUpdate();
|
||||
em.getTransaction().commit();
|
||||
em.clear();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -298,7 +325,7 @@ public User updateUser(User user, boolean passwordChangeRequired) throws UserNot
|
||||
|
||||
@Override
|
||||
public String getDescriptionKey() {
|
||||
return null;
|
||||
return "archiva.redback.usermanager.jpa";
|
||||
}
|
||||
|
||||
|
||||
|
@ -19,9 +19,13 @@
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import javax.persistence.CollectionTable;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ElementCollection;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.OrderColumn;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@ -35,21 +39,38 @@
|
||||
public class JpaUser implements org.apache.archiva.redback.users.User {
|
||||
|
||||
@Id
|
||||
@Column(name="USERNAME")
|
||||
private String username;
|
||||
|
||||
@Column(name="FULL_NAME")
|
||||
private String fullName;
|
||||
@Column(name="EMAIL")
|
||||
private String email;
|
||||
@Column(name="ENCODED_PASSWORD")
|
||||
private String encodedPassword;
|
||||
@Column(name="LAST_PASSWORD_CHANGE")
|
||||
private Date lastPasswordChange;
|
||||
@ElementCollection
|
||||
@OrderColumn(name="INTEGER_IDX")
|
||||
@Column(name="STRING_ELE")
|
||||
@CollectionTable(name="JDOUSER_PREVIOUSENCODEDPASSWORDS",
|
||||
joinColumns = @JoinColumn(name = "USERNAME_OID", referencedColumnName = "USERNAME")
|
||||
)
|
||||
private List<String> previousEncodedPasswords = new ArrayList<String>();
|
||||
@Column(name="PERMANENT")
|
||||
private boolean permanent;
|
||||
@Column(name="LOCKED")
|
||||
private boolean locked;
|
||||
@Column(name="PASSWORD_CHANGE_REQUIRED")
|
||||
private boolean passwordChangeRequired;
|
||||
@Column(name="VALIDATED")
|
||||
private boolean validated;
|
||||
@Column(name="COUNT_FAILED_LOGIN_ATTEMPTS")
|
||||
private int countFailedLoginAttempts;
|
||||
@Column(name="ACCOUNT_CREATION_DATE")
|
||||
private Date accountCreationDate;
|
||||
@Column(name="LAST_LOGIN_DATE")
|
||||
private Date lastLoginDate;
|
||||
@Column(name="USER_PASSSWORD")
|
||||
private String rawPassword;
|
||||
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!--
|
||||
~ Licensed to the Apache Software Foundation (ASF) under one
|
||||
~ or more contributor license agreements. See the NOTICE file
|
||||
~ distributed with this work for additional information
|
||||
~ regarding copyright ownership. The ASF licenses this file
|
||||
~ to you under the Apache License, Version 2.0 (the
|
||||
~ "License"); you may not use this file except in compliance
|
||||
~ with the License. You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing,
|
||||
~ software distributed under the License is distributed on an
|
||||
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
~ KIND, either express or implied. See the License for the
|
||||
~ specific language governing permissions and limitations
|
||||
~ under the License.
|
||||
-->
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context
|
||||
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:component-scan base-package="org.apache.archiva.redback.users.jpa" />
|
||||
|
||||
</beans>
|
@ -65,7 +65,6 @@ public void setUp() throws Exception {
|
||||
is.close();
|
||||
EntityManagerFactory emf = Persistence.createEntityManagerFactory("redback-jpa",props);
|
||||
|
||||
log.info("test setup");
|
||||
jpaUserManager.setEntityManager(emf.createEntityManager());
|
||||
super.setUserManager(jpaUserManager);
|
||||
assertNotNull(jpaUserManager);
|
||||
|
Loading…
x
Reference in New Issue
Block a user