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); } } } |