Search in sources :

Example 1 with AppConfiguration

use of org.gluu.oxauth.model.configuration.AppConfiguration in project oxAuth by GluuFederation.

the class CrossEncryptionTest method nestedJWTProducedByGluu.

@Test
public void nestedJWTProducedByGluu() throws Exception {
    AppConfiguration appConfiguration = new AppConfiguration();
    List<JSONWebKey> keyArrayList = new ArrayList<JSONWebKey>();
    keyArrayList.add(getSenderWebKey());
    JSONWebKeySet keySet = new JSONWebKeySet();
    keySet.setKeys(keyArrayList);
    final JwtSigner jwtSigner = new JwtSigner(appConfiguration, keySet, SignatureAlgorithm.RS256, "audience", null, new AbstractCryptoProvider() {

        @Override
        public JSONObject generateKey(Algorithm algorithm, Long expirationTime, Use use) throws Exception {
            return null;
        }

        @Override
        public JSONObject generateKey(Algorithm algorithm, Long expirationTime, Use use, int keyLength) throws Exception {
            return null;
        }

        @Override
        public boolean containsKey(String keyId) {
            return false;
        }

        @Override
        public String sign(String signingInput, String keyId, String sharedSecret, SignatureAlgorithm signatureAlgorithm) throws Exception {
            RSAPrivateKey privateKey = ((RSAKey) JWK.parse(senderJwkJson)).toRSAPrivateKey();
            Signature signature = Signature.getInstance(signatureAlgorithm.getAlgorithm(), "BC");
            signature.initSign(privateKey);
            signature.update(signingInput.getBytes());
            return Base64Util.base64urlencode(signature.sign());
        }

        @Override
        public boolean verifySignature(String signingInput, String encodedSignature, String keyId, JSONObject jwks, String sharedSecret, SignatureAlgorithm signatureAlgorithm) throws Exception {
            return false;
        }

        @Override
        public boolean deleteKey(String keyId) throws Exception {
            return false;
        }

        @Override
        public PrivateKey getPrivateKey(String keyId) throws Exception {
            throw new UnsupportedOperationException("Method not implemented.");
        }
    });
    Jwt jwt = jwtSigner.newJwt();
    jwt.getClaims().setSubjectIdentifier("testing");
    jwt.getClaims().setIssuer("https:devgluu.saminet.local");
    jwt = jwtSigner.sign();
    RSAKey recipientPublicJWK = (RSAKey) (JWK.parse(recipientJwkJson));
    BlockEncryptionAlgorithm blockEncryptionAlgorithm = BlockEncryptionAlgorithm.A128GCM;
    KeyEncryptionAlgorithm keyEncryptionAlgorithm = KeyEncryptionAlgorithm.RSA_OAEP;
    Jwe jwe = new Jwe();
    jwe.getHeader().setType(JwtType.JWT);
    jwe.getHeader().setAlgorithm(keyEncryptionAlgorithm);
    jwe.getHeader().setEncryptionMethod(blockEncryptionAlgorithm);
    jwe.getHeader().setKeyId("1");
    jwe.setSignedJWTPayload(jwt);
    JweEncrypterImpl encrypter = new JweEncrypterImpl(keyEncryptionAlgorithm, blockEncryptionAlgorithm, recipientPublicJWK.toPublicKey());
    String jweString = encrypter.encrypt(jwe).toString();
    decryptAndValidateSignatureWithGluu(jweString);
    decryptAndValidateSignatureWithNimbus(jweString);
}
Also used : RSAKey(com.nimbusds.jose.jwk.RSAKey) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) PrivateKey(java.security.PrivateKey) JSONWebKeySet(org.gluu.oxauth.model.jwk.JSONWebKeySet) ArrayList(java.util.ArrayList) SignatureAlgorithm(org.gluu.oxauth.model.crypto.signature.SignatureAlgorithm) BlockEncryptionAlgorithm(org.gluu.oxauth.model.crypto.encryption.BlockEncryptionAlgorithm) JwtSigner(org.gluu.oxauth.model.token.JwtSigner) AppConfiguration(org.gluu.oxauth.model.configuration.AppConfiguration) Jwe(org.gluu.oxauth.model.jwe.Jwe) AbstractCryptoProvider(org.gluu.oxauth.model.crypto.AbstractCryptoProvider) Use(org.gluu.oxauth.model.jwk.Use) Jwt(org.gluu.oxauth.model.jwt.Jwt) SignatureAlgorithm(org.gluu.oxauth.model.crypto.signature.SignatureAlgorithm) KeyEncryptionAlgorithm(org.gluu.oxauth.model.crypto.encryption.KeyEncryptionAlgorithm) Algorithm(org.gluu.oxauth.model.jwk.Algorithm) BlockEncryptionAlgorithm(org.gluu.oxauth.model.crypto.encryption.BlockEncryptionAlgorithm) JSONException(org.json.JSONException) ParseException(java.text.ParseException) InvalidJwtException(org.gluu.oxauth.model.exception.InvalidJwtException) IOException(java.io.IOException) InvalidJweException(org.gluu.oxauth.model.exception.InvalidJweException) JSONWebKey(org.gluu.oxauth.model.jwk.JSONWebKey) JSONObject(org.json.JSONObject) Signature(java.security.Signature) KeyEncryptionAlgorithm(org.gluu.oxauth.model.crypto.encryption.KeyEncryptionAlgorithm) JweEncrypterImpl(org.gluu.oxauth.model.jwe.JweEncrypterImpl) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) Test(org.testng.annotations.Test)

