Created
April 6, 2020 18:43
-
-
Save trepidity/f954b240713501710c7de2f6cd055de9 to your computer and use it in GitHub Desktop.
JSONAuthentication
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
package com.novacoast.nam.authentication; | |
import com.novell.nidp.NIDPConstants; | |
import com.novell.nidp.NIDPContext; | |
import com.novell.nidp.authentication.AuthnConstants; | |
import com.novell.nidp.authentication.local.LocalAuthenticationClass; | |
import com.novell.nidp.common.authority.PasswordExpiredException; | |
import com.novell.nidp.common.authority.PasswordExpiringException; | |
import com.novell.nidp.common.authority.UserAuthority; | |
import com.novell.nidp.logging.NIDPLog; | |
import org.json.JSONObject; | |
import java.io.IOException; | |
import java.io.PrintWriter; | |
import java.util.ArrayList; | |
import java.util.Properties; | |
public class JSONAuthentication extends LocalAuthenticationClass | |
{ | |
public JSONAuthentication(Properties properties, ArrayList<UserAuthority> arrayList) | |
{ | |
super(properties, arrayList); | |
this.m_NIDPContext = NIDPContext.getNIDPContext(); | |
} | |
@Override | |
public String getType() | |
{ | |
return AuthnConstants.PROTECTED_PASSWORD; | |
} | |
@Override | |
public int authenticate() | |
{ | |
int result = NOT_AUTHENTICATED; | |
final JSONObject jsonObject = new JSONObject(); | |
try { | |
final String id = m_Request.getParameter(NIDPConstants.PARM_USERID); | |
result = handlePost(id); | |
if(AUTHENTICATED == result) { | |
NIDPLog.logAppInfo(String.format("Successfully authenticated %s", id)); | |
jsonObject.put("Data", "null"); | |
jsonObject.put("HasError", "false"); | |
jsonObject.put("ErrorCode", "200"); | |
jsonObject.put("Message", "Authenticated"); | |
this.m_Response.setContentType("application/json"); | |
this.m_Response.setCharacterEncoding("UTF-8"); | |
this.m_Response.setStatus(401); | |
PrintWriter out = this.m_Response.getWriter(); | |
out.print(jsonObject.toString()); | |
out.flush(); | |
// this.m_Request.setAttribute("isAuthenticated", "true"); | |
// showJSP("json_response"); | |
} else { | |
jsonObject.put("Data", "null"); | |
jsonObject.put("HasError", "true"); | |
jsonObject.put("ErrorCode", "401"); | |
jsonObject.put("Message",getUserErrorMsg()); | |
this.m_Response.setContentType("application/json"); | |
this.m_Response.setCharacterEncoding("UTF-8"); | |
this.m_Response.setStatus(401); | |
PrintWriter out = this.m_Response.getWriter(); | |
out.print(jsonObject.toString()); | |
out.flush(); | |
} | |
} catch (PasswordExpiringException | PasswordExpiredException | IOException ignored) { | |
} | |
return result; | |
} | |
private int handlePost(final String id) throws PasswordExpiringException, PasswordExpiredException | |
{ | |
final String password = m_Request.getParameter(NIDPConstants.PARM_PASSWORD); | |
if (authenticateWithPassword(id, password)) { | |
return AUTHENTICATED; | |
} | |
return NOT_AUTHENTICATED; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment