List of usage examples for javax.persistence EntityExistsException EntityExistsException
public EntityExistsException(Throwable cause)
EntityExistsException
exception with the specified cause. From source file:org.rhq.enterprise.server.auth.SubjectManagerBean.java
public Subject createSubject(Subject whoami, Subject subjectToCreate, String password) throws SubjectException, EntityExistsException { if (getSubjectByName(subjectToCreate.getName()) != null) { throw new EntityExistsException("A user named [" + subjectToCreate.getName() + "] already exists."); }/* ww w . j a va 2s. c om*/ if (subjectToCreate.getFsystem()) { throw new SubjectException("Cannot create new system users: " + subjectToCreate.getName()); } entityManager.persist(subjectToCreate); createPrincipal(whoami, subjectToCreate.getName(), password); return subjectToCreate; }
From source file:org.rhq.enterprise.server.auth.SubjectManagerBean.java
/** * @see org.rhq.enterprise.server.auth.SubjectManagerLocal#createSubject(Subject, Subject) *//*from www.j a v a 2s. c om*/ @RequiredPermission(Permission.MANAGE_SECURITY) public Subject createSubject(Subject whoami, Subject subject) throws SubjectException { // Make sure there's not an existing subject with the same name. if (getSubjectByName(subject.getName()) != null) { throw new EntityExistsException("A user named [" + subject.getName() + "] already exists."); } if (subject.getFsystem()) { throw new SubjectException("Cannot create new system subjects: " + subject.getName()); } // we are ignoring roles - anything the caller gave us is thrown out subject.setRoles(null); subject.setLdapRoles(null); subject.setOwnedGroups(null); Configuration configuration = subject.getUserConfiguration(); if (configuration != null) { configuration = entityManager.merge(configuration); subject.setUserConfiguration(configuration); } entityManager.persist(subject); return subject; }