private ServerManager getServerManager() { ServerManager manager = (ServerManager) IWMainApplication.getDefaultIWApplicationContext() .getApplicationAttribute(OpenIDConstants.ATTRIBUTE_SERVER_MANAGER); if (manager == null) { String endPointUrl = IWMainApplication.getDefaultIWApplicationContext() .getApplicationSettings() .getProperty(OpenIDConstants.PROPERTY_END_POINT_URL, "http://localhost:8080/"); String userSetupUrl = IWMainApplication.getDefaultIWApplicationContext() .getApplicationSettings() .getProperty( OpenIDConstants.PROPERTY_USER_SETUP_URL, "http://localhost:8080/pages/profile/?doRedirect=true"); manager = new ServerManager(); manager.setSharedAssociations(new InMemoryServerAssociationStore()); manager.setPrivateAssociations(new InMemoryServerAssociationStore()); manager.setOPEndpointUrl(endPointUrl); manager.setUserSetupUrl(userSetupUrl); IWMainApplication.getDefaultIWApplicationContext() .setApplicationAttribute(OpenIDConstants.ATTRIBUTE_SERVER_MANAGER, manager); } return manager; }
/** * Gets the scripts that is need for this element to work * * @return script files uris */ public static List<String> getNeededScripts(IWContext iwc) { List<String> scripts = new ArrayList<String>(); scripts.add(CoreConstants.DWR_ENGINE_SCRIPT); scripts.add(CoreConstants.DWR_UTIL_SCRIPT); Web2Business web2 = WFUtil.getBeanInstance(iwc, Web2Business.SPRING_BEAN_IDENTIFIER); if (web2 != null) { JQuery jQuery = web2.getJQuery(); scripts.add(jQuery.getBundleURIToJQueryLib()); scripts.add(web2.getBundleUriToHumanizedMessagesScript()); } else { Logger.getLogger("ContentShareComponent") .log( Level.WARNING, "Failed getting Web2Business no jQuery and it's plugins files were added"); } IWMainApplication iwma = iwc.getApplicationContext().getIWMainApplication(); IWBundle iwb = iwma.getBundle(UserConstants.IW_BUNDLE_IDENTIFIER); scripts.add(iwb.getVirtualPathWithFileNameString("javascript/GroupJoinerHelper.js")); scripts.add("/dwr/interface/GroupService.js"); return scripts; }
protected void redirectToAuthorisationPage( HttpServletRequest req, HttpServletResponse resp, ParameterList requestParameters, OpenIDServerBean serverBean) throws IOException { String URL = req.getScheme() + "://" + req.getServerName() + (req.getServerPort() != 80 ? ":" + req.getServerPort() : "") + req.getRequestURI(); String queryString = req.getQueryString(); if (queryString != null) { URL += "?" + queryString; } serverBean.setServerUrl(URL); serverBean.setParameterList(requestParameters); String authenticateURL = IWMainApplication.getDefaultIWApplicationContext() .getApplicationSettings() .getProperty( OpenIDConstants.PROPERTY_AUTHENTICATION_URL, "http://www.elykill.is/pages/profile/mypage/authenticate/"); resp.sendRedirect(authenticateURL); }
@SuppressWarnings("unchecked") protected <T extends IBOService> T getServiceInstance( Class<? extends IBOService> serviceBeanClass) { // Casting is needed to avoid stupid compilation error in Maven 2 return (T) getServiceInstance(IWMainApplication.getDefaultIWApplicationContext(), serviceBeanClass); }
private String getUserSelectedClaimedId(IWContext iwc, User user) { String identityFormat = IWMainApplication.getDefaultIWApplicationContext() .getApplicationSettings() .getProperty(OpenIDConstants.PROPERTY_OPENID_IDENTITY_FORMAT, "http://{0}.elykill.is"); String identity = MessageFormat.format(identityFormat, getUserBusiness(iwc).getUserLogin(user)); return identity; }
protected List<User> getUsersHavingHandlerRole() { String roleKey = getHandlerRoleKey(); if (StringUtil.isEmpty(roleKey)) { return null; } IWApplicationContext iwac = IWMainApplication.getDefaultIWApplicationContext(); AccessController accessControler = IWMainApplication.getDefaultIWMainApplication().getAccessController(); Collection<Group> groupsWithRole = accessControler.getAllGroupsForRoleKey(roleKey, iwac); if (ListUtil.isEmpty(groupsWithRole)) { return null; } UserBusiness userBusiness = getUserBusiness(); if (userBusiness == null) { return null; } List<User> users = new ArrayList<User>(); for (Group group : groupsWithRole) { if (group instanceof User) { User user = (User) group; if (!users.contains(user)) { users.add(user); } } else { Collection<User> usersInGroup = null; try { usersInGroup = userBusiness.getUsersInGroup(group); } catch (Exception e) { LOGGER.log(Level.WARNING, "Error getting users in group: " + group, e); } if (!ListUtil.isEmpty(usersInGroup)) { for (User user : usersInGroup) { if (!users.contains(user)) { users.add(user); } } } } } return users; }
public String getUriToAttachment(String commentId, ICFile attachment, User user) { URIUtil uri = new URIUtil(IWMainApplication.getDefaultIWMainApplication().getMediaServletURI()); uri.setParameter( MediaWritable.PRM_WRITABLE_CLASS, IWMainApplication.getEncryptedClassName(CommentAttachmentDownloader.class)); uri.setParameter(ArticleCommentAttachmentStatisticsViewer.COMMENT_ID_PARAMETER, commentId); uri.setParameter( ArticleCommentAttachmentStatisticsViewer.COMMENT_ATTACHMENT_ID_PARAMETER, attachment.getPrimaryKey().toString()); if (user != null) { uri.setParameter(LoginBusinessBean.PARAM_LOGIN_BY_UNIQUE_ID, user.getUniqueId()); uri.setParameter(LoginBusinessBean.LoginStateParameter, LoginBusinessBean.LOGIN_EVENT_LOGIN); } return uri.getUri(); }
protected Locale getCurrentLocale() { IWContext iwc = CoreUtil.getIWContext(); Locale locale = iwc == null ? null : iwc.getCurrentLocale(); if (locale == null) { locale = IWMainApplication.getDefaultIWMainApplication().getDefaultLocale(); } return locale == null ? Locale.ENGLISH : locale; }
protected String getHost() { ICDomain domain = null; IWContext iwc = CoreUtil.getIWContext(); if (iwc == null) { domain = IWMainApplication.getDefaultIWApplicationContext().getDomain(); } else domain = iwc.getDomain(); int port = domain.getServerPort(); String host = domain.getServerProtocol().concat("://").concat(domain.getServerName()); if (port > 0) host = host.concat(":").concat(String.valueOf(port)); return host; }
@Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { if (iwma == null) { iwma = IWMainApplication.getIWMainApplication(servletConfig.getServletContext()); } if (request.getParameter(PARAMETER_NAME) != null || request.getParameter("image_id") != null) { new MediaOutputWriter().doPost(request, response, iwma); } else if (request.getParameter(PRM_SESSION_MEMORY_BUFFER) != null) { new MemoryFileBufferWriter().doPost(request, response); } else if (request.getParameter(MediaWritable.PRM_WRITABLE_CLASS) != null) { IWContext iwc = null; try { FacesContext facesContext = facesContextFactory.getFacesContext( servletConfig.getServletContext(), request, response, lifecycle); iwc = IWContext.getIWContext(facesContext); } catch (Exception e) { e.printStackTrace(); } try { if (iwc == null) { iwc = new IWContext(request, response, servletConfig.getServletContext()); } String mediaWriter = request.getParameter(MediaWritable.PRM_WRITABLE_CLASS); MediaWritable mw = (MediaWritable) RefactorClassRegistry.forName(IWMainApplication.decryptClassName(mediaWriter)) .newInstance(); mw.init(request, iwc); response.setContentType(mw.getMimeType()); ServletOutputStream out = response.getOutputStream(); mw.writeTo(out); out.flush(); } catch (Exception ex) { ex.printStackTrace(); } } }
public boolean validateTicket(java.lang.String in0, java.lang.String in1) throws java.rmi.RemoteException { try { WSTicketBusiness bus1 = (WSTicketBusiness) IBOLookup.getServiceInstance( IWMainApplication.getDefaultIWApplicationContext(), WSTicketBusiness.class); return bus1.validateTicket(in0, in1); } catch (Exception ex) { ex.printStackTrace(); return false; } }
@SuppressWarnings("unchecked") protected <T extends IBOService> T getServiceInstance( IWApplicationContext iwac, Class<? extends IBOService> serviceBeanClass) { try { // Casting is needed to avoid stupid compilation error in Maven 2 return (T) IBOLookup.getServiceInstance( iwac == null ? IWMainApplication.getDefaultIWApplicationContext() : iwac, serviceBeanClass); } catch (Exception e) { LOGGER.log(Level.WARNING, "Error getting service instance: " + serviceBeanClass); } return null; }
public MarathonWS2Client(IWMainApplication iwma) { IWMainApplicationSettings settings = iwma.getSettings(); String propServiceUrl = settings.getProperty(PROP_GLITNIR_MARATHONWS_URL); String propUserName = settings.getProperty(PROP_GLITNIR_MARATHONWS_USERNAME); String propPassword = settings.getProperty(PROP_GLITNIR_MARATHONWS_PASSWORD); if (propServiceUrl != null) { setServiceUrl(propServiceUrl); } if (propUserName != null) { setUserName(propUserName); } if (propPassword != null) { setPassword(propPassword); } }
/** * Method that uses the Java Mail API to send an email message.<br> * It is recommended to use the <type>com.idega.core.messaging.EmailMessage</type> class rather * than calling this method directly. * * @param from * @param to * @param cc * @param bcc * @param replyTo * @param host * @param subject * @param text * @param mailType: plain text, HTML etc. * @param attachedFiles * @throws MessagingException */ public static void send( String from, String to, String cc, String bcc, String replyTo, String host, String subject, String text, String mailType, File... attachedFiles) throws MessagingException { // Charset usually either "UTF-8" or "ISO-8859-1". If not set the system default set is taken IWMainApplicationSettings settings = IWMainApplication.getDefaultIWApplicationContext().getApplicationSettings(); String charset = settings.getCharSetForSendMail(); boolean useSmtpAuthentication = settings.getBoolean(MessagingSettings.PROP_SYSTEM_SMTP_USE_AUTHENTICATION, Boolean.FALSE); boolean useSSL = settings.getBoolean(MessagingSettings.PROP_SYSTEM_SMTP_USE_SSL, Boolean.FALSE); String username = settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_USER_NAME, CoreConstants.EMPTY); String password = settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_PASSWORD, CoreConstants.EMPTY); String port = settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_PORT, CoreConstants.EMPTY); if (StringUtil.isEmpty(host)) { host = settings.getProperty(MessagingSettings.PROP_SYSTEM_SMTP_MAILSERVER); if (StringUtil.isEmpty(host)) { throw new MessagingException("Mail server is not configured."); } } if (StringUtil.isEmpty(username)) { useSmtpAuthentication = false; } // Set the host smtp address Properties props = new Properties(); props.put("mail.smtp.host", host); // Set the smtp server port if (!StringUtil.isEmpty(port)) { props.put("mail.smtp.port", port); } // Start a session Session session; if (useSmtpAuthentication) { props.put("mail.smtp.auth", Boolean.TRUE.toString()); Authenticator auth = new SMTPAuthenticator(username, password); if (useSSL) { props.put("mail.smtp.ssl.enable", Boolean.TRUE.toString()); } session = Session.getInstance(props, auth); } else { session = Session.getInstance(props, null); } // Set debug if needed session.setDebug(settings.isDebugActive()); // Construct a message if (StringUtil.isEmpty(from)) { throw new MessagingException("From address is null."); } MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); // Process to, cc and bcc addRecipients(message, Message.RecipientType.TO, to); addRecipients(message, Message.RecipientType.CC, cc); addRecipients(message, Message.RecipientType.BCC, bcc); if (!StringUtil.isEmpty(replyTo)) { message.setReplyTo(InternetAddress.parse(replyTo)); } message.setSubject(subject, charset); if (ArrayUtil.isEmpty(attachedFiles)) { setMessageContent(message, text, mailType, charset); } else { MimeBodyPart body = new MimeBodyPart(); setMessageContent(body, text, mailType, charset); MimeMultipart multipart = new MimeMultipart(); multipart.addBodyPart(body); for (File attachedFile : attachedFiles) { if (attachedFile == null) { continue; } BodyPart attachment = new MimeBodyPart(); DataSource attachmentSource = new FileDataSource(attachedFile); DataHandler attachmentHandler = new DataHandler(attachmentSource); attachment.setDataHandler(attachmentHandler); attachment.setFileName(attachedFile.getName()); attachment.setDescription("Attached file: " + attachment.getFileName()); LOGGER.info("Adding attachment " + attachment); multipart.addBodyPart(attachment); } message.setContent(multipart); } // Send the message and close the connection Transport.send(message); }
@SuppressWarnings("unchecked") protected void processRequest(HttpServletRequest req, HttpServletResponse resp, boolean isPost) throws ServletException, IOException { ServerManager manager = getServerManager(); IWMainApplication iwma = IWMainApplication.getIWMainApplication(req); // extract the parameters from the request ParameterList requestParameters = new ParameterList(req.getParameterMap()); OpenIDServerBean serverBean = ELUtil.getInstance().getBean("openIDServerBean"); ParameterList sessionStoredParameterList = serverBean.getParameterList(); if (sessionStoredParameterList != null) { if (!requestParameters.hasParameter(OpenIDConstants.PARAMETER_OPENID_MODE)) { sessionStoredParameterList.addParams(requestParameters); requestParameters = sessionStoredParameterList; } } String mode = requestParameters.hasParameter(OpenIDConstants.PARAMETER_OPENID_MODE) ? requestParameters.getParameterValue(OpenIDConstants.PARAMETER_OPENID_MODE) : null; String realm = requestParameters.hasParameter(OpenIDConstants.PARAMETER_REALM) ? requestParameters.getParameterValue(OpenIDConstants.PARAMETER_REALM) : null; if (realm != null) { serverBean.setReturnUrl(realm); realm = getRealmName(realm); serverBean.setRealm(realm); } Message response; String responseText = null; try { if (OpenIDConstants.PARAMETER_ASSOCIATE.equals(mode)) { // --- process an association request --- response = manager.associationResponse(requestParameters); responseText = response.keyValueFormEncoding(); } else if (OpenIDConstants.PARAMETER_CHECKID_SETUP.equals(mode) || OpenIDConstants.PARAMETER_CHECKID_IMMEDIATE.equals(mode)) { IWContext iwc = new IWContext(req, resp, getServletContext()); boolean goToLogin = doRedirectToLoginPage(manager, requestParameters, iwc, realm); if (!goToLogin) { serverBean.setParameterList(null); serverBean.setServerUrl(null); serverBean.setDoRedirect(null); serverBean.setUsername(null); // interact with the user and obtain data needed to continue User user = iwc.getCurrentUser(); String userSelectedClaimedId = getUserSelectedClaimedId(iwc, user); // --- process an authentication request --- AuthRequest authReq = AuthRequest.createAuthRequest(requestParameters, manager.getRealmVerifier()); storeRequestedAttributesToSession(iwc, authReq); Boolean authenticatedAndApproved = isAuthenticatedAndApproved(iwc, user, authReq); String opLocalId = null; // if the user chose a different claimed_id than the one in request if (userSelectedClaimedId != null && !userSelectedClaimedId.equals(authReq.getClaimed())) { opLocalId = userSelectedClaimedId; } response = manager.authResponse( requestParameters, opLocalId, userSelectedClaimedId, authenticatedAndApproved.booleanValue(), false); // Sign after we added extensions. if (response instanceof DirectError) { directResponse(resp, response.keyValueFormEncoding()); return; } else if (response instanceof AuthFailure) { redirectToAuthorisationPage(req, resp, requestParameters, serverBean); return; } else { String[] extensionsToSign = prepareResponse(serverBean, response, iwc, user, authReq); boolean signExtensions = iwma.getSettings().getBoolean(OpenIDConstants.PROPERTY_SIGN_EXTENSIONS, false); AuthSuccess success = (AuthSuccess) response; if (signExtensions) { success.setSignExtensions(extensionsToSign); } // Sign the auth success message. // This is required as AuthSuccess.buildSignedList has a `todo' tag now. manager.sign(success); // caller will need to decide which of the following to use: // option1: GET HTTP-redirect to the return_to URL // cleanUpBeforeReturning(iwc, loginExpireHandle); // Clean up before returning serverBean.invalidate(); getDAO().createLogEntry(user.getUniqueId(), realm, ""); resp.sendRedirect(response.getDestinationUrl(true)); return; // option2: HTML FORM Redirection // RequestDispatcher dispatcher = // getServletContext().getRequestDispatcher("formredirection.jsp"); // httpReq.setAttribute("parameterMap", response.getParameterMap()); // httpReq.setAttribute("destinationUrl", response.getDestinationUrl(false)); // dispatcher.forward(request, response); // return null; } } else { redirectToLoginPage(req, resp, requestParameters, serverBean, manager); return; } } else if (OpenIDConstants.PARAMETER_CHECK_AUTHENTICATION.equals(mode)) { // --- processing a verification request --- response = manager.verify(requestParameters); responseText = response.keyValueFormEncoding(); } else { // --- error response --- response = DirectError.createDirectError("Unknown request"); responseText = response.keyValueFormEncoding(); serverBean.invalidate(); } } catch (MessageException me) { me.printStackTrace(); responseText = me.getMessage(); serverBean.invalidate(); } catch (AssociationException ae) { ae.printStackTrace(); responseText = ae.getMessage(); serverBean.invalidate(); } catch (ServerException se) { se.printStackTrace(); responseText = se.getMessage(); serverBean.invalidate(); } // return the result to the user directResponse(resp, responseText); }
protected IWMainApplication getApplication() { return IWMainApplication.getDefaultIWMainApplication(); }