[New] Added .getRealm(), .getEmail(), .getLocator() on Certificate, User, UserRep
This commit is contained in:
parent
33cfc9b9d7
commit
05a1b8ab22
|
@ -16,6 +16,7 @@
|
|||
package li.strolch.agent.impl;
|
||||
|
||||
import static li.strolch.model.Tags.AGENT;
|
||||
import static li.strolch.runtime.StrolchConstants.PROP_REALM;
|
||||
import static li.strolch.runtime.StrolchConstants.SYSTEM_USER_AGENT;
|
||||
import static li.strolch.utils.helper.StringHelper.formatNanoDuration;
|
||||
|
||||
|
@ -112,14 +113,14 @@ public class ComponentContainerImpl implements ComponentContainer {
|
|||
@Override
|
||||
public StrolchRealm getRealm(Certificate certificate) throws StrolchException {
|
||||
|
||||
String realmName = certificate.getProperty(StrolchConstants.PROP_REALM);
|
||||
String realmName = certificate.getRealm();
|
||||
if (StringHelper.isEmpty(realmName)) {
|
||||
if (getRealmNames().contains(StrolchConstants.DEFAULT_REALM)) {
|
||||
realmName = StrolchConstants.DEFAULT_REALM;
|
||||
} else {
|
||||
String msg = "The User {0} is missing the property {1} and the Realm {2} can not be used as it does not exist!";
|
||||
throw new StrolchException(MessageFormat
|
||||
.format(msg, certificate.getUsername(), StrolchConstants.PROP_REALM,
|
||||
.format(msg, certificate.getUsername(), PROP_REALM,
|
||||
StrolchConstants.DEFAULT_REALM));
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +130,7 @@ public class ComponentContainerImpl implements ComponentContainer {
|
|||
} catch (StrolchException e) {
|
||||
String msg = "The User {0} has property {1} with value={2}, but the Realm does not eixst, or is not accessible by this user!";
|
||||
throw new StrolchException(
|
||||
MessageFormat.format(msg, certificate.getUsername(), StrolchConstants.PROP_REALM, realmName), e);
|
||||
MessageFormat.format(msg, certificate.getUsername(), PROP_REALM, realmName), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import static li.strolch.utils.helper.StringHelper.DOT;
|
|||
import li.strolch.agent.api.ObserverHandler;
|
||||
import li.strolch.model.StrolchModelConstants;
|
||||
import li.strolch.persistence.api.PersistenceHandler;
|
||||
import li.strolch.privilege.base.PrivilegeConstants;
|
||||
import li.strolch.privilege.handler.PrivilegeHandler;
|
||||
|
||||
/**
|
||||
|
@ -35,7 +36,7 @@ public class StrolchConstants {
|
|||
public static final String PRIVILEGE_HANDLER = "PrivilegeHandler";
|
||||
public static final String SYSTEM_USER_AGENT = "agent";
|
||||
|
||||
public static final String PROP_REALM = "realm";
|
||||
public static final String PROP_REALM = PrivilegeConstants.REALM;
|
||||
public static final String DEFAULT_REALM = "defaultRealm";
|
||||
|
||||
public static final String DEFAULT_XML_VERSION = StrolchModelConstants.DEFAULT_XML_VERSION;
|
||||
|
|
|
@ -134,6 +134,7 @@ public class Tags {
|
|||
|
||||
// miscellaneous
|
||||
|
||||
public static final String MSG_TYPE = "msgType";
|
||||
public static final String USERNAME = "username";
|
||||
public static final String ELEMENTS = "elements";
|
||||
public static final String NR_OF_ELEMENTS = "nrOfElements";
|
||||
|
@ -142,6 +143,8 @@ public class Tags {
|
|||
public static final String REALMS = "realms";
|
||||
public static final String SIZE = "size";
|
||||
public static final String EXCEPTION = "exception";
|
||||
public static final String FORMAT = "format";
|
||||
public static final String FLAT = "flat";
|
||||
}
|
||||
|
||||
public static class Audit {
|
||||
|
|
|
@ -7,4 +7,8 @@ public class PrivilegeConstants {
|
|||
public static final int DEFAULT_KEY_LENGTH = 256;
|
||||
public static final int DEFAULT_SMALL_ITERATIONS = 10000;
|
||||
public static final int DEFAULT_ITERATIONS = 200000;
|
||||
|
||||
public static final String REALM = "realm";
|
||||
public static final String LOCATION = "location";
|
||||
public static final String EMAIL = "email";
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package li.strolch.privilege.handler;
|
||||
|
||||
import static li.strolch.privilege.base.PrivilegeConstants.EMAIL;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import li.strolch.privilege.model.internal.User;
|
||||
|
@ -8,8 +10,6 @@ import li.strolch.utils.helper.StringHelper;
|
|||
|
||||
public class MailUserChallengeHandler extends UserChallengeHandler {
|
||||
|
||||
private static final String EMAIL = "email";
|
||||
|
||||
@Override
|
||||
public void sendChallengeToUser(User user, String challenge) {
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class MailUserChallengeHandler extends UserChallengeHandler {
|
|||
sb.append(challenge);
|
||||
|
||||
String text = sb.toString();
|
||||
String recipient = user.getProperty(EMAIL);
|
||||
String recipient = user.getEmail();
|
||||
if (StringHelper.isEmpty(recipient)) {
|
||||
String msg = "User {0} has no property {1}";
|
||||
throw new RuntimeException(MessageFormat.format(msg, user.getUsername(), EMAIL));
|
||||
|
|
|
@ -15,9 +15,12 @@
|
|||
*/
|
||||
package li.strolch.privilege.model;
|
||||
|
||||
import static li.strolch.privilege.base.PrivilegeConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
import li.strolch.privilege.base.PrivilegeConstants;
|
||||
import li.strolch.privilege.base.PrivilegeException;
|
||||
import li.strolch.privilege.handler.PrivilegeHandler;
|
||||
import li.strolch.privilege.model.internal.User;
|
||||
|
@ -166,6 +169,33 @@ public final class Certificate implements Serializable {
|
|||
return this.propertyMap.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#REALM}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#REALM}
|
||||
*/
|
||||
public String getRealm() {
|
||||
return getProperty(REALM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#LOCATION}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#LOCATION}
|
||||
*/
|
||||
public String getLocation() {
|
||||
return getProperty(LOCATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#EMAIL}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#EMAIL}
|
||||
*/
|
||||
public String getEmail() {
|
||||
return getProperty(EMAIL);
|
||||
}
|
||||
|
||||
public Locale getLocale() {
|
||||
return this.locale;
|
||||
}
|
||||
|
|
|
@ -15,10 +15,13 @@
|
|||
*/
|
||||
package li.strolch.privilege.model;
|
||||
|
||||
import static li.strolch.privilege.base.PrivilegeConstants.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.*;
|
||||
|
||||
import li.strolch.privilege.base.PrivilegeConstants;
|
||||
import li.strolch.privilege.base.PrivilegeException;
|
||||
import li.strolch.privilege.model.internal.Role;
|
||||
import li.strolch.privilege.model.internal.User;
|
||||
|
@ -286,6 +289,33 @@ public class UserRep implements Serializable {
|
|||
return new HashMap<>(this.properties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#REALM}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#REALM}
|
||||
*/
|
||||
public String getRealm() {
|
||||
return getProperty(REALM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#LOCATION}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#LOCATION}
|
||||
*/
|
||||
public String getLocation() {
|
||||
return getProperty(LOCATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#EMAIL}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#EMAIL}
|
||||
*/
|
||||
public String getEmail() {
|
||||
return getProperty(EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a string representation of this object displaying its concrete type and its values
|
||||
*
|
||||
|
|
|
@ -15,8 +15,11 @@
|
|||
*/
|
||||
package li.strolch.privilege.model.internal;
|
||||
|
||||
import static li.strolch.privilege.base.PrivilegeConstants.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import li.strolch.privilege.base.PrivilegeConstants;
|
||||
import li.strolch.privilege.base.PrivilegeException;
|
||||
import li.strolch.privilege.model.UserRep;
|
||||
import li.strolch.privilege.model.UserState;
|
||||
|
@ -279,6 +282,33 @@ public final class User {
|
|||
return this.propertyMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#REALM}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#REALM}
|
||||
*/
|
||||
public String getRealm() {
|
||||
return getProperty(REALM);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#LOCATION}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#LOCATION}
|
||||
*/
|
||||
public String getLocation() {
|
||||
return getProperty(LOCATION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property {@link PrivilegeConstants#EMAIL}
|
||||
*
|
||||
* @return the value of the property {@link PrivilegeConstants#EMAIL}
|
||||
*/
|
||||
public String getEmail() {
|
||||
return getProperty(EMAIL);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a {@link UserRep} which is a representation of this object used to serialize and view on clients
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue