forked from devonfw-forge/keywi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
devonfw-forge#28: various improvements on authorization
- Loading branch information
Showing
15 changed files
with
363 additions
and
56 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
core/src/main/java/com/devonfw/keywi/general/common/api/NlsBundleApplicationRoot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.devonfw.keywi.general.common.api; | ||
|
||
import javax.inject.Named; | ||
|
||
import net.sf.mmm.util.nls.api.NlsBundle; | ||
import net.sf.mmm.util.nls.api.NlsBundleMessage; | ||
import net.sf.mmm.util.nls.api.NlsMessage; | ||
|
||
/** | ||
* This is the {@link NlsBundle} for this application. | ||
*/ | ||
public interface NlsBundleApplicationRoot extends NlsBundle { | ||
|
||
/** | ||
* @return error message if the user tried to modify the business key. | ||
* @see com.devonfw.keywi.keymanagement.common.api.KeyObject#getKey() | ||
* | ||
* @param entity the {@link String} describing the entity that could not be modified. | ||
* @param key the new business key the user tried to change to. | ||
*/ | ||
@NlsBundleMessage("You can not change the business key of entity {entity} to {key}! If you really need to change the business key, create a new entity and delete the old one.") | ||
NlsMessage errorKeyImmutable(@Named("entity") String entity, @Named("key") String key); | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
...ain/java/com/devonfw/keywi/general/common/api/exception/ApplicationBusinessException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.devonfw.keywi.general.common.api.exception; | ||
|
||
import net.sf.mmm.util.exception.api.NlsRuntimeException; | ||
import net.sf.mmm.util.nls.api.NlsMessage; | ||
|
||
import com.devonfw.keywi.general.common.api.NlsBundleApplicationRoot; | ||
|
||
/** | ||
* Abstract base class for business exceptions of this application. | ||
*/ | ||
public abstract class ApplicationBusinessException extends NlsRuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param cause is the {@link #getCause() cause} of this exception. May be {@code null}. | ||
* @param message the {@link #getNlsMessage() message} describing the problem briefly. | ||
* @see #createBundle() | ||
*/ | ||
public ApplicationBusinessException(Throwable cause, NlsMessage message) { | ||
|
||
super(cause, message); | ||
} | ||
|
||
/** | ||
* @return the {@link NlsBundleApplicationRoot} to create the actual {@link NlsMessage}. | ||
*/ | ||
protected static NlsBundleApplicationRoot createBundle() { | ||
|
||
return createBundle(NlsBundleApplicationRoot.class); | ||
} | ||
|
||
@Override | ||
public boolean isForUser() { | ||
|
||
return true; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...n/java/com/devonfw/keywi/keymanagement/common/api/exception/KeyModificationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.devonfw.keywi.keymanagement.common.api.exception; | ||
|
||
import com.devonfw.keywi.general.common.api.exception.ApplicationBusinessException; | ||
import com.devonfw.keywi.keymanagement.common.api.KeyObject; | ||
|
||
/** | ||
* Thrown if the user tried to modify the business key of an existing entity. | ||
*/ | ||
public class KeyModificationException extends ApplicationBusinessException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param entity the {@link String} describing the entity that could not be modified. Should at least contain the | ||
* original business key. | ||
* @param key the new business key the user tried to save. | ||
*/ | ||
public KeyModificationException(KeyObject entity, String key) { | ||
|
||
this(entity, key, null); | ||
} | ||
|
||
/** | ||
* The constructor. | ||
* | ||
* @param entity the {@link String} describing the entity that could not be modified. Should at least contain the | ||
* original business key. | ||
* @param key the new business key the user tried to save. | ||
* @param cause is the {@link #getCause() cause} of this exception. May be {@code null}. | ||
*/ | ||
public KeyModificationException(KeyObject entity, String key, Throwable cause) { | ||
|
||
super(cause, createBundle().errorKeyImmutable(toString(entity), key)); | ||
} | ||
|
||
private static String toString(KeyObject entity) { | ||
|
||
StringBuilder sb = new StringBuilder(entity.getClass().getSimpleName()); | ||
sb.append("[id="); | ||
sb.append(entity.getId()); | ||
sb.append(",key="); | ||
sb.append(entity.getKey()); | ||
sb.append(']'); | ||
return sb.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...src/main/java/com/devonfw/keywi/keymanagement/logic/base/usecase/AbstractKeyObjectUc.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.devonfw.keywi.keymanagement.logic.base.usecase; | ||
|
||
import java.util.Objects; | ||
|
||
import com.devonfw.keywi.general.logic.base.AbstractUc; | ||
import com.devonfw.keywi.keymanagement.common.api.KeyObject; | ||
import com.devonfw.keywi.keymanagement.common.api.exception.KeyModificationException; | ||
import com.devonfw.keywi.keymanagement.dataaccess.api.KeyObjectEntity; | ||
import com.devonfw.keywi.keymanagement.logic.api.to.KeyObjectEto; | ||
|
||
/** | ||
* Abstract use case for {@link KeyObject}s. | ||
*/ | ||
public class AbstractKeyObjectUc extends AbstractUc { | ||
|
||
/** | ||
* Verifies that the {@link com.devonfw.keywi.keymanagement.common.api.KeyObject#getKey() business key} of both given | ||
* {@link com.devonfw.keywi.keymanagement.common.api.KeyObject}s are equal. | ||
* | ||
* @param keyObjectToSave the {@link KeyObjectEto} to save. | ||
* @param keyObjectFromDb the {@link KeyObjectEntity} loaded from the Database that should be modified. | ||
*/ | ||
protected void verifyKeyNotModified(KeyObjectEto keyObjectToSave, KeyObjectEntity keyObjectFromDb) { | ||
|
||
String keyToSave = keyObjectToSave.getKey(); | ||
if (!Objects.equals(keyToSave, keyObjectFromDb.getKey())) { | ||
throw new KeyModificationException(keyObjectFromDb, keyToSave); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.