All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.greenpepper.server.license.SecurityContext Maven / Gradle / Ivy

There is a newer version: 4.2.0
Show newest version
package com.greenpepper.server.license;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import com.greenpepper.server.domain.Repository;

/**
 * 

SecurityContext class.

* * @author oaouattara * @version $Id: $Id */ public class SecurityContext { private final static TimeSource DEFAULT_TIME_SOURCE = new TimeSource() { public Date now() { return new Date(); } }; private Set grantedApplications = new HashSet(); private TimeSource timeSource; /** *

isMaxReached.

* * @param repository a {@link com.greenpepper.server.domain.Repository} object. * @param licenseMaxUsers a int. * @return a boolean. */ public boolean isMaxReached(Repository repository, int licenseMaxUsers) { Set clonedApp = new HashSet(grantedApplications); int counter = 0; clonedApp.remove(repository); for (Repository repo : clonedApp) { if (repo.getType().equals(repository.getType()) && !repo.getBaseUrl().equals(repository.getBaseUrl())) { counter += repo.getMaxUsers(); } } return repository.getMaxUsers() + counter > licenseMaxUsers; } /** *

grantAccess.

* * @param repository a {@link com.greenpepper.server.domain.Repository} object. */ public void grantAccess(Repository repository) { grantedApplications.add(repository); } /** *

denyAccess.

* * @param repository a {@link com.greenpepper.server.domain.Repository} object. */ public void denyAccess(Repository repository) { grantedApplications.remove(repository); } /** *

Constructor for SecurityContext.

*/ public SecurityContext() { this(DEFAULT_TIME_SOURCE); } /** *

Constructor for SecurityContext.

* * @param timeSource a {@link com.greenpepper.server.license.TimeSource} object. */ public SecurityContext(TimeSource timeSource) { this.timeSource = timeSource; } /** *

now.

* * @return a {@link java.util.Date} object. */ public Date now() { return timeSource.now(); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy