インストール
公式サイトからtarをダウンロード。解凍して、openid4java-x.x.x.jarをWEB-INF/libに配置。
依存するライブラリが、openid4java-x.x.x.xxx/libディレクトリに入っているので、これも必要に応じてWEB-INF/libに投入。
作ったもの
ほとんどQuickStartにあったものをつなぎあわせただけです。userSuppliedStringが謎でしたが、http://www.ibm.com/developerworks/java/library/j-openid/を見ると、
The RP normalizes the User-Supplied Identifier to determine which OP to contact for authentication and how to contact it.
とあったので、Providerの認証URIを指定しました。
とりあえずアクションクラスだけ載せときます。
jspとかアクションフォームとかsturts-configとかも見たい人はgistへ。
[AuthAction.java]
public class AuthAction extends DispatchAction { private ConsumerManager manager; private static final String RETURN_URL = "http://localhost:8080/OpenId/auth.do?event=verify"; public AuthAction() { manager = new ConsumerManager(); } @SuppressWarnings("rawtypes") public ActionForward redirect(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { OpenIdInfoForm f = (OpenIdInfoForm) form; String provider = f.getProvider(); List discoveries = manager.discover(provider); DiscoveryInformation discovered = manager.associate(discoveries); HttpSession session = request.getSession(); session.setAttribute("discovered", discovered); AuthRequest authReq = manager.authenticate(discovered, RETURN_URL); response.sendRedirect(authReq.getDestinationUrl(true)); return null; } public ActionForward verify(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { ParameterList openidResp = new ParameterList(request.getParameterMap()); HttpSession session = request.getSession(); DiscoveryInformation discovered = (DiscoveryInformation) session .getAttribute("discovered"); StringBuffer receivingURL = request.getRequestURL(); String queryString = request.getQueryString(); if (queryString != null && queryString.length() > 0) receivingURL.append("?").append(request.getQueryString()); VerificationResult verification = manager.verify( receivingURL.toString(), openidResp, discovered); Identifier verified = verification.getVerifiedId(); if (verified == null) { ActionMessages errors = new ActionMessages(); errors.add("authError", new ActionMessage("errors.authError")); saveErrors(request, errors); return mapping.findForward("failure"); } OpenIdInfoForm f = (OpenIdInfoForm)form; f.setId(verified.getIdentifier()); return mapping.findForward("success"); } }
0 件のコメント:
コメントを投稿