/** * Logs in the user. * * @see javax.security.auth.spi.LoginModule#login() */ @SuppressWarnings("unchecked") @Override public boolean login() throws LoginException { HttpRequestCallback rcb = new HttpRequestCallback(); AuthorizerCallback acb = new AuthorizerCallback(); Callback[] callbacks = new Callback[] {rcb, acb}; try { // First, try to extract a Principal object out of the request // directly. If we find one, we're done. m_handler.handle(callbacks); HttpServletRequest request = rcb.getRequest(); if (request == null) { throw new LoginException("No Http request supplied."); } UserDetail userDetail = (UserDetail) request.getAttribute(SilverpeasWikiAuthorizer.USER_ATTR_NAME); if (userDetail == null) { throw new LoginException("No user supplied."); } String[] userRoles = (String[]) request.getAttribute(SilverpeasWikiAuthorizer.ROLE_ATTR_NAME); Principal principal = new WikiPrincipal(userDetail.getLogin(), WikiPrincipal.LOGIN_NAME); Principal principalFullName = new WikiPrincipal(userDetail.getDisplayedName(), WikiPrincipal.FULL_NAME); Principal principalWikiName = new WikiPrincipal(userDetail.getDisplayedName(), WikiPrincipal.WIKI_NAME); SilverTrace.debug( "wiki", "SilverpeasWikiLoginModule", "Added Principal " + principal.getName() + ",Role.ANONYMOUS,Role.ALL"); m_principals.add(new PrincipalWrapper(principal)); m_principals.add(new PrincipalWrapper(principalWikiName)); m_principals.add(new PrincipalWrapper(principalFullName)); // Add any container roles injectWebAuthorizerRoles(acb.getAuthorizer(), request); // If login succeeds, commit these roles for (String userRole : userRoles) { m_principals.add(convertSilverpeasRole(userRole)); } // If login succeeds, remove these principals/roles m_principalsToOverwrite.add(WikiPrincipal.GUEST); m_principalsToOverwrite.add(Role.ANONYMOUS); m_principalsToOverwrite.add(Role.ASSERTED); // If login fails, remove these roles m_principalsToRemove.add(Role.AUTHENTICATED); return true; } catch (IOException e) { SilverTrace.error("wiki", "SilverpeasWikiLoginModule", "wiki.EX_LOGIN", e); return false; } catch (UnsupportedCallbackException e) { SilverTrace.error("wiki", "SilverpeasWikiLoginModule", "wiki.EX_LOGIN", e); return false; } }
@Override public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { SilverTrace.info("peasUtil", "RssServlet.doPost", "root.MSG_GEN_ENTER_METHOD"); String instanceId = getObjectId(req); String userId = getUserId(req); String login = getLogin(req); String password = getPassword(req); // rechercher si le composant a bien le flux RSS autorisé if (isComponentRss(instanceId)) { try { SilverTrace.info( "peasUtil", "RssServlet.doPost", "root.MSG_GEN_PARAM_VALUE", "InstanceId = " + instanceId); // Vérification que le user a droit d'accès au composant AdminController adminController = new AdminController(null); UserFull user = adminController.getUserFull(userId); if (user != null && login.equals(user.getLogin()) && password.equals(user.getPassword()) && isComponentAvailable(adminController, instanceId, userId)) { String serverURL = getServerURL(adminController, user.getDomainId()); ChannelIF channel = new Channel(); // récupération de la liste des N éléments à remonter dans le flux int nbReturnedElements = getNbReturnedElements(); Collection<T> listElements = getListElements(instanceId, nbReturnedElements); // création d'une liste de ItemIF en fonction de la liste des éléments for (T element : listElements) { String title = getElementTitle(element, userId); URL link = new URL(serverURL + getElementLink(element, userId)); String description = getElementDescription(element, userId); Date dateElement = getElementDate(element); String creatorId = getElementCreatorId(element); ItemIF item = new Item(); item.setTitle(title); item.setLink(link); item.setDescription(description); item.setDate(dateElement); if (StringUtil.isDefined(creatorId)) { UserDetail creator = adminController.getUserDetail(creatorId); if (creator != null) { item.setCreator(creator.getDisplayedName()); } } else if (StringUtil.isDefined(getExternalCreatorId(element))) { item.setCreator(getExternalCreatorId(element)); } channel.addItem(item); } // construction de l'objet Channel channel.setTitle(getChannelTitle(instanceId)); URL componentUrl = new URL( serverURL + URLManager.getApplicationURL() + URLManager.getURL("useless", instanceId)); channel.setLocation(componentUrl); // exportation du channel res.setContentType("application/rss+xml"); res.setHeader("Content-Disposition", "inline; filename=feeds.rss"); Writer writer = res.getWriter(); RSS_2_0_Exporter rssExporter = new RSS_2_0_Exporter(writer, "UTF-8"); rssExporter.write(channel); } else { objectNotFound(req, res); } } catch (Exception e) { objectNotFound(req, res); } } }