La création d'un customRealm permet la saisie de credentials au travers de votre propre API.
Exemple : Création d'un customRealm à partir d'informations passées dans l'URL.
L'utilisateur souhaite lancer l'application au travers d'une URL de type http://host/mywebapp/index.jsp?login=myuser&password=mypassword.
Exemple d'encapsulation de la servlet principale index.jsp :
<%@taglib prefix="t" tagdir="/WEB-INF/tags" %> <%@ taglib prefix="adelwagon" uri="http://adelwagon.adelia.hardis.com/adelwagon" %> <adelwagon:pushCustomVariable key="login"><%=request.getParameter("login")%></adelwagon:pushCustomVariable> <adelwagon:pushCustomVariable key="password" cipher="true"><%=request.getParameter("password")%></adelwagon:pushCustomVariable> <t:adeliaDesktop title="Adelia Desktop" desktopName="default" frameOptions="SAMEORIGIN"> <jsp:attribute name="head_header"> <adelwagon:customSessionVariables/> <link href="logo/logo.css" rel="stylesheet" type="text/css"/> </jsp:attribute> <jsp:attribute name="head_footer"> </jsp:attribute><jsp:attribute name="body_header"> </jsp:attribute><jsp:attribute name="body_footer"> </jsp:attribute> </t:adeliaDesktop>
|
Exemple : MyCustomRealm
La récupération des couples <cle,valeur> s'effectue avec l'API. Lorsque l'attribut est de type <key,value>, la récupération de la valeur value s'effectue en préfixant la clé key par custom :
String this.getSessionContext().getMainContainerConfiguration().getAttributes().get("custom.key")
La récupération d'une valeur chiffrée, s'effectue avec l'API :
String WagonCipher.getInstance().decode(String); Une valeur chiffrée est du type {RSA}....
Si la valeur n'est pas préfixée par {RSA} l'API renvoie la valeur passée
WagonCipher.getInstance().decode((String) this.getSessionContext().getMainContainerConfiguration().getAttributes().get("custom.login"));
package mypackage.realms; import java.util.HashMap; import java.util.Map; import com.hardis.adelia.cloud.security.ICommonRealmInformations; import com.hardis.adelia.cloud.security.ICommonRealmInformations.InputMsgType; import com.hardis.wagon.runtime.Application; import com.hardis.wagon.runtime.communication.InputMessage.MSGType; import com.hardis.wagon.runtime.security.AbstractSecurityRealm; import com.hardis.wagon.runtime.security.SecurityResponse; import com.hardis.wagon.runtime.security.WagonCipher; public class MyCustomRealm extends AbstractSecurityRealm { String requestLogin; String requestPassword; private boolean firstAttempt; public RequestRealm() { } @Override public final void init(Application application, String realName, Map<String, String> parameters) { super.init(application, realName, parameters); /* */ requestLogin = (String) this.getSessionContext().getMainContainerConfiguration().getAttributes().get("custom.login"); /* we can always encapsulate with WagonCipher.getInstance().decode() as the API support null value and recognize non ciphered data */ * requestLogin = WagonCipher.getInstance().decode((String) this.getSessionContext().getMainContainerConfiguration().getAttributes().get("custom.login")); */ requestPassword = WagonCipher.getInstance().decode((String) this.getSessionContext().getMainContainerConfiguration().getAttributes().get("custom.password")); /* in case of requestRealm, only one attempt is done. In case of invalid credentials, user will be redirect to the logout page */ this.firstAttempt = true; } @Override protected SecurityResponse sendAuthRequest(Map<String, String> realmEntries) { if (this.firstAttempt) { /* in case of requestRealm, only one attempt is done. In case of invalid credentials, user will be redirect to the logout page */ this.firstAttempt = false; Map<String, String> data = new HashMap<String, String>(); data.put(ICommonRealmInformations.LOGIN, requestLogin); data.put(ICommonRealmInformations.PASSWORD, requestPassword); data.put(ICommonRealmInformations.ACTION, InputMsgType.AUTHENTICATION.toString()); return new SecurityResponse(MSGType.AUTH_RESPONSE, data); } else { return new SecurityResponse(MSGType.AUTH_ABORT, null); } } }
|