Shibboleth Credentials

krrishv krish.v at gmail.com
Wed Jan 29 20:59:58 EST 2014


Hi,

I am trying to take the shibboleth credentials and post it to an other App.
I got the usernamePasswordLoginServlet sourcecode and changed something like
below after authenticated user.

 protected boolean authenticateUser(HttpServletRequest request) {

        try {
            String username =
DatatypeHelper.safeTrimOrNullString(request.getParameter(usernameAttribute));
            String password =
DatatypeHelper.safeTrimOrNullString(request.getParameter(passwordAttribute));

            SimpleCallbackHandler cbh = new SimpleCallbackHandler(username,
password);

            javax.security.auth.login.LoginContext jaasLoginCtx = new
javax.security.auth.login.LoginContext(
                    jaasConfigName, cbh);

            jaasLoginCtx.login();
            log.debug("Successfully authenticated user {}", username);

            Subject subject = jaasLoginCtx.getSubject();
            Set<Principal> principals = subject.getPrincipals();

            if (principals.isEmpty()) {
                request.setAttribute(LoginHandler.PRINCIPAL_NAME_KEY,
username);
            } else {
                Principal principal = principals.iterator().next();
                String principalName =
DatatypeHelper.safeTrimOrNullString(principal.getName());
                if (principalName == null) {
                    request.setAttribute(LoginHandler.PRINCIPAL_NAME_KEY,
username);
                } else {
                    request.setAttribute(LoginHandler.PRINCIPAL_NAME_KEY,
principal.getName());
                }
                request.setAttribute(LoginHandler.SUBJECT_KEY,
jaasLoginCtx.getSubject());
            }

// For custom API put.

        CloseableHttpClient httpClient = null;
        HttpPut httpPut = null;
        CloseableHttpResponse response = null;
	//	StringEntity okturl = new StringEntity("htts://test.preview.com");
	//	StringEntity apikey = new StringEntity("apikey");
	//	StringEntity appplicationid = new StringEntity("aphid");

        try {

            		StringEntity okturl = new
StringEntity("htts://test.preview.com");
		StringEntity apikey = new StringEntity("apikey");
		StringEntity appplicationid = new StringEntity("aphid");
            httpClient = HttpClients.createDefault();
          //  httpPost = new
HttpPost("https://api.kii.com/api/oauth2/token");
            httpPut  = new
HttpPut("https://test.preview.com/api/v1/apps/0oa1bpy80zKNYPTUZVRU/users/00u1bpy99uKWDOPOTUXC");

            List<NameValuePair> nvps = new ArrayList<NameValuePair>();
            nvps.add(new BasicNameValuePair("content-type",
"application/json"));
          //  nvps.add(new BasicNameValuePair("x-kii-appid", "xxxxx"));
            nvps.add(new BasicNameValuePair("Authorization", "SSWS
00GsQzLUU39CCZ1RFG-qD8JftbvPawtb6rBCocJ"));

          //   StringEntity input = new StringEntity("{\"userName\":
\"test1\",\"password\": \"value\": \"test*1234\"}");
         StringEntity input = new StringEntity( 
         "{"
              
  + " \"id\": \"00u1bpy99uKWDOPOTUXC\","
   + "\"scope\": \"USER\","
   + "\"credentials\": {"
    +    "\"userName\": \"test1\","
     +   "\"password\": { \"value\": \"updatedP at 55word\" }"
    +"}"
+"}"
                 
         
         );
            input.setContentType("application/json");
             httpPut.setEntity(input);

            for (NameValuePair h : nvps)
            {
                httpPut.addHeader(h.getName(), h.getValue());
            }

            response = httpClient.execute(httpPut);

            if (response.getStatusLine().getStatusCode() != 200) {
                throw new RuntimeException("Failed : HTTP error code : "
                        + response.getStatusLine().getStatusCode());
            }

            BufferedReader br = new BufferedReader(new InputStreamReader(
                    (response.getEntity().getContent())));

            String output;
            System.out.println("Output from Server .... \n");
            while ((output = br.readLine()) != null) {
                System.out.println(output);
            }
        } catch (MalformedURLException e) {

            e.printStackTrace();

        } catch (IOException e) {

            e.printStackTrace();

        } finally {
            try{
                response.close();
                httpClient.close();
            }catch(Exception ex) {
                ex.printStackTrace();
            }
        }

//END test API

            return true;
        } catch (LoginException e) {
            log.debug("User authentication failed", e);
            return false;
        }
    }

Now i repackaged the shibbolethidentityprovider.jar and deployed it. After
that when i try do a IDP initiated login something like below.

https://win-citrix.krish.com/idp/profile/SAML2/Unsolicited/SSO?providerId=https://www.krish.com/saml2/service-provider/sp12ki4awZBWDTLSYVUL


I get the below error any idea.

ERROR

An error occurred while processing your request. Please contact your
helpdesk or user ID office for assistance.

Error Message: Invalid IdP URL (HTTP 404) 




--
View this message in context: http://shibboleth.1660669.n2.nabble.com/Shibboleth-Credentials-tp7594432.html
Sent from the Shibboleth - Users mailing list archive at Nabble.com.


More information about the users mailing list