Skip to content

Commit

Permalink
AccessPermisions
Browse files Browse the repository at this point in the history
This class helps to make some AccessPermissions into Frameworks. To make D2W more powerful.
  • Loading branch information
ishimoto authored and Pascal Robert committed Jul 23, 2012
1 parent 5336768 commit c1d9b3d
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package er.extensions.security;

import org.apache.log4j.Logger;

/**
* AccessPermission
*
* This class makes it easy to create AccessPermission into Frameworks.
*
* The User can implement IERXAccessPermissionInterface and Delegate
* and then do what he like.
*
* @author ishimoto
*
*/
public class ERXAccessPermission implements IERXAccessPermissionInterface {

private static final Logger log = Logger.getLogger(ERXAccessPermission.class);

//********************************************************************
// Singleton
//********************************************************************

public static ERXAccessPermission instance() {
return instance;
}
private static final ERXAccessPermission instance = new ERXAccessPermission();

private ERXAccessPermission() {}

//********************************************************************
// Delegate
//********************************************************************

public void setDelegate(IERXAccessPermissionInterface delegate) {
this.delegate = delegate;
}
public IERXAccessPermissionInterface delegate() {
return delegate;
}
private IERXAccessPermissionInterface delegate = null;

//********************************************************************
// AccessPermission
//********************************************************************

public boolean can(String key) {
return canWithDefault(key, false);
}


public boolean canWithDefault(String key, boolean defaultValue) {
if(delegate() != null) {
return delegate().canWithDefault(key, defaultValue);
}

log.warn("No Delegate is set. Result for '" + key + "' is false.");
return false;
}

public boolean isDeveloper() {
if(delegate() != null) {
return delegate().isDeveloper();
}

log.warn("No Delegate is set. Result for 'isDeveloper' is false.");
return false;
}

public boolean isAdministrator() {
if(delegate() != null) {
return delegate().isAdministrator();
}

log.warn("No Delegate is set. Result for 'isAdministrator' is false.");
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package er.extensions.security;

/**
* <span class="ja">
* このクラスはアクセス権限に使用します
* </span>
*
* @author ishimoto
*
*/
public interface IERXAccessPermissionInterface {

public boolean can(String key);

public boolean canWithDefault(String key, boolean defaultValue);

public boolean isDeveloper();

public boolean isAdministrator();

}

0 comments on commit c1d9b3d

Please sign in to comment.