Search in sources :

Example 6 with GluuConfiguration

use of org.gluu.oxtrust.model.GluuConfiguration in project oxTrust by GluuFederation.

the class ConfigurationStatusTest method testIsConfigurationStatus3.

@Test(dependsOnMethods = { "testIsConfigurationStatus2" })
@Parameters({ "test.login.user.admin.uid" })
public void testIsConfigurationStatus3(String userUid) {
    loginUuser(userUid);
    GluuConfiguration configuration = configurationService.getConfiguration();
    long currentTime = System.currentTimeMillis() - 101 * 1000;
    Date currentDateTime = new Date(currentTime);
    configuration.setLastUpdate(currentDateTime);
    configurationService.updateConfiguration(configuration);
    assertEquals(configurationStatusAction.checkHealth(), OxTrustConstants.RESULT_SUCCESS);
    assertEquals(configurationStatusAction.getHealth(), "FAIL");
}
Also used : GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) Date(java.util.Date) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 7 with GluuConfiguration

use of org.gluu.oxtrust.model.GluuConfiguration in project oxTrust by GluuFederation.

the class ConfigurationStatusTest method testIsConfigurationStatus1.

@Test
@Parameters({ "test.login.user.admin.uid" })
public void testIsConfigurationStatus1(String userUid) {
    loginUuser(userUid);
    GluuConfiguration configuration = configurationService.getConfiguration();
    Date currentDateTime = new Date();
    configuration.setLastUpdate(currentDateTime);
    configurationService.updateConfiguration(configuration);
    assertEquals(configurationStatusAction.checkHealth(), OxTrustConstants.RESULT_SUCCESS);
    assertEquals(configurationStatusAction.getHealth(), "OK");
}
Also used : GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) Date(java.util.Date) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 8 with GluuConfiguration

use of org.gluu.oxtrust.model.GluuConfiguration in project oxTrust by GluuFederation.

the class ConfigurationStatusTest method testIsConfigurationStatus2.

@Test(dependsOnMethods = { "testIsConfigurationStatus1" })
@Parameters({ "test.login.user.admin.uid" })
public void testIsConfigurationStatus2(String userUid) {
    loginUuser(userUid);
    GluuConfiguration configuration = configurationService.getConfiguration();
    long currentTime = System.currentTimeMillis() - 50 * 1000;
    Date currentDateTime = new Date(currentTime);
    configuration.setLastUpdate(currentDateTime);
    configurationService.updateConfiguration(configuration);
    assertEquals(configurationStatusAction.checkHealth(), OxTrustConstants.RESULT_SUCCESS);
    assertEquals(configurationStatusAction.getHealth(), "OK");
}
Also used : GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) Date(java.util.Date) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 9 with GluuConfiguration

use of org.gluu.oxtrust.model.GluuConfiguration in project oxTrust by GluuFederation.

the class LogDir method processInt.

/**
 * Gather periodically site and server status
 */
private void processInt() {
    GluuConfiguration configuration = configurationService.getConfiguration();
    long maxSize = configuration.getMaxLogSize();
    ;
    log.debug("Max Log Size: " + maxSize);
    if (maxSize > 0) {
        log.debug("Max Log Size: " + maxSize);
        long maxSizeInByte = maxSize * 1024 * 1024;
        long currentSize = 0;
        Date today = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String todayStr = sdf.format(today);
        log.debug("Getting the tomcat home directory");
        String filePath = ConfigurationFactory.DIR + ConfigurationFactory.LOG_ROTATION_CONFIGURATION;
        log.debug("FilePath: " + filePath);
        List<LogDir> logDirs = readConfig(filePath);
        List<FileData> fDataList = new ArrayList<FileData>();
        for (LogDir logDir : logDirs) {
            File file = new File(logDir.getLocation());
            File[] files = file.listFiles();
            long totalSize = 0;
            if (files != null && files.length > 0) {
                for (File singleFile : files) {
                    if (singleFile.getName().startsWith(logDir.getPrefix()) && singleFile.getName().endsWith(logDir.getExtension())) {
                        totalSize += singleFile.length();
                        FileData fData = new FileData(singleFile.getName(), logDir.getLocation(), singleFile.lastModified(), singleFile.length());
                        fDataList.add(fData);
                    }
                }
            }
            currentSize += totalSize;
            logDir.setLength(totalSize);
        }
        Collections.sort(fDataList);
        if (currentSize > maxSizeInByte) {
            // empty 15% space
            maxSizeInByte -= (maxSizeInByte * 15) / 100;
        // less of the
        // maximum
        // allocated
        }
        for (FileData fileData : fDataList) {
            if (currentSize < maxSizeInByte) {
                break;
            }
            Date date = new Date(fileData.getLastModified());
            String dateStr = sdf.format(date);
            if (todayStr.equals(dateStr)) {
                log.debug("--Skipped Active File: " + fileData.getName() + " Date: " + sdf.format(date) + " Size: " + fileData.getSize());
                continue;
            }
            File singleFile = new File(fileData.getFilePath() + "/" + fileData.getName());
            if (!singleFile.delete()) {
                log.error("Failed to delete the file.");
            } else {
                currentSize -= fileData.getSize();
                log.debug("--Deleted File Name: " + fileData.getName() + " Date: " + sdf.format(date) + " Size: " + fileData.getSize());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) FileData(org.gluu.oxtrust.model.FileData) File(java.io.File) Date(java.util.Date)

Example 10 with GluuConfiguration

use of org.gluu.oxtrust.model.GluuConfiguration in project oxTrust by GluuFederation.

the class PermissionService method hasPermission.

public boolean hasPermission(Object target, String action) {
    log.trace("Checking permissions for target '{}' an 'action'. Identity: {}", target, action, identity);
    if (!identity.isLoggedIn()) {
        return false;
    }
    if (identity.hasRole(UserRole.MANAGER.getValue()) || identity.hasRole(UserRole.USER.getValue())) {
        if (StringHelper.equalsIgnoreCase("profile_management", action)) {
            GluuConfiguration configuration = configurationService.getConfiguration();
            GluuConfiguration targetConfiguration = (GluuConfiguration) target;
            if (configuration.isProfileManagment() && StringHelper.equals(configurationService.getConfiguration().getInum(), targetConfiguration.getInum())) {
                return true;
            } else {
                return false;
            }
        }
    }
    if (identity.hasRole(UserRole.MANAGER.getValue())) {
        for (String[] managerAction : managerActions) {
            String targetString = (String) target;
            if (StringHelper.equals(managerAction[0], targetString) && StringHelper.equals(managerAction[1], action)) {
                return true;
            }
        }
    }
    if (identity.hasRole(UserRole.USER.getValue())) {
        for (String[] managerAction : managerActions) {
            String targetString = (String) target;
            if (StringHelper.equals("profile", targetString) && StringHelper.equals(managerAction[0], targetString) && StringHelper.equals(managerAction[1], action)) {
                return true;
            }
        }
    }
    return false;
}
Also used : GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration)

Aggregations

GluuConfiguration (org.gluu.oxtrust.model.GluuConfiguration)32 Date (java.util.Date)8 IOException (java.io.IOException)6 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)6 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)5 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)5 TrustStoreCertificate (org.gluu.oxtrust.model.cert.TrustStoreCertificate)4 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 AppConfiguration (org.gluu.config.oxtrust.AppConfiguration)2 SmtpConfiguration (org.gluu.model.SmtpConfiguration)2 GluuOxTrustStat (org.gluu.oxtrust.model.GluuOxTrustStat)2 TrustStoreConfiguration (org.gluu.oxtrust.model.cert.TrustStoreConfiguration)2 X509CertificateShortInfo (org.gluu.oxtrust.util.X509CertificateShortInfo)2 File (java.io.File)1