Java Code Examples for org.gluu.oxauth.model.util.Util#isNullOrEmpty()

The following examples show how to use org.gluu.oxauth.model.util.Util#isNullOrEmpty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OxAuthCryptoProvider.java    From oxAuth with MIT License 6 votes vote down vote up
public OxAuthCryptoProvider(String keyStoreFile, String keyStoreSecret, String dnName, boolean rejectNoneAlg) throws Exception {
    this.rejectNoneAlg = rejectNoneAlg;
    if (!Util.isNullOrEmpty(keyStoreFile) && !Util.isNullOrEmpty(keyStoreSecret) /* && !Util.isNullOrEmpty(dnName) */) {
        this.keyStoreFile = keyStoreFile;
        this.keyStoreSecret = keyStoreSecret;
        this.dnName = dnName;

        keyStore = KeyStore.getInstance("JKS");
        try {
            File f = new File(keyStoreFile);
            if (!f.exists()) {
                keyStore.load(null, keyStoreSecret.toCharArray());
                FileOutputStream fos = new FileOutputStream(keyStoreFile);
                keyStore.store(fos, keyStoreSecret.toCharArray());
                fos.close();
            }
            final InputStream is = new FileInputStream(keyStoreFile);
            keyStore.load(is, keyStoreSecret.toCharArray());
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
        }
    }
}
 
Example 2
Source File: OxAuthCryptoProvider.java    From oxAuth with MIT License 6 votes vote down vote up
public PublicKey getPublicKey(String alias) {
    PublicKey publicKey = null;

    try {
        if (Util.isNullOrEmpty(alias)) {
            return null;
        }

        java.security.cert.Certificate certificate = keyStore.getCertificate(alias);
        if (certificate == null) {
            return null;
        }
        publicKey = certificate.getPublicKey();

        checkKeyExpiration(alias);
    } catch (KeyStoreException e) {
        e.printStackTrace();
    }

    return publicKey;
}
 
Example 3
Source File: OxAuthCryptoProvider.java    From oxAuth with MIT License 6 votes vote down vote up
public PrivateKey getPrivateKey(String alias)
        throws UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException {
    if (Util.isNullOrEmpty(alias)) {
        return null;
    }

    Key key = keyStore.getKey(alias, keyStoreSecret.toCharArray());
    if (key == null) {
        return null;
    }
    PrivateKey privateKey = (PrivateKey) key;

    checkKeyExpiration(alias);

    return privateKey;
}
 
Example 4
Source File: EndSessionUtils.java    From oxAuth with MIT License 5 votes vote down vote up
public static String createFronthannelHtml(Set<String> logoutUris, String postLogoutUrl, String state) {
    String iframes = "";
    for (String logoutUri : logoutUris) {
        iframes = iframes + String.format("<iframe height=\"0\" width=\"0\" src=\"%s\" sandbox=\"allow-same-origin allow-scripts allow-popups allow-forms\"></iframe>", logoutUri);
    }

    String html = "<!DOCTYPE html>" +
            "<html>" +
            "<head>";

    if (!Util.isNullOrEmpty(postLogoutUrl)) {

        if (!Util.isNullOrEmpty(state)) {
            if (postLogoutUrl.contains("?")) {
                postLogoutUrl += "&state=" + state;
            } else {
                postLogoutUrl += "?state=" + state;
            }
        }

        html += "<script>" +
                "window.onload=function() {" +
                "window.location='" + postLogoutUrl + "'" +
                "}" +
                "</script>";
    }

    html += "<title>Your logout was successful</title>" +
            "</head>" +
            "<body>" +
            "Your logout was successful.<br/>" +
            iframes +
            "</body>" +
            "</html>";
    return html;
}
 
Example 5
Source File: RegisterParamsValidator.java    From oxAuth with MIT License 5 votes vote down vote up
public void validateLogoutUri(String logoutUri, List<String> redirectUris, ErrorResponseFactory errorResponseFactory) {
    if (Util.isNullOrEmpty(logoutUri)) { // logout uri is optional so null or empty string is valid
        return;
    }

    // preconditions
    if (redirectUris == null || redirectUris.isEmpty()) {
        log.debug("Preconditions of logout uri validation are failed.");
        throwInvalidLogoutUri(errorResponseFactory);
        return;
    }

    try {
        Set<String> redirectUriHosts = collectUriHosts(redirectUris);

        URI uri = new URI(logoutUri);

        if (!redirectUriHosts.contains(uri.getHost())) {
            log.debug("logout uri host is not within redirect_uris, logout_uri: {}, redirect_uris: {}", logoutUri, redirectUris);
            throwInvalidLogoutUri(errorResponseFactory);
            return;
        }

        if (!HTTPS.equalsIgnoreCase(uri.getScheme())) {
            log.debug("logout uri schema is not https, logout_uri: {}", logoutUri);
            throwInvalidLogoutUri(errorResponseFactory);
        }
    } catch (Exception e) {
        log.debug(e.getMessage(), e);
        throwInvalidLogoutUri(errorResponseFactory);
    }
}
 
Example 6
Source File: UserService.java    From oxAuth with MIT License 5 votes vote down vote up
/**
 * returns User by Dn
 *
 * @return User
 */
@Nullable
public User getUserByDn(String dn, String... returnAttributes) {
    if (Util.isNullOrEmpty(dn)) {
        return null;
    }
    return persistenceEntryManager.find(dn, User.class, returnAttributes);
}
 
Example 7
Source File: JSONWebKey.java    From oxAuth with MIT License 5 votes vote down vote up
public JSONObject toJSONObject() throws JSONException {
    JSONObject jsonObj = new JSONObject();

    jsonObj.put(KEY_ID, kid);
    jsonObj.put(KEY_TYPE, kty);
    jsonObj.put(KEY_USE, use != null ? use.getParamName() : "");
    jsonObj.put(ALGORITHM, alg);
    jsonObj.put(EXPIRATION_TIME, exp);
    jsonObj.put(CURVE, crv != null ? crv.getName() : "");
    if (!Util.isNullOrEmpty(n)) {
        jsonObj.put(MODULUS, n);
    }
    if (!Util.isNullOrEmpty(e)) {
        jsonObj.put(EXPONENT, e);
    }
    if (!Util.isNullOrEmpty(x)) {
        jsonObj.put(X, x);
    }
    if (!Util.isNullOrEmpty(y)) {
        jsonObj.put(Y, y);
    }
    if (x5c != null && !x5c.isEmpty()) {
        jsonObj.put(CERTIFICATE_CHAIN, StringUtils.toJSONArray(x5c));
    }

    return jsonObj;
}
 
Example 8
Source File: RedirectionUriService.java    From oxAuth with MIT License 4 votes vote down vote up
public String validatePostLogoutRedirectUri(String clientId, String postLogoutRedirectUri) {

        boolean isBlank = Util.isNullOrEmpty(postLogoutRedirectUri);

        Client client = clientService.getClient(clientId);

        if (client != null) {
            String[] postLogoutRedirectUris = client.getPostLogoutRedirectUris();
            log.debug("Validating post logout redirect URI: clientId = {}, postLogoutRedirectUri = {}", clientId, postLogoutRedirectUri);

            return validatePostLogoutRedirectUri(postLogoutRedirectUri, postLogoutRedirectUris);
        }

        if (!isBlank) {
            throw errorResponseFactory.createWebApplicationException(Response.Status.BAD_REQUEST, EndSessionErrorResponseType.POST_LOGOUT_URI_NOT_ASSOCIATED_WITH_CLIENT, "`post_logout_redirect_uri` is not added to associated client.");
        }

        return null;
    }