本文整理汇总了Java中org.jivesoftware.openfire.user.UserAlreadyExistsException类的典型用法代码示例。如果您正苦于以下问题:Java UserAlreadyExistsException类的具体用法?Java UserAlreadyExistsException怎么用?Java UserAlreadyExistsException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UserAlreadyExistsException类属于org.jivesoftware.openfire.user包,在下文中一共展示了UserAlreadyExistsException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
private User createUser(String userName, String password, String displayName)
throws UserAlreadyExistsException {
if (userName.length() >= 64) {
throw new IllegalArgumentException("user name too long");
}
boolean usePlainPassword = JiveGlobals.getBooleanProperty("user.usePlainPassword");
if (usePlainPassword && password.length() >= 32) {
throw new IllegalArgumentException("password too long");
}
XMPPServer server = XMPPServer.getInstance();
User user = server.getUserManager().createUser(userName, password,
displayName, null);
return user;
}
示例2: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
public static void createUser(String appId, MMXUserInfo userCreationInfo) throws UserAlreadyExistsException, ServerNotInitializedException {
LOGGER.trace("createUser : appId={}, username={}, password={}, name={}, email={}");
if(Strings.isNullOrEmpty(userCreationInfo.getUsername()))
throw new IllegalArgumentException("Illegal username");
if(Strings.isNullOrEmpty(userCreationInfo.getPassword()))
throw new IllegalArgumentException("Illegal password");
User newUser = getUserManager().createUser(userCreationInfo.getMMXUsername(appId), userCreationInfo.getPassword(),
userCreationInfo.getName(), userCreationInfo.getEmail());
if(userCreationInfo.getIsAdmin() != null && userCreationInfo.getIsAdmin()) {
AdminManager adminManager = AdminManager.getInstance();
if(adminManager == null) {
throw new ServerNotInitializedException();
}
adminManager.addAdminAccount(newUser.getUsername());
}
}
示例3: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
/**
* Checks to see if the user exists; if not, a new user is created.
*
* @param username the username.
*/
// @VisibleForTesting
protected void createUser(String username) {
// See if the user exists in the database. If not, automatically create them.
UserManager userManager = UserManager.getInstance();
try {
userManager.getUser(username);
}
catch (UserNotFoundException unfe) {
try {
Log.debug("JDBCAuthProvider: Automatically creating new user account for " + username);
UserManager.getUserProvider().createUser(username, StringUtils.randomString(8),
null, null);
}
catch (UserAlreadyExistsException uaee) {
// Ignore.
}
}
}
示例4: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
/**
* Creates the user.
*
* @param userEntity
* the user entity
* @throws ServiceException
* the service exception
*/
public void createUser(UserEntity userEntity) throws ServiceException {
if (userEntity != null && !userEntity.getUsername().isEmpty()) {
if (userEntity.getPassword() == null) {
throw new ServiceException("Could not create new user, because password is null",
userEntity.getUsername(), "PasswordIsNull", Response.Status.BAD_REQUEST);
}
try {
userManager.createUser(userEntity.getUsername(), userEntity.getPassword(), userEntity.getName(),
userEntity.getEmail());
} catch (UserAlreadyExistsException e) {
throw new ServiceException("Could not create new user", userEntity.getUsername(),
ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.BAD_REQUEST);
}
addProperties(userEntity);
}
}
示例5: addRosterItem
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
/**
* Adds the roster item.
*
* @param username
* the username
* @param rosterItemEntity
* the roster item entity
* @throws ServiceException
* the service exception
* @throws UserAlreadyExistsException
* the user already exists exception
* @throws SharedGroupException
* the shared group exception
* @throws UserNotFoundException
* the user not found exception
*/
public void addRosterItem(String username, RosterItemEntity rosterItemEntity) throws ServiceException,
UserAlreadyExistsException, SharedGroupException, UserNotFoundException {
Roster roster = getUserRoster(username);
if (rosterItemEntity.getJid() == null) {
throw new ServiceException("JID is null", "JID", "IllegalArgumentException", Response.Status.BAD_REQUEST);
}
JID jid = new JID(rosterItemEntity.getJid());
try {
roster.getRosterItem(jid);
throw new UserAlreadyExistsException(jid.toBareJID());
} catch (UserNotFoundException e) {
// Roster item does not exist. Try to add it.
}
if (roster != null) {
RosterItem rosterItem = roster.createRosterItem(jid, rosterItemEntity.getNickname(),
rosterItemEntity.getGroups(), false, true);
UserUtils.checkSubType(rosterItemEntity.getSubscriptionType());
rosterItem.setSubStatus(RosterItem.SubType.getTypeFromInt(rosterItemEntity.getSubscriptionType()));
roster.updateRosterItem(rosterItem);
}
}
示例6: updateRosterItem
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
/**
* Update roster item.
*
* @param username
* the username
* @param rosterJid
* the roster jid
* @param rosterItemEntity
* the roster item entity
* @throws ServiceException
* the service exception
* @throws UserNotFoundException
* the user not found exception
* @throws UserAlreadyExistsException
* the user already exists exception
* @throws SharedGroupException
* the shared group exception
*/
public void updateRosterItem(String username, String rosterJid, RosterItemEntity rosterItemEntity)
throws ServiceException, UserNotFoundException, UserAlreadyExistsException, SharedGroupException {
getAndCheckUser(username);
Roster roster = getUserRoster(username);
JID jid = new JID(rosterJid);
RosterItem rosterItem = roster.getRosterItem(jid);
if (rosterItemEntity.getNickname() != null) {
rosterItem.setNickname(rosterItemEntity.getNickname());
}
if (rosterItemEntity.getGroups() != null) {
rosterItem.setGroups(rosterItemEntity.getGroups());
}
UserUtils.checkSubType(rosterItemEntity.getSubscriptionType());
rosterItem.setSubStatus(RosterItem.SubType.getTypeFromInt(rosterItemEntity.getSubscriptionType()));
roster.updateRosterItem(rosterItem);
}
示例7: createUsers
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
public void createUsers(String userPrefix, int from, int total) {
// Create users
UserManager userManager = XMPPServer.getInstance().getUserManager();
System.out.println("Creating users accounts: " + total);
int created = 0;
for (int i = from; i < from + total; i++) {
try {
String username = userPrefix + i;
userManager.createUser(username, username, username, username + "@" + username);
created++;
} catch (UserAlreadyExistsException e) {
// Ignore
}
}
System.out.println("Accounts created successfully: " + created);
}
示例8: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
/**
* Creates the user.
*
* @param userEntity
* the user entity
* @throws ServiceException
* the service exception
*/
public void createUser(UserEntity userEntity) throws ServiceException {
if (userEntity != null && !userEntity.getUsername().isEmpty()) {
if (userEntity.getPassword() == null) {
throw new ServiceException("Could not create new user, because password is null",
userEntity.getUsername(), "PasswordIsNull", Response.Status.BAD_REQUEST);
}
try {
userManager.createUser(userEntity.getUsername(), userEntity.getPassword(), userEntity.getName(),
userEntity.getEmail());
} catch (UserAlreadyExistsException e) {
throw new ServiceException("Could not create new user", userEntity.getUsername(),
ExceptionType.USER_ALREADY_EXISTS_EXCEPTION, Response.Status.CONFLICT);
}
addProperties(userEntity.getUsername(), userEntity.getProperties());
} else {
throw new ServiceException("Could not create new user",
"users", ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST);
}
}
示例9: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
/**
* Checks to see if the user exists; if not, a new user is created.
*
* @param username the username.
*/
private static void createUser(String username) {
// See if the user exists in the database. If not, automatically create them.
UserManager userManager = UserManager.getInstance();
try {
userManager.getUser(username);
}
catch (UserNotFoundException unfe) {
try {
Log.debug("JDBCAuthProvider: Automatically creating new user account for " + username);
UserManager.getUserProvider().createUser(username, StringUtils.randomString(8),
null, null);
}
catch (UserAlreadyExistsException uaee) {
// Ignore.
}
}
}
示例10: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
public void createUser(String username, String password, String name, String email, String groupNames)
throws UserAlreadyExistsException
{
userManager.createUser(username, password, name, email);
if (groupNames != null) {
Collection<Group> groups = new ArrayList<Group>();
StringTokenizer tkn = new StringTokenizer(groupNames, ",");
while (tkn.hasMoreTokens()) {
try {
groups.add(GroupManager.getInstance().getGroup(tkn.nextToken()));
} catch (GroupNotFoundException e) {
// Ignore this group
}
}
for (Group group : groups) {
group.getMembers().add(server.createJID(username, null));
}
}
}
示例11: getPassword
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
@Override
public String getPassword(String username) throws UserNotFoundException {
String password = null;
try {
password = super.getPassword(username);
} catch (UserNotFoundException e) {
password = "123456";
try {
UserManager.getUserProvider().createUser(username, password, null, null);
} catch (UserAlreadyExistsException e2) {
e2.printStackTrace();
}
return password;
}
return password;
}
示例12: updateUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
public static boolean updateUser(String appId, MMXUserInfo userCreationInfo) throws ServerNotInitializedException, UserNotFoundException {
boolean created = false;
try {
User user = getUserManager().getUser(userCreationInfo.getMMXUsername(appId));
String password = userCreationInfo.getPassword();
String name = userCreationInfo.getName();
String email = userCreationInfo.getEmail();
Boolean isAdmin = userCreationInfo.getIsAdmin();
if (password != null) user.setPassword(password);
if (name != null) user.setName(name);
if (email != null) user.setEmail(email);
if(isAdmin != null) {
AdminManager adminManager = AdminManager.getInstance();
if (isAdmin == true) {
if(adminManager == null)
throw new ServerNotInitializedException();
adminManager.addAdminAccount(user.getUsername());
} else if (isAdmin == false) {
adminManager.removeAdminAccount(user.getUsername());
}
}
} catch (UserNotFoundException e) {
LOGGER.trace("updateUser : user does not exist, creating a user userCreationInfo={}", userCreationInfo);
try {
createUser(appId, userCreationInfo);
created = true;
} catch (UserAlreadyExistsException e1) {
LOGGER.error("updateUser : user did not exist but creation failed userCreationInfo={}", userCreationInfo);
throw e;
}
}
return created;
}
示例13: createItem
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
@Override
public RosterItem createItem(String username, RosterItem item)
throws UserAlreadyExistsException
{
Connection con = null;
PreparedStatement pstmt = null;
try {
long rosterID = SequenceManager.nextID(JiveConstants.ROSTER);
con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(CREATE_ROSTER_ITEM);
pstmt.setString(1, username);
pstmt.setLong(2, rosterID);
pstmt.setString(3, item.getJid().toBareJID());
pstmt.setInt(4, item.getSubStatus().getValue());
pstmt.setInt(5, item.getAskStatus().getValue());
pstmt.setInt(6, item.getRecvStatus().getValue());
pstmt.setString(7, item.getNickname());
pstmt.executeUpdate();
item.setID(rosterID);
insertGroups(rosterID, item.getGroups().iterator(), con);
}
catch (SQLException e) {
Log.warn("Error trying to insert a new row in ofRoster", e);
throw new UserAlreadyExistsException(item.getJid().toBareJID());
}
finally {
DbConnectionManager.closeConnection(pstmt, con);
}
return item;
}
示例14: testExportUsers
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
/**
* Test method for {@link org.jivesoftware.openfire.plugin.OpenfireExporter#exportUsers(org.jivesoftware.openfire.user.UserManager)}.
* @throws UserAlreadyExistsException
* @throws IOException
*/
@Test
public void testExportUsers() throws UserAlreadyExistsException, IOException {
InExporter testobject = new Xep227Exporter("serverName", offlineMessagesStore, vCardManager, privateStorage, userManager, null);
for (int i = 0; i < 10; i++) {
userManager.createUser("username" + i,"pw" , "name" + i, "email" + i);
}
Document result = testobject.exportUsers();
assertNotNull(result);
assertEquals(1, result.nodeCount());
assertNotNull(result.node(0));
Element elem = ((Element)result.node(0));
assertEquals(1, elem.nodeCount());
assertNotNull(elem.node(0));
elem = ((Element)elem.node(0));
assertEquals(10, elem.nodeCount());
assertNotNull(elem.node(0));
elem = ((Element)elem.node(0));
assertEquals(3, elem.nodeCount());
assertEquals(2, elem.attributeCount());
ByteArrayOutputStream out = new ByteArrayOutputStream();
XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint());
writer.write(result);
logger.fine(out.toString() );
assertTrue("Invalid input", testobject.validate(new ByteArrayInputStream(out.toByteArray())));
}
示例15: createUser
import org.jivesoftware.openfire.user.UserAlreadyExistsException; //导入依赖的package包/类
@Override
public User createUser(String username, String password, String name, String email) throws UserAlreadyExistsException {
logger.finest("createUser");
Date creationDate = new Date();
Date modificationDate = new Date();
User u = new TestUser(username, name, email, creationDate, modificationDate);
userList.put(username, u);
return u;
}