Example 2 with AppConfiguration

use of org.gluu.oxauth.model.configuration.AppConfiguration in project oxAuth by GluuFederation.

the class ConfigurationTest method loadConfFromFile.

private static AppConfiguration loadConfFromFile(String p_filePath) throws JAXBException {
    final JAXBContext jc = JAXBContext.newInstance(AppConfiguration.class);
    final Unmarshaller u = jc.createUnmarshaller();
    return (AppConfiguration) u.unmarshal(new File(p_filePath));
}
Also used : AppConfiguration(org.gluu.oxauth.model.configuration.AppConfiguration) JAXBContext(javax.xml.bind.JAXBContext) Unmarshaller(javax.xml.bind.Unmarshaller) File(java.io.File)

Example 3 with AppConfiguration

use of org.gluu.oxauth.model.configuration.AppConfiguration in project oxTrust by GluuFederation.

the class ConfigureLogViewerAction method updateOxAuthConfiguration.

private void updateOxAuthConfiguration() {
    try {
        AppConfiguration appConfiguration = jsonConfigurationService.getOxauthAppConfiguration();
        appConfiguration.setExternalLoggerConfiguration(oxAuthLogConfigLocation);
        jsonConfigurationService.saveOxAuthAppConfiguration(appConfiguration);
    } catch (IOException e) {
        log.error("Failed to update oxauth-config.json", e);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update oxAuth configuration in LDAP");
    }
}
Also used : AppConfiguration(org.gluu.oxauth.model.configuration.AppConfiguration) IOException(java.io.IOException)

Example 4 with AppConfiguration

use of org.gluu.oxauth.model.configuration.AppConfiguration in project oxAuth by GluuFederation.

the class CorsFilter method init.

@Override
public void init(final FilterConfig filterConfig) throws ServletException {
    // Initialize defaults
    parseAndStore(DEFAULT_ALLOWED_ORIGINS, DEFAULT_ALLOWED_HTTP_METHODS, DEFAULT_ALLOWED_HTTP_HEADERS, DEFAULT_EXPOSED_HEADERS, DEFAULT_SUPPORTS_CREDENTIALS, DEFAULT_PREFLIGHT_MAXAGE, DEFAULT_DECORATE_REQUEST);
    AppConfiguration appConfiguration = configurationFactory.getAppConfiguration();
    if (filterConfig != null) {
        String filterName = filterConfig.getFilterName();
        CorsFilterConfig corsFilterConfig = new CorsFilterConfig(filterName, appConfiguration);
        String configEnabled = corsFilterConfig.getInitParameter(PARAM_CORS_ENABLED);
        String configAllowedOrigins = corsFilterConfig.getInitParameter(PARAM_CORS_ALLOWED_ORIGINS);
        String configAllowedHttpMethods = corsFilterConfig.getInitParameter(PARAM_CORS_ALLOWED_METHODS);
        String configAllowedHttpHeaders = corsFilterConfig.getInitParameter(PARAM_CORS_ALLOWED_HEADERS);
        String configExposedHeaders = corsFilterConfig.getInitParameter(PARAM_CORS_EXPOSED_HEADERS);
        String configSupportsCredentials = corsFilterConfig.getInitParameter(PARAM_CORS_SUPPORT_CREDENTIALS);
        String configPreflightMaxAge = corsFilterConfig.getInitParameter(PARAM_CORS_PREFLIGHT_MAXAGE);
        String configDecorateRequest = corsFilterConfig.getInitParameter(PARAM_CORS_REQUEST_DECORATE);
        if (configEnabled != null) {
            this.filterEnabled = Boolean.parseBoolean(configEnabled);
        }
        parseAndStore(configAllowedOrigins, configAllowedHttpMethods, configAllowedHttpHeaders, configExposedHeaders, configSupportsCredentials, configPreflightMaxAge, configDecorateRequest);
    }
}
Also used : AppConfiguration(org.gluu.oxauth.model.configuration.AppConfiguration)

Example 5 with AppConfiguration

use of org.gluu.oxauth.model.configuration.AppConfiguration in project oxAuth by GluuFederation.

the class ConfigurationFactory method reloadConfFromFile.

private boolean reloadConfFromFile() {
    final AppConfiguration configFromFile = loadConfFromFile();
    if (configFromFile != null) {
        log.info("Reloaded configuration from file: " + configFilePath);
        conf = configFromFile;
        return true;
    } else {
        log.error("Failed to load configuration from file: " + configFilePath);
    }
    return false;
}
Also used : AppConfiguration(org.gluu.oxauth.model.configuration.AppConfiguration)

Aggregations

AppConfiguration (org.gluu.oxauth.model.configuration.AppConfiguration)8 IOException (java.io.IOException)2 Function (com.google.common.base.Function)1 Strings (com.google.common.base.Strings)1 RSAKey (com.nimbusds.jose.jwk.RSAKey)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 PrivateKey (java.security.PrivateKey)1 Signature (java.security.Signature)1 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)1 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Date (java.util.Date)1 GregorianCalendar (java.util.GregorianCalendar)1 Inject (javax.inject.Inject)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Path (javax.ws.rs.Path)1 WebApplicationException (javax.ws.rs.WebApplicationException)1