本文整理匯總了Java中org.androidpn.server.service.UserNotFoundException類的典型用法代碼示例。如果您正苦於以下問題:Java UserNotFoundException類的具體用法?Java UserNotFoundException怎麽用?Java UserNotFoundException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
UserNotFoundException類屬於org.androidpn.server.service包,在下文中一共展示了UserNotFoundException類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: authenticate
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
/**
* Authenticates a user with a username and plain text password, and
* returns an AuthToken.
*
* @param username the username
* @param password the password
* @return an AuthToken
* @throws UnauthenticatedException if the username and password do not match
*/
public static AuthToken authenticate(String username, String password)
throws UnauthenticatedException {
if (username == null || password == null) {
throw new UnauthenticatedException();
}
username = username.trim().toLowerCase();
if (username.contains("@")) {
int index = username.indexOf("@");
String domain = username.substring(index + 1);
if (domain.equals(XmppServer.getInstance().getServerName())) {
username = username.substring(0, index);
} else {
throw new UnauthenticatedException();
}
}
try {
if (!password.equals(getPassword(username))) {
throw new UnauthenticatedException();
}
} catch (UserNotFoundException unfe) {
throw new UnauthenticatedException();
}
return new AuthToken(username);
}
示例2: authenticate
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
public static AuthToken authenticate(String username, String password)
throws UnauthorizedException {
if (username == null || password == null) {
throw new UnauthorizedException();
}
username = username.trim().toLowerCase();
if (username.contains("@")) {
// Check that the specified domain matches the server's domain
int index = username.indexOf("@");
String domain = username.substring(index + 1);
if (domain.equals(XmppServer.getInstance().getServerName())) {
username = username.substring(0, index);
} else {
throw new UnauthorizedException();
}
}
try {
if (!password.equals(getPassword(username))) {
throw new UnauthorizedException();
}
} catch (UserNotFoundException unfe) {
throw new UnauthorizedException();
}
return new AuthToken(username);
}
示例3: authenticate
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
public static AuthToken authenticate(String username, String password)
throws UnauthorizedException {
if (username == null || password == null) {
throw new UnauthorizedException();
}
username = username.trim().toLowerCase();
if (username.contains("@")) {
int index = username.indexOf("@");
String domain = username.substring(index + 1);
if (domain.equals(XmppServer.getInstance().getServerName())) {
username = username.substring(0, index);
} else {
throw new UnauthorizedException();
}
}
try {
if (!password.equals(getPassword(username))) {
throw new UnauthorizedException();
}
} catch (UserNotFoundException unfe) {
throw new UnauthorizedException();
}
return new AuthToken(username);
}
示例4: authenticate
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
/**
* Authenticates a user with a username and plain text password, and
* returns an AuthToken.
*
* @param username the username
* @param password the password
* @return an AuthToken
* @throws UnauthorizedException if the username and password do not match
*/
public static AuthToken authenticate(String username, String password)
throws UnauthorizedException {
if (username == null || password == null) {
throw new UnauthorizedException();
}
username = username.trim().toLowerCase();
if (username.contains("@")) {
int index = username.indexOf("@");
String domain = username.substring(index + 1);
if (domain.equals(XmppServer.getInstance().getServerName())) {
username = username.substring(0, index);
} else {
throw new UnauthorizedException();
}
}
try {
if (!password.equals(getPassword(username))) {
throw new UnauthorizedException();
}
} catch (UserNotFoundException unfe) {
throw new UnauthorizedException();
}
return new AuthToken(username);
}
示例5: getUserByUsername
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public User getUserByUsername(String username) throws UserNotFoundException {
List users = getHibernateTemplate().find("from User where username=?",
username);
if (users == null || users.isEmpty()) {
throw new UserNotFoundException("用戶 '" + username + "' 未找到");
} else {
return (User) users.get(0);
}
}
示例6: sendNotifcationToUser
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
/**
* 向特定用戶發送新創建的通知消息
*
* @param apiKey
* 密鑰
* @param username
* 用戶名
* @param title
* 消息標題
* @param message
* 消息詳情
* @param uri
* 消息URI
* @param imageUrl
* 圖片地址
* @param shouldSave
* 是否要保存該消息
*/
public void sendNotifcationToUser(String apiKey, String username,
String title, String message, String uri, String imageUrl,
boolean shouldSave) {
log.debug("sendNotifcationToUser()...");
Random random = new Random();
String id = Integer.toHexString(random.nextInt());
try {
User user = userService.getUserByUsername(username);
// 避免user非法存儲到數據庫(過濾垃圾數據)
if (user != null && shouldSave) {
saveNotification(apiKey, username, title, message, uri,
imageUrl, id);
}
} catch (UserNotFoundException e) {
log.debug("未找到該用戶:" + username);
e.printStackTrace();
}
IQ notificationIQ = createNotificationIQ(id, apiKey, title, message,
uri, imageUrl);
ClientSession session = sessionManager.getSession(username);
if (session != null) {
if (session.getPresence().isAvailable()) {
notificationIQ.setTo(session.getAddress());
session.deliver(notificationIQ);
}
}
}
示例7: authenticate
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
/**
* 根據用戶名、密碼驗證用戶名真實性,並返回一個令牌
*
* @param username
* 用戶名
* @param password
* 用戶密碼
* @return 一個令牌
* @throws UnauthenticatedException
* 如果用戶名和密碼不匹配
*/
public static AuthToken authenticate(String username, String password)
throws UnauthenticatedException {
if (username == null || password == null) {
throw new UnauthenticatedException();
}
// 用戶名是否是@domain形式
username = username.trim().toLowerCase();
if (username.contains("@")) {
int index = username.indexOf("@");
String domain = username.substring(index + 1);
// 驗證domain
if (domain.equals(XmppServer.getInstance().getServerName())) {
// 獲得真正的username
username = username.substring(0, index);
} else {
throw new UnauthenticatedException();
}
}
try {
if (!password.equals(getPassword(username))) {
throw new UnauthenticatedException();
}
} catch (UserNotFoundException unfe) {
throw new UnauthenticatedException();
}
return new AuthToken(username);
}
示例8: getUserByUsername
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public User getUserByUsername(String username) throws UserNotFoundException {
List users = getHibernateTemplate().find("from User where username=?",
username);
if (users == null || users.isEmpty()) {
throw new UserNotFoundException("User '" + username + "' not found");
} else {
return (User) users.get(0);
}
}
示例9: getUsername
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
/**
* Returns the username associated with this session.
*
* @return the username
* @throws UserNotFoundException if a user has not authenticated yet
*/
public String getUsername() throws UserNotFoundException {
if (authToken == null) {
throw new UserNotFoundException();
}
return getAddress().getNode();
}
示例10: authorize
import org.androidpn.server.service.UserNotFoundException; //導入依賴的package包/類
public static boolean authorize(String username, String principal) {
if (log.isDebugEnabled()) {
log.debug("Trying authorize(" + username + " , " + principal + ")");
}
try {
ServiceManager.getUserService().getUserByUsername(username);
} catch (UserNotFoundException nfe) {
return false;
}
return true;
}