Package org.wso2.carbon.identity.base

Examples of org.wso2.carbon.identity.base.IdentityException


            String value = authReq.getDestinationUrl(true);
            return value;
        } catch (Exception e) {
            log.error(e.getMessage(), e);
            // Present error to the user
            throw new IdentityException(e.getMessage(), e);
        }
    }
View Full Code Here


            mode = response.getParameterValue(IdentityConstants.OpenId.ATTR_MODE);

            if (mode != null && IdentityConstants.OpenId.CANCEL.equals(mode)) {
                // User has denied sending his profile info :(
                throw new IdentityException("User has denied sending his profile info");
            }

            authSuccess = (AuthSuccess) verifyOpenID(request, response);

            claimList = new ArrayList<ClaimDTO>();

            for (Object alias : authSuccess.getExtensions()) {
                extension = OpenIDExtensionFactory.getInstance().getExtension((String) alias,
                        authSuccess);
                if (extension != null)
                    extension.setSessionAttributes(claimList);
            }

            openID = new OpenIDDTO();
            openID.setOpenID(authSuccess.getIdentity());
            openID.setClaims(claimList.toArray(new ClaimDTO[claimList.size()]));

            return openID;

        } catch (OpenIDException e) {
            log.error(e.getMessage());
            // Present error to the user.
            throw new IdentityException("OpenID authentication failed", e);
        }
    }
View Full Code Here

                if(authnMode.equals(SAMLSSOConstants.AuthnModes.OPENID) && !isExistingSession){
                    AuthnRequestProcessor authnRequestProcessor = new AuthnRequestProcessor();
                    try {
                        return authnRequestProcessor.process(validationResp, sessionId, rpSessionId, authnMode);
                    } catch (Exception e) {
                        throw new IdentityException("Error processing the Authentication Request", e);
                    }
                }
                if (isExistingSession) {
                    AuthnRequestProcessor authnRequestProcessor = new AuthnRequestProcessor();
                    try {
                        return authnRequestProcessor.process(validationResp, sessionId, rpSessionId, authnMode);
                    } catch (Exception e) {
                        throw new IdentityException("Error processing the Authentication Request", e);
                    }
                }
            }
            validationResp.setRpSessionId(rpSessionId);
            return validationResp;
View Full Code Here

        AuthnRequestProcessor authnRequestProcessor = new AuthnRequestProcessor();
        try {
            return authnRequestProcessor.process(authReqDTO, sessionId, false,
                                                 SAMLSSOConstants.AuthnModes.USERNAME_PASSWORD);
        } catch (Exception e) {
            throw new IdentityException("Error when authenticating the users", e);
        }
    }
View Full Code Here

                } else {
                    return doOpenIDSignUp(dto.getUserName(), dto.getOpenID());
                }
            }
        } catch (Exception e) {
            throw new IdentityException(e.getMessage(), e);
        }

        return false;
    }
View Full Code Here

        String cookie = null;
        ConfigurationContext configContext = null;
        String serverURL = null;

        if (request == null || response == null) {
            throw new IdentityException("Required attributes missing");
        }

        try {
            session = request.getSession();
            serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session);
            configContext = (ConfigurationContext) session.getServletContext().getAttribute(
                    CarbonConstants.CONFIGURATION_CONTEXT);
            cookie = (String) session.getAttribute(OpenIDAdminClient.OPENID_ADMIN_COOKIE);
            client = new OpenIDAdminClient(configContext, serverURL, cookie);

            if (OpenId.COMPLETE.equals(session.getAttribute(OpenId.ACTION))
                    || OpenId.CANCEL.equals(session.getAttribute(OpenId.ACTION))) {
                // Ready for authentication.
                paramList = (ParameterList) session.getAttribute(OpenId.PARAM_LIST);
            } else {
                // Extract the parameters from the request.Authentication not
                // completed.
                paramList = new ParameterList(request.getParameterMap());
            }

            if (paramList == null) {
                responseText = getErrorResponseText("Invalid OpenID authentication request");
                if (log.isDebugEnabled()) {
                    log.debug("Invalid OpenID authentication request :" + responseText);
                }
                directResponse(response, responseText);
                return null;
            }

            String mode = paramList.hasParameter(OpenId.ATTR_MODE) ? paramList
                    .getParameterValue(OpenId.ATTR_MODE) : null;

            if (log.isDebugEnabled()) {
                log.debug("OpenID authentication mode :" + mode);
            }

            if (OpenId.ASSOCIATE.equals(mode)) {
                responseText = client.getOpenIDAssociationResponse(OpenIDUtil
                        .getOpenIDAuthRequest(request));
                if (log.isDebugEnabled()) {
                    log.debug("Association created successfully");
                }
            } else if (OpenId.CHECKID_SETUP.equals(mode) || OpenId.CHECKID_IMMEDIATE.equals(mode)) {
                return checkSetupOrImmediate(request, paramList);
            } else if (OpenId.CHECK_AUTHENTICATION.equals(mode)) {
                responseText = client.verify(OpenIDUtil.getOpenIDAuthRequest(request));
                if (log.isDebugEnabled()) {
                    log.debug("Authentication verified successfully");
                }
            } else {
                // Error response - oops..!!! we did not get a valid OpenID
                // mode.
                responseText = getErrorResponseText("No valid OpenID found in the authentication request");
                if (log.isDebugEnabled()) {
                    log.debug("No valid OpenID found in the authentication request");
                }
            }
        } catch (Exception e) {
            responseText = getErrorResponseText(e.getMessage());
        }

        try {
            // Return the result to the user.
            directResponse(response, responseText);
        } catch (IOException e) {
            log.error(e.getMessage());
            throw new IdentityException("OpenID redirect reponse failed");
        }

        return null;
    }
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("Authentication check for OpenID " + openId);
        }

        if (openId == null) {
            throw new IdentityException("Required attributes missing");
        }

        if (log.isDebugEnabled()) {
            log.debug("Authentication check for user " + openId);
        }
