📄 authorizationfactory.java
字号:
package com.gs.db;
/**
* 这个abstract类定义了进行身份认证的框架。 static方法 getAuthorization(String,String)
* 和 getAnonymousAuthorization() 直接供应用程序调用以生成 Authorization 证明<p>
*
* An abstract class that defines a framework for providing authorization
* services in Ioffice. The static getAuthorization(String,String) and
* getAnonymousAuthorization() methods should be called directly from
* applications using ioffice kernel in order to obtain Authorization tokens.
*
*/
public abstract class AuthorizationFactory {
public static final int PULSE_INTERVAL_SEC=30;
/**
* The default class to instantiate is database implementation.
*/
private static String className =
"com.gs.db.dbimp.DbAuthorizationFactory";
private static AuthorizationFactory factory = null;
/**
* Returns the Authorization token associated with the specified username
* and password. If the username and password do not match the record of
* any user in the system, the method throws an UnauthorizedException.<p>
*
* When using most implementations of this class, authorization tokens
* should be cached. A convenient place to store a token is often in the
* HttpSession.
*
* @param username the username to create an Authorization with.
* @param password the password to create an Authorization with.
* @return an Authorization token if the username and password are correct.
* @throws UnauthorizedException if the username and password do not match
* any existing user.
*/
public static Authorization getAuthorization(String username,
String password) throws UnauthorizedException,AlreadyLoginException
{
loadAuthorizationFactory();
return factory.createAuthorization(username, password);
}
/**
* Returns the anonymous user Authorization.
*
* @return an anonymous Authorization token.
*/
public static Authorization getAnonymousAuthorization() {
loadAuthorizationFactory();
return factory.createAnonymousAuthorization();
}
/**
* Creates Authorization tokens for users. This method is implemented by
* concrete subclasses of AuthorizationFactory.
*
* @param username the username to create an Authorization with.
* @param password the password to create an Authorization with.
* @return an Authorization token if the username and password are correct.
* @throws UnauthorizedException if the username and password do not match
* any existing user.
*/
public abstract Authorization createAuthorization(String username,
String password) throws UnauthorizedException, AlreadyLoginException;
/**
* Creates anonymous Authorization tokens. This method is implemented by
* concrete subclasses AuthorizationFactory.
*
* @return an anonymous Authorization token.
*/
public abstract Authorization createAnonymousAuthorization();
/**
* Loads a concrete AuthorizationFactory that can be used generate
* Authorization tokens for authorized users.<p>
*
* By default, the implementation used will be an instance of
* DbAuthorizationFactory -- the standard database implementation that uses
* the InterOffice user table. A different factory can be specified by setting the
* InterOffice property "AuthorizationFactory.className". However, you must
* restart InterOffice for any change to take effect.
*/
private static void loadAuthorizationFactory() {
if (factory == null) {
//Use className as a convenient object to get a lock on.
synchronized(className) {
if (factory == null) {
//See if the classname has been set as a InterOffice property.
String classNameProp = PropertyManager.getProperty(
"AuthorizationFactory.className"
);
if (classNameProp != null) {
className = classNameProp;
}
try {
Class c = Class.forName(className);
factory = (AuthorizationFactory)c.newInstance();
}
catch (Exception e) {
System.err.println("Exception loading class: " + e);
e.printStackTrace();
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -