summaryrefslogtreecommitdiffstats
path: root/java/coldfusion/src/CFLassoSingleSignOn.java
blob: cfcff1272be62e6c820bb8e8a58c19a7700c3eae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*
 * ColdFusionLasso -- ColdFusion bindings for Lasso library
 *
 * Copyright (C) 2004 Entr'ouvert
 * http://lasso.entrouvert.org
 *
 * Authors: Emmanuel Raviart <eraviart@entrouvert.com>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


/*
 * Simple wrapper for JLasso, to ease its use by ColdFusion applications.
 *
 * To compile it:
 * $ javac -classpath ../../lasso.jar *.java
 *
 * To test it:
 * $ export LD_LIBRARY_PATH=../../.libs/
 * $ java -classpath ../../lasso.jar:. CFLassoLogin
 *
 * To use it:
 * $ jar cf CFLasso.jar *.class
 * edit ColdFusion file bin/jvm.config:
 *   - Add libjlasso.so directory to java.library.path variable.
 *   - Add lasso.jar & CFLasso.jar to java.class.path variable.
 */

import com.entrouvert.lasso.AuthnRequest;
import com.entrouvert.lasso.Identity;
import com.entrouvert.lasso.lassoConstants;
import com.entrouvert.lasso.lasso;
import com.entrouvert.lasso.Login;
import com.entrouvert.lasso.Server;
import com.entrouvert.lasso.Session;


public class CFLassoSingleSignOn {
    /* A simple service provider single sign-on */

    protected Login login = null;
    protected Server server = null;

    public String idpProviderId = null;

    public void acceptSso() {
	login.acceptSso();
    }

    public void buildAuthnRequestMsg() {
        login.buildAuthnRequestMsg(idpProviderId);
    }

    public void buildRequestMsg() {
	login.buildRequestMsg();
    }

    public void configure(String metadataPath, String publicKeyPath, String privateKeyPath,
			  String idpProviderId, String idpMetadataPath, String idpPublicKeyPath) {
        server = new Server(metadataPath, publicKeyPath, privateKeyPath, null,
			    lassoConstants.signatureMethodRsaSha1);
	this.idpProviderId = idpProviderId;
        server.addProvider(idpMetadataPath, idpPublicKeyPath, null);
        login = new Login(server);
    }

    public String getIdentityDump() {
	Identity identity = login.getIdentity();
	if (identity != null)
	    return identity.dump();
	else
	    return null;
    }

    public String getMsgBody() {
	return login.getMsgBody();
    }

    public String getMsgRelayState() {
	return login.getMsgRelayState();
    }

    public String getMsgUrl() {
	return login.getMsgUrl();
    }

    public String getNameIdentifier() {
	return login.getNameIdentifier();
    }

    public String getSessionDump() {
	Session session = login.getSession();
	if (session != null)
	    return session.dump();
	else
	    return null;
    }

    public void initAuthnRequest(String relayState) {
	AuthnRequest authnRequest;
	String authnRequestUrl;

        login.initAuthnRequest(lassoConstants.httpMethodRedirect);
	authnRequest = login.getAuthnRequest();
        authnRequest.setIsPassive(false);
        authnRequest.setNameIdPolicy(lassoConstants.libNameIdPolicyTypeFederated);
        authnRequest.setConsent(lassoConstants.libConsentObtained);
	if (relayState != null)
	    authnRequest.setRelayState(relayState);
    }

    public void initRequest(String queryString) {
	login.initRequest(queryString, lassoConstants.httpMethodRedirect);
    }

    static public void main(String [] args) {
	CFLassoSingleSignOn lasso = new CFLassoSingleSignOn();
	lasso.configure("../../../tests/data/sp2-la/metadata.xml",
			"../../../tests/data/sp2-la/public-key.pem",
			"../../../tests/data/sp2-la/private-key-raw.pem",
			"https://idp2/metadata",
			"../../../tests/data/idp2-la/metadata.xml",
			"../../../tests/data/idp2-la/public-key.pem");
	lasso.initAuthnRequest("data-to-get-back");
	lasso.buildAuthnRequestMsg();
	String ssoUrl = lasso.getMsgUrl();
	System.out.println("Test");
	System.out.print("Identity provider single sign-on URL = ");
	System.out.println(ssoUrl);
    }

    public void processResponseMsg(String responseMsg) {
	login.processResponseMsg(responseMsg);
    }

    public void setIdentityFromDump(String identityDump) {
	login.setIdentityFromDump(identityDump);
    }

    public void setSessionFromDump(String sessionDump) {
	login.setSessionFromDump(sessionDump);
    }
}