执行CQ5中的自定义认证处理程序
问题描述:
我想要一个远程系统为我们的CQ5执行用户认证。我猜测道路上的AuthenticationHandler是一个方向。如果是这样,AuthenticationHandler如何工作。而且,在CQ5中,我是如何实现一个Custom AuthenticationHandler的?我如何才能使它成为一个OSGi包(或片段包)并将其安装到CQ5中?执行CQ5中的自定义认证处理程序
如果可能的话,一些代码示例与OSGi清单表示赞赏。
答
你可以找到Sling AuthenticationHandler如何工作的说明here。你也可以看看Sling FormAuthenticationHandler来源为例。您可以在maven-bundle-plugin的配置下看到该项目的POM file中OSGi配置的详细信息。
如果您只需检查密码或同步用户帐户,则可以使用custom CQ5 LoginModule。
答
我会通过查看兔崽子AbstractLoginModule http://jackrabbit.apache.org/api/2.4/org/apache/jackrabbit/core/security/authentication/AbstractLoginModule.html
开始我的例子,是写一个定制的解决方案/片段捆绑的,但它有很多件。我们正在实施Gigya(社交网络登录)的内容。
我们有一些其他类实现MyAbstractLoginModule。如果您需要,我可以深入挖掘并获得更多示例。希望这可以让你开始走上正确的道路。
public abstract class MyAbstractLoginModule extends AbstractLoginModule {
static private final Logger logger = LoggerFactory.getLogger(MyAbstractLoginModule.class);
protected Session session;
protected UserManager userManager;
protected ValueFactory valueFactory;
protected long tokenExpiration = 7200000L;
@Override
public void initialize(Subject subject, CallbackHandler callbackHandler, Map<String, ?> sharedState, Map<String, ?> options) {
if (options.containsKey("tokenExpiration")) {
try {
this.tokenExpiration = Long.parseLong(options.get("tokenExpiration").toString());
logger.debug("- Token expiration -> '" + this.tokenExpiration + "'");
} catch (NumberFormatException e) {
logger.warn("Unabled to parse token expiration: ", e);
}
}
super.initialize(subject, callbackHandler, sharedState, options);
}
/**
* Initiates the login module
*
* @param ch
* @param ses
* @param map
* @throws LoginException
*/
@Override
protected void doInit(CallbackHandler ch, Session ses, Map map) throws LoginException {
logger.trace("doInit");
SessionImpl session = (SessionImpl) ses;
try {
this.session = session;
this.userManager = session.getUserManager();
this.valueFactory = session.getValueFactory();
} catch (RepositoryException e) {
throw new LoginException("Unable to retrieve principal editor: " + e.toString());
}
}
/**
* Impersonates users
*
* @param prncpl
* @param c
* @return
* @throws RepositoryException
* @throws LoginException
*/
@Override
protected boolean impersonate(Principal prncpl, Credentials c) throws RepositoryException, LoginException {
Authorizable authrz = this.userManager.getAuthorizable(principal);
if ((authrz == null) || (authrz.isGroup())) {
return false;
}
Subject impersSubject = getImpersonatorSubject(credentials);
User user = (User) authrz;
if (user.getImpersonation().allows(impersSubject)) {
return true;
}
throw new FailedLoginException("attempt to impersonate denied for " + principal.getName());
}
@Override
protected boolean isPreAuthenticated(Credentials creds) {
return false;
}
}
@Woodifer,请你帮我[这里] [1]? [1]:http://stackoverflow.com/questions/22978803/doubts-on-3rd-party-authentication – 2014-04-13 04:39:43
可以请你帮我在这里:HTTP://stackoverflow.com/questions/22978803 /疑虑上,第三方认证 – 2014-04-13 04:47:36