View Full Code Here

      // Set the default value
      issuerPolicy = TokenVerifierConstants.SELF_AND_MANGED;
    } else if (!(issuerPolicy.equals(TokenVerifierConstants.SELF_ONLY)
        || issuerPolicy.equals(TokenVerifierConstants.MANGED_ONLY) || issuerPolicy
        .equals(TokenVerifierConstants.SELF_AND_MANGED))) {
      throw new IdentityException("Invalid Issuer Policy!");
    }

    try {
      store = KeyStore.getInstance(storeType);
      stream = new FileInputStream(keyStore);
      store.load(stream, storePass.toCharArray());
      privateKey = (PrivateKey) store.getKey(keyAlias, keyPass.toCharArray());
      trustStore = store;
    } catch (Exception e) {
      throw new IdentityException("Cannot load the private key", e);
    } finally {
      if (stream != null) {
        try {
          stream.close();
        } catch (IOException e) {
          log.error("Error while closing system keystore file", e);
        }
      }
    }

    // Step 2: Reading Token validate policy - Promiscuous/BlackList/WhiteList/CertValidate

    // Promiscuous - In this mode, all tokens that has a valid signature are allowed
    // CertValidate - In this mode, all tokens that has a valid signature by an IdP who has a
    // trusted certificate are allowed
    // WhiteList - First CertValidity checked and after that if the issuer
    // DN is in the white list, the token is allowed
    // BlackList - First CertValidity checked and after that if the issuer
    // DN is not listed in the BlackList, the token is allowed

    validatePolicy = IdentityUtil.getProperty(ServerConfig.TOKEN_VALIDATE_POLICY);

    if (validatePolicy == null || validatePolicy.trim().length() == 0) {
      validatePolicy = TokenVerifierConstants.CERT_VALIDATE;
    }

    // Step 3: Reading parameters of each policy

    if (validatePolicy.equals(TokenVerifierConstants.BLACK_LIST)) {
      String value = IdentityUtil.getProperty(ServerConfig.BLACK_LIST);
      if (value != null) {
        blackList = readBlackWhiteList(value);
      }
    } else if (validatePolicy.equals(TokenVerifierConstants.WHITE_LIST)) {
      String value = IdentityUtil.getProperty(ServerConfig.WHITE_LIST);
      if (value != null) {
        whiteList = readBlackWhiteList(value);
      }
    }

    if (validatePolicy.equals(TokenVerifierConstants.WHITE_LIST)
        || validatePolicy.equals(TokenVerifierConstants.BLACK_LIST)
        || validatePolicy.equals(TokenVerifierConstants.CERT_VALIDATE)) {

      String javaHome = null;
      String defaultKeyStore = null;
      FileInputStream fileStream = null;
      KeyStore sysKS = null;

      String defaultStorePass = IdentityUtil.getProperty(ServerConfig.SYSTEM_KEY_STORE_PASS);
      if (defaultStorePass == null) {
        // assume that it hasn't been changed
        defaultStorePass = "changeit";
      }

      javaHome = System.getenv("JAVA_HOME");

      if (javaHome == null) {
        throw new IdentityException("Cannot find JAVA_HOME");
      }

      defaultKeyStore = IdentityUtil.getProperty(ServerConfig.SYSTEM_KEY_STORE);

      if (defaultKeyStore != null && defaultKeyStore.trim().length() > 0) {
        defaultKeyStore = javaHome + defaultKeyStore;
      } else {
        if (File.separator.equals("/")) {
          defaultKeyStore = javaHome + TokenVerifierConstants.CACERTS_STORE_UNIX;
        } else {
          defaultKeyStore = javaHome + TokenVerifierConstants.CACERTS_STORE_WIN;
        }
      }

      try {
        fileStream = new FileInputStream(defaultKeyStore);
        sysKS = KeyStore.getInstance("JKS");
        sysKS.load(fileStream, defaultStorePass.toCharArray());
        this.systemStore = sysKS;
            } catch (RuntimeException e){
                throw e;
      } catch (Exception e) {
        throw new IdentityException("Cannot load system key store");
      } finally {
        if (fileStream != null) {
          try {
            fileStream.close();
          } catch (IOException e) {
View Full Code Here

        try {
      uri = new URI(rquestUrl);
      path = uri.getPath();
    } catch (URISyntaxException e) {
      throw new IdentityException("Invalid OpenID", e);
    }

    caller = path.substring(path.indexOf(contextPath)
        + contextPath.length(), path.length());
    return caller;
View Full Code Here

        try {
            uri = new URI(openID);
        } catch (URISyntaxException e) {
            log.error("Invalid OpenID URL :" + openID, e);
            throw new IdentityException("Invalid OpenID URL");
        }

        try {
            url = uri.normalize().toURL();
            if (url.getQuery() != null || url.getRef() != null) {
                log.error("Invalid user name for OpenID :" + openID);
                throw new IdentityException("Invalid user name for OpenID");
            }
        } catch (MalformedURLException e) {
            log.error("Malformed OpenID URL :" + openID, e);
            throw new IdentityException("Malformed OpenID URL");
        }

        openID = url.toString();

        if (log.isDebugEnabled()) {
View Full Code Here

TOP

Related Classes of org.wso2.carbon.identity.base.IdentityException

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.