Package org.openid4java.server

Examples of org.openid4java.server.ServerManager


  public void init(ServletConfig config) throws ServletException {
    super.init(config);

    context = config.getServletContext();

    this.manager = new ServerManager();
    manager.setOPEndpointUrl(OP_ENDPOINT_URL);
        manager.getRealmVerifier().setEnforceRpId(false);
        manager.setSharedAssociations(new InMemoryServerAssociationStore());
        manager.setPrivateAssociations(new InMemoryServerAssociationStore());
   
View Full Code Here


        return serverManager;
    }

    @Inject
    public void startup() throws Exception {
        serverManager = new ServerManager();
        serverManager.setOPEndpointUrl(providerBean.get().getServiceURL(OpenIdService.OPEN_ID_SERVICE));
    }
View Full Code Here

   }

   @Inject
   public void startup() throws Exception
   {
      serverManager = new ServerManager();
      serverManager.setOPEndpointUrl(providerBean.getServiceURL(OpenIdService.OPEN_ID_SERVICE));
   }
View Full Code Here

        ParameterList paramList = null;
        Message message = null;
        paramList = getParameterList(request.getParams());
        String destinationUrl = null;
        AuthRequest authReq = null;
        ServerManager manager = null;
        OpenIDAuthResponseDTO response = null;

        response = new OpenIDAuthResponseDTO();
        manager = OpenIDProvider.getInstance().getManager();
        authReq = AuthRequest.createAuthRequest(paramList, manager.getRealmVerifier());
        message = manager.authResponse(paramList, request.getOpLocalId(), request
                .getUserSelectedClaimedId(), request.isAuthenticated());

        if (message instanceof DirectError || message instanceof AuthFailure) {
            // Validation fails - returns 'cancel'.
            destinationUrl = message.getDestinationUrl(true);
            response.setDestinationUrl(destinationUrl);
            response.setValidated(false);
        } else {
            OpenIDExtension extension = null;
            OpenIDAuthenticationRequest req = null;
            req = new OpenIDAuthenticationRequest();

            if (request.isPhishiingResistanceAuthRequest()) {
                // Relying party requests phishing-resistant login.
                req.setPhishingResistanceLogin(true);
            }
            if (request.isMultiFactorAuthRequested()) {
                // Relying party requests phishing-resistant login.
                req.setMultifactorLogin(true);
            }

            req.setAuthRequest(authReq);

            // A given OpenID authentication request can contain multiple
            // extensions.
            // OpenIDProvider is not aware of extensions - we simply delegate
            // the extension
            // processing logic to a subclass of OpenIDExtension.
            for (Object alias : authReq.getExtensions()) {
                req.setExtensionAlias((String) alias);

                // Get the corresponding OpenIDExtension instance from the
                // OpenIDExtensionFactory.
                extension = OpenIDExtensionFactory.getInstance().getExtension(req);
                if (extension != null) {
                    MessageExtension messageExtension = null;
                    messageExtension = extension.getMessageExtension(request.getOpenID(), request
                            .getProfileName());
                    if (messageExtension != null) {
                        message.addExtension(messageExtension);
                        AuthSuccess authSuccess = (AuthSuccess) message;
                        authSuccess.addSignExtension((String) alias);
                        manager.sign(authSuccess);
                    }
                }
            }

            // We only have SReg extensions.
View Full Code Here

        ParameterList paramList = getParameterList(papeInfoRequestDto.getParamList());
        String username = OpenIDUtil.getUserName(papeInfoRequestDto.getOpenID());

        AuthRequest authReq = null;
        ServerManager manager = null;
        String domainName = null;
        Registry registry;
        String tenatUser = null;

        try {
            manager = OpenIDProvider.getInstance().getManager();
            authReq = AuthRequest.createAuthRequest(paramList, manager.getRealmVerifier());
            OpenIDAuthenticationRequest req = new OpenIDAuthenticationRequest();
            req.setAuthRequest(authReq);
            setPAPEProperties(req, paramList);
            domainName = TenantUtils.getDomainNameFromOpenId(papeInfoRequestDto.getOpenID());
            tenatUser = UserCoreUtil.getTenantLessUsername(username);
View Full Code Here

    @Get("form")
    public Representation represent() throws ParserConfigurationException {
        Document response = null;

        ConcurrentMap<String, Object> attribs = getContext().getAttributes();
        ServerManager manager = (ServerManager) attribs.get("openid_manager");
        String opEndpoint = manager.getOPEndpointUrl();

        Form query = getQuery();
        String returnTo = query.getFirstValue("returnTo");
        if (returnTo != null && returnTo.length() > 0) { // OP Server lookup
            response = createDocument(TYPE_RETURN_TO, returnTo, null);
View Full Code Here

    private Representation handle(ParameterList request) {
        Logger log = getLogger();
        log.info("Handle on OP");
        ConcurrentMap<String, Object> attribs = getContext().getAttributes();
        ServerManager manager = (ServerManager) attribs.get("openid_manager");
        log.info("OP endpoint = " + manager.getOPEndpointUrl());

        String mode = request.hasParameter("openid.mode") ? request
                .getParameterValue("openid.mode") : null;

        Message response;
        String responseText;

        if ("associate".equals(mode)) {
            // --- process an association request ---
            response = manager.associationResponse(request);
            responseText = response.keyValueFormEncoding();
        } else if ("checkid_setup".equals(mode)
                || "checkid_immediate".equals(mode)) {
            // interact with the user and obtain data needed to continue
            List<?> userData = userInteraction(request,
                    manager.getOPEndpointUrl());

            String userSelectedId = (String) userData.get(0);
            String userSelectedClaimedId = (String) userData.get(1);
            Boolean authenticatedAndApproved = (Boolean) userData.get(2);

            // --- process an authentication request ---
            response = manager.authResponse(request, userSelectedId,
                    userSelectedClaimedId,
                    authenticatedAndApproved.booleanValue());

            if (response instanceof DirectError) {
                Form f = new Form();
                @SuppressWarnings("unchecked")
                Map<String, String> m = (Map<String, String>) response
                        .getParameterMap();
                for (String key : m.keySet()) {
                    f.add(key, m.get(key));
                }
                return f.getWebRepresentation();
            } else {
                // caller will need to decide which of the following to use:

                // option1: GET HTTP-redirect to the return_to URL
                // return new
                // StringRepresentation(response.getDestinationUrl(true));
                redirectSeeOther(response.getDestinationUrl(true));
                return new EmptyRepresentation();

                // option2: HTML FORM Redirection
                // RequestDispatcher dispatcher =
                // getServletContext().getRequestDispatcher("formredirection.jsp");
                // httpReq.setAttribute("prameterMap",
                // response.getParameterMap());
                // httpReq.setAttribute("destinationUrl",
                // response.getDestinationUrl(false));
                // dispatcher.forward(request, response);
                // return null;
            }
        } else if ("check_authentication".equals(mode)) {
            // --- processing a verification request ---
            response = manager.verify(request);
            log.info("OpenID : " + response.keyValueFormEncoding());
            responseText = response.keyValueFormEncoding();
        } else if (Method.GET.equals(getMethod())) {
            // Could be a discovery request
            sendXRDSLocation();
View Full Code Here

          session.setAttribute("authenticatedAndApproved", authorizedUser);
        }
      }
    }
   
    ServerManager manager = ((SimpleServiceProxy)getServiceProxy()).getServerManager();
    // extract the parameters from the request
    ParameterList parameterList = null;
       
    if (session.getAttribute("parameterlist")!=null) {
      parameterList = (ParameterList) session.getAttribute("parameterlist");
View Full Code Here

    // return the result to the user
    return directResponse(response,messageResponse.keyValueFormEncoding());
  }

  private String checkAuthentication(HttpServletRequest request, HttpServletResponse response, ParameterList parameterList) throws IOException {
    ServerManager manager = ((SimpleServiceProxy)getServiceProxy()).getServerManager();
    HttpSession session = request.getSession();
    Message messageResponse;
    String responseText;
   
    // --- processing a verification request ---
    messageResponse = manager.verify(parameterList);
    responseText = messageResponse.keyValueFormEncoding();
    return directResponse(response, messageResponse.keyValueFormEncoding());
  }
View Full Code Here

    responseText = messageResponse.keyValueFormEncoding();
    return directResponse(response, messageResponse.keyValueFormEncoding());
  }

  private String checkId(HttpServletRequest request, HttpServletResponse response, ParameterList parameterList) throws ServletException, IOException {
    ServerManager manager = ((SimpleServiceProxy)getServiceProxy()).getServerManager();
    HttpSession session = request.getSession();
    Message messageResponse;
    String responseText;
   
    // interact with the user and obtain data needed to continue
    String userSelectedId = null;
    String userSelectedClaimedId = null;
    User authenticatedAndApproved = null;
    String email = "";

    if (session.getAttribute("authenticatedAndApproved") == null) {
      session.setAttribute("parameterlist", parameterList);
      String wwwParams = wwwFormEncoding(parameterList);
      String url = "login.jsp?" + wwwParams;
      response.sendRedirect(url);
      return null;
    } else {
      userSelectedId = (String) session.getAttribute("openid.claimed_id");
      userSelectedClaimedId = (String) session.getAttribute("openid.identity");
      authenticatedAndApproved = (User) session.getAttribute("authenticatedAndApproved");
      // Remove the parameterlist so this provider can accept requests from elsewhere
      session.removeAttribute("parameterlist");
      session.setAttribute("authenticatedAndApproved", null);
    }

    // --- process an authentication request ---
    AuthRequest authReq = null;
    String opLocalId = null;

    try {
      authReq = AuthRequest.createAuthRequest(parameterList, manager.getRealmVerifier());
      // if the user chose a different claimed_id than the one in request
      if (userSelectedClaimedId != null && userSelectedClaimedId.equals(authReq.getClaimed())) {
        //opLocalId = "http://localhost:8081/idp4java/idp";//lookupLocalId(userSelectedClaimedId);
      }
    } catch (MessageException e) {
      e.printStackTrace();
      throw new ServletException(e);
    }

    // --- process an authentication request ---
    //messageResponse = manager.authResponse(parameterList, userSelectedId, userSelectedClaimedId, true);
    messageResponse = manager.authResponse(parameterList, opLocalId, opLocalId, true);
   

    if (messageResponse instanceof DirectError)
      return directResponse(response, messageResponse.keyValueFormEncoding());
    else {

            try {
        if (authReq.hasExtension(AxMessage.OPENID_NS_AX))
        {
            MessageExtension ext = authReq.getExtension(AxMessage.OPENID_NS_AX);
            if (ext instanceof FetchRequest)
            {
                FetchRequest fetchReq = (FetchRequest) ext;
                Map required = fetchReq.getAttributes(true);
                Map optional = fetchReq.getAttributes(false);
                if (required.containsKey("email"))
                {
                    Map userDataExt = new HashMap();
                    userDataExt.put("email", "someone@someplace.com");
                    FetchResponse fetchResp = FetchResponse.createFetchResponse(fetchReq, userDataExt);
                    // (alternatively) manually add attribute values
                    //fetchResp.addAttribute("email", "http://schema.openid.net/contact/email", email);
                    messageResponse.addExtension(fetchResp);
                }
            }
            else //if (ext instanceof StoreRequest)
            {
                throw new UnsupportedOperationException("TODO");
            }
        }
        if (authReq.hasExtension(SRegMessage.OPENID_NS_SREG))
        {
            MessageExtension ext = authReq.getExtension(SRegMessage.OPENID_NS_SREG);
            if (ext instanceof SRegRequest)
            {
                SRegRequest sregReq = (SRegRequest) ext;
                List required = sregReq.getAttributes(true);
                List optional = sregReq.getAttributes(false);
                if (required.contains("email"))
                {
                    // data released by the user
                    Map userDataSReg = new HashMap();
                    userDataSReg.put("email", "user@example.com");

                    SRegResponse sregResp = SRegResponse.createSRegResponse(sregReq, userDataSReg);
                    // (alternatively) manually add attribute values
                    //sregResp.addAttribute("email", email);
                    messageResponse.addExtension(sregResp);
                }
            }
            else
            {
                throw new UnsupportedOperationException("TODO");
            }
        }

        // Sign the auth success message.
        // This is required as AuthSuccess.buildSignedList has a `todo' tag now.
        manager.sign((AuthSuccess) messageResponse);
      } catch (MessageException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ServerException e) {
        // TODO Auto-generated catch block
View Full Code Here

TOP

Related Classes of org.openid4java.server.ServerManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.