Applied code cleanup
parent
3e23967b46
commit
15aea61fbe
|
@ -28,177 +28,177 @@ import com.google.gson.JsonParser;
|
|||
public class IntrospectingTokenService implements ResourceServerTokenServices {
|
||||
|
||||
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String introspectionUrl;
|
||||
private String clientId;
|
||||
private String clientSecret;
|
||||
private String introspectionUrl;
|
||||
|
||||
// Inner class to store in the hash map
|
||||
private class TokenCacheObject { OAuth2AccessToken token; OAuth2Authentication auth;
|
||||
private TokenCacheObject(OAuth2AccessToken token, OAuth2Authentication auth) {
|
||||
this.token = token;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
private Map<String, TokenCacheObject> authCache = new HashMap<String, TokenCacheObject>();
|
||||
// Inner class to store in the hash map
|
||||
private class TokenCacheObject { OAuth2AccessToken token; OAuth2Authentication auth;
|
||||
private TokenCacheObject(OAuth2AccessToken token, OAuth2Authentication auth) {
|
||||
this.token = token;
|
||||
this.auth = auth;
|
||||
}
|
||||
}
|
||||
private Map<String, TokenCacheObject> authCache = new HashMap<String, TokenCacheObject>();
|
||||
|
||||
public String getIntrospectionUrl() {
|
||||
return introspectionUrl;
|
||||
}
|
||||
public String getIntrospectionUrl() {
|
||||
return introspectionUrl;
|
||||
}
|
||||
|
||||
public void setIntrospectionUrl(String introspectionUrl) {
|
||||
this.introspectionUrl = introspectionUrl;
|
||||
}
|
||||
public void setIntrospectionUrl(String introspectionUrl) {
|
||||
this.introspectionUrl = introspectionUrl;
|
||||
}
|
||||
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
// Check if there is a token and authentication in the cache
|
||||
// and check if it is not expired.
|
||||
private TokenCacheObject checkCache(String key) {
|
||||
if(authCache.containsKey(key)) {
|
||||
TokenCacheObject tco = authCache.get(key);
|
||||
if (tco.token.getExpiration().after(new Date())) {
|
||||
return tco;
|
||||
} else {
|
||||
// if the token is expired, don't keep things around.
|
||||
authCache.remove(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
// Check if there is a token and authentication in the cache
|
||||
// and check if it is not expired.
|
||||
private TokenCacheObject checkCache(String key) {
|
||||
if(authCache.containsKey(key)) {
|
||||
TokenCacheObject tco = authCache.get(key);
|
||||
if (tco.token.getExpiration().after(new Date())) {
|
||||
return tco;
|
||||
} else {
|
||||
// if the token is expired, don't keep things around.
|
||||
authCache.remove(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private OAuth2Request createStoredRequest(final JsonObject token) {
|
||||
clientId = token.get("client_id").getAsString();
|
||||
Set<String> scopes = new HashSet<String>();
|
||||
for (JsonElement e : token.get("scope").getAsJsonArray()) {
|
||||
scopes.add(e.getAsString());
|
||||
}
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
parameters.put("client_id", clientId);
|
||||
parameters.put("scope", OAuth2Utils.formatParameterList(scopes));
|
||||
OAuth2Request storedRequest = new OAuth2Request(parameters, clientId, null, true, scopes, null, null, null);
|
||||
return storedRequest;
|
||||
private OAuth2Request createStoredRequest(final JsonObject token) {
|
||||
clientId = token.get("client_id").getAsString();
|
||||
Set<String> scopes = new HashSet<String>();
|
||||
for (JsonElement e : token.get("scope").getAsJsonArray()) {
|
||||
scopes.add(e.getAsString());
|
||||
}
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
parameters.put("client_id", clientId);
|
||||
parameters.put("scope", OAuth2Utils.formatParameterList(scopes));
|
||||
OAuth2Request storedRequest = new OAuth2Request(parameters, clientId, null, true, scopes, null, null, null);
|
||||
return storedRequest;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// create a default authentication object with authority ROLE_API
|
||||
private Authentication createAuthentication(JsonObject token){
|
||||
// TODO: make role/authority configurable somehow
|
||||
return new PreAuthenticatedAuthenticationToken(token.get("subject").getAsString(), null, AuthorityUtils.createAuthorityList("ROLE_API"));
|
||||
}
|
||||
// create a default authentication object with authority ROLE_API
|
||||
private Authentication createAuthentication(JsonObject token){
|
||||
// TODO: make role/authority configurable somehow
|
||||
return new PreAuthenticatedAuthenticationToken(token.get("subject").getAsString(), null, AuthorityUtils.createAuthorityList("ROLE_API"));
|
||||
}
|
||||
|
||||
private OAuth2AccessToken createAccessToken(final JsonObject token, final String tokenString){
|
||||
OAuth2AccessToken accessToken = new OAuth2AccessTokenImpl(token, tokenString);
|
||||
return accessToken;
|
||||
}
|
||||
private OAuth2AccessToken createAccessToken(final JsonObject token, final String tokenString){
|
||||
OAuth2AccessToken accessToken = new OAuth2AccessTokenImpl(token, tokenString);
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
// Validate a token string against the introspection endpoint,
|
||||
// then parse it and store it in the local cache. Return true on
|
||||
// sucess, false otherwise.
|
||||
private boolean parseToken(String accessToken) {
|
||||
String validatedToken = null;
|
||||
// Use the SpringFramework RestTemplate to send the request to the endpoint
|
||||
// Validate a token string against the introspection endpoint,
|
||||
// then parse it and store it in the local cache. Return true on
|
||||
// sucess, false otherwise.
|
||||
private boolean parseToken(String accessToken) {
|
||||
String validatedToken = null;
|
||||
// Use the SpringFramework RestTemplate to send the request to the endpoint
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
|
||||
form.add("token",accessToken);
|
||||
form.add("client_id", this.clientId);
|
||||
form.add("client_secret", this.clientSecret);
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
MultiValueMap<String, String> form = new LinkedMultiValueMap<String, String>();
|
||||
form.add("token",accessToken);
|
||||
form.add("client_id", this.clientId);
|
||||
form.add("client_secret", this.clientSecret);
|
||||
|
||||
try {
|
||||
validatedToken = restTemplate.postForObject(introspectionUrl, form, String.class);
|
||||
} catch (RestClientException rce) {
|
||||
// TODO: LOG THIS!?
|
||||
LoggerFactory.getLogger(IntrospectingTokenService.class).error("validateToken", rce);
|
||||
}
|
||||
if (validatedToken != null) {
|
||||
// parse the json
|
||||
JsonElement jsonRoot = new JsonParser().parse(validatedToken);
|
||||
if (!jsonRoot.isJsonObject()) {
|
||||
return false; // didn't get a proper JSON object
|
||||
}
|
||||
try {
|
||||
validatedToken = restTemplate.postForObject(introspectionUrl, form, String.class);
|
||||
} catch (RestClientException rce) {
|
||||
// TODO: LOG THIS!?
|
||||
LoggerFactory.getLogger(IntrospectingTokenService.class).error("validateToken", rce);
|
||||
}
|
||||
if (validatedToken != null) {
|
||||
// parse the json
|
||||
JsonElement jsonRoot = new JsonParser().parse(validatedToken);
|
||||
if (!jsonRoot.isJsonObject()) {
|
||||
return false; // didn't get a proper JSON object
|
||||
}
|
||||
|
||||
JsonObject tokenResponse = jsonRoot.getAsJsonObject();
|
||||
JsonObject tokenResponse = jsonRoot.getAsJsonObject();
|
||||
|
||||
if (tokenResponse.get("error") != null) {
|
||||
// report an error?
|
||||
return false;
|
||||
}
|
||||
if (tokenResponse.get("error") != null) {
|
||||
// report an error?
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!tokenResponse.get("valid").getAsBoolean()){
|
||||
// non-valid token
|
||||
return false;
|
||||
}
|
||||
// create an OAuth2Authentication
|
||||
OAuth2Authentication auth = new OAuth2Authentication(createStoredRequest(tokenResponse), createAuthentication(tokenResponse));
|
||||
// create an OAuth2AccessToken
|
||||
OAuth2AccessToken token = createAccessToken(tokenResponse, accessToken);
|
||||
if (!tokenResponse.get("valid").getAsBoolean()){
|
||||
// non-valid token
|
||||
return false;
|
||||
}
|
||||
// create an OAuth2Authentication
|
||||
OAuth2Authentication auth = new OAuth2Authentication(createStoredRequest(tokenResponse), createAuthentication(tokenResponse));
|
||||
// create an OAuth2AccessToken
|
||||
OAuth2AccessToken token = createAccessToken(tokenResponse, accessToken);
|
||||
|
||||
if (token.getExpiration().after(new Date())){
|
||||
// Store them in the cache
|
||||
authCache.put(accessToken, new TokenCacheObject(token,auth));
|
||||
if (token.getExpiration().after(new Date())){
|
||||
// Store them in the cache
|
||||
authCache.put(accessToken, new TokenCacheObject(token,auth));
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// If we never put a token and an authentication in the cache...
|
||||
return false;
|
||||
}
|
||||
// If we never put a token and an authentication in the cache...
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException {
|
||||
// First check if the in memory cache has an Authentication object, and that it is still valid
|
||||
// If Valid, return it
|
||||
TokenCacheObject cacheAuth = checkCache(accessToken);
|
||||
if (cacheAuth != null) {
|
||||
return cacheAuth.auth;
|
||||
} else {
|
||||
if (parseToken(accessToken)) {
|
||||
cacheAuth = authCache.get(accessToken);
|
||||
if (cacheAuth != null && (cacheAuth.token.getExpiration().after(new Date()))) {
|
||||
return cacheAuth.auth;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public OAuth2Authentication loadAuthentication(String accessToken) throws AuthenticationException {
|
||||
// First check if the in memory cache has an Authentication object, and that it is still valid
|
||||
// If Valid, return it
|
||||
TokenCacheObject cacheAuth = checkCache(accessToken);
|
||||
if (cacheAuth != null) {
|
||||
return cacheAuth.auth;
|
||||
} else {
|
||||
if (parseToken(accessToken)) {
|
||||
cacheAuth = authCache.get(accessToken);
|
||||
if (cacheAuth != null && (cacheAuth.token.getExpiration().after(new Date()))) {
|
||||
return cacheAuth.auth;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2AccessToken readAccessToken(String accessToken) {
|
||||
// First check if the in memory cache has a Token object, and that it is still valid
|
||||
// If Valid, return it
|
||||
TokenCacheObject cacheAuth = checkCache(accessToken);
|
||||
if (cacheAuth != null) {
|
||||
return cacheAuth.token;
|
||||
} else {
|
||||
if (parseToken(accessToken)) {
|
||||
cacheAuth = authCache.get(accessToken);
|
||||
if (cacheAuth != null && (cacheAuth.token.getExpiration().after(new Date()))) {
|
||||
return cacheAuth.token;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public OAuth2AccessToken readAccessToken(String accessToken) {
|
||||
// First check if the in memory cache has a Token object, and that it is still valid
|
||||
// If Valid, return it
|
||||
TokenCacheObject cacheAuth = checkCache(accessToken);
|
||||
if (cacheAuth != null) {
|
||||
return cacheAuth.token;
|
||||
} else {
|
||||
if (parseToken(accessToken)) {
|
||||
cacheAuth = authCache.get(accessToken);
|
||||
if (cacheAuth != null && (cacheAuth.token.getExpiration().after(new Date()))) {
|
||||
return cacheAuth.token;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,73 +20,73 @@ import com.google.gson.JsonObject;
|
|||
|
||||
public class OAuth2AccessTokenImpl implements OAuth2AccessToken {
|
||||
|
||||
private JsonObject token;
|
||||
private String tokenString;
|
||||
private Set<String> scopes = null;
|
||||
private Date expireDate;
|
||||
private JsonObject token;
|
||||
private String tokenString;
|
||||
private Set<String> scopes = null;
|
||||
private Date expireDate;
|
||||
|
||||
|
||||
public OAuth2AccessTokenImpl(JsonObject token, String tokenString) {
|
||||
this.token = token;
|
||||
this.tokenString = tokenString;
|
||||
scopes = new HashSet<String>();
|
||||
for (JsonElement e : token.get("scope").getAsJsonArray()) {
|
||||
scopes.add(e.getAsString());
|
||||
}
|
||||
public OAuth2AccessTokenImpl(JsonObject token, String tokenString) {
|
||||
this.token = token;
|
||||
this.tokenString = tokenString;
|
||||
scopes = new HashSet<String>();
|
||||
for (JsonElement e : token.get("scope").getAsJsonArray()) {
|
||||
scopes.add(e.getAsString());
|
||||
}
|
||||
|
||||
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
try {
|
||||
expireDate = dateFormater.parse(token.get("expires_at").getAsString());
|
||||
} catch (ParseException ex) {
|
||||
Logger.getLogger(IntrospectingTokenService.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
DateFormat dateFormater = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
|
||||
try {
|
||||
expireDate = dateFormater.parse(token.get("expires_at").getAsString());
|
||||
} catch (ParseException ex) {
|
||||
Logger.getLogger(IntrospectingTokenService.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getAdditionalInformation() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Map<String, Object> getAdditionalInformation() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getScope() {
|
||||
return scopes;
|
||||
}
|
||||
@Override
|
||||
public Set<String> getScope() {
|
||||
return scopes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2RefreshToken getRefreshToken() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public OAuth2RefreshToken getRefreshToken() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTokenType() {
|
||||
return BEARER_TYPE;
|
||||
}
|
||||
@Override
|
||||
public String getTokenType() {
|
||||
return BEARER_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExpired() {
|
||||
if (expireDate != null && expireDate.before(new Date())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isExpired() {
|
||||
if (expireDate != null && expireDate.before(new Date())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Date getExpiration() {
|
||||
return expireDate;
|
||||
}
|
||||
@Override
|
||||
public Date getExpiration() {
|
||||
return expireDate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getExpiresIn() {
|
||||
if (expireDate != null) {
|
||||
return (int)TimeUnit.MILLISECONDS.toSeconds(expireDate.getTime() - (new Date()).getTime());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getExpiresIn() {
|
||||
if (expireDate != null) {
|
||||
return (int)TimeUnit.MILLISECONDS.toSeconds(expireDate.getTime() - (new Date()).getTime());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue() {
|
||||
return tokenString;
|
||||
}
|
||||
@Override
|
||||
public String getValue() {
|
||||
return tokenString;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,8 +20,6 @@ import java.math.BigInteger;
|
|||
import java.security.SecureRandom;
|
||||
import java.text.ParseException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -29,8 +27,6 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
import org.mitre.jwt.signer.service.JwtSigningAndValidationService;
|
||||
import org.mitre.jwt.signer.service.impl.JWKSetSigningAndValidationServiceCacheService;
|
||||
|
@ -232,7 +228,7 @@ public class OIDCAuthenticationFilter extends AbstractAuthenticationProcessingFi
|
|||
*/
|
||||
form.add("client_id", clientConfig.getClientId());
|
||||
form.add("client_secret", clientConfig.getClientSecret());
|
||||
/**/
|
||||
/**/
|
||||
|
||||
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
|
||||
|
@ -303,99 +299,99 @@ public class OIDCAuthenticationFilter extends AbstractAuthenticationProcessingFi
|
|||
}
|
||||
|
||||
try {
|
||||
SignedJWT idToken = SignedJWT.parse(idTokenValue);
|
||||
SignedJWT idToken = SignedJWT.parse(idTokenValue);
|
||||
|
||||
// validate our ID Token over a number of tests
|
||||
ReadOnlyJWTClaimsSet idClaims = idToken.getJWTClaimsSet();
|
||||
// validate our ID Token over a number of tests
|
||||
ReadOnlyJWTClaimsSet idClaims = idToken.getJWTClaimsSet();
|
||||
|
||||
// check the signature
|
||||
JwtSigningAndValidationService jwtValidator = validationServices.get(serverConfig.getJwksUri());
|
||||
if (jwtValidator != null) {
|
||||
if(!jwtValidator.validateSignature(idToken)) {
|
||||
throw new AuthenticationServiceException("Signature validation failed");
|
||||
}
|
||||
} else {
|
||||
logger.info("No validation service found. Skipping signature validation");
|
||||
}
|
||||
// check the signature
|
||||
JwtSigningAndValidationService jwtValidator = validationServices.get(serverConfig.getJwksUri());
|
||||
if (jwtValidator != null) {
|
||||
if(!jwtValidator.validateSignature(idToken)) {
|
||||
throw new AuthenticationServiceException("Signature validation failed");
|
||||
}
|
||||
} else {
|
||||
logger.info("No validation service found. Skipping signature validation");
|
||||
}
|
||||
|
||||
// check the issuer
|
||||
if (idClaims.getIssuer() == null) {
|
||||
throw new AuthenticationServiceException("Id Token Issuer is null");
|
||||
} else if (!idClaims.getIssuer().equals(serverConfig.getIssuer())){
|
||||
throw new AuthenticationServiceException("Issuers do not match, expected " + serverConfig.getIssuer() + " got " + idClaims.getIssuer());
|
||||
}
|
||||
// check the issuer
|
||||
if (idClaims.getIssuer() == null) {
|
||||
throw new AuthenticationServiceException("Id Token Issuer is null");
|
||||
} else if (!idClaims.getIssuer().equals(serverConfig.getIssuer())){
|
||||
throw new AuthenticationServiceException("Issuers do not match, expected " + serverConfig.getIssuer() + " got " + idClaims.getIssuer());
|
||||
}
|
||||
|
||||
// check expiration
|
||||
if (idClaims.getExpirationTime() == null) {
|
||||
throw new AuthenticationServiceException("Id Token does not have required expiration claim");
|
||||
} else {
|
||||
// it's not null, see if it's expired
|
||||
Date now = new Date(System.currentTimeMillis() - (timeSkewAllowance * 1000));
|
||||
if (now.after(idClaims.getExpirationTime())) {
|
||||
throw new AuthenticationServiceException("Id Token is expired: " + idClaims.getExpirationTime());
|
||||
}
|
||||
}
|
||||
// check expiration
|
||||
if (idClaims.getExpirationTime() == null) {
|
||||
throw new AuthenticationServiceException("Id Token does not have required expiration claim");
|
||||
} else {
|
||||
// it's not null, see if it's expired
|
||||
Date now = new Date(System.currentTimeMillis() - (timeSkewAllowance * 1000));
|
||||
if (now.after(idClaims.getExpirationTime())) {
|
||||
throw new AuthenticationServiceException("Id Token is expired: " + idClaims.getExpirationTime());
|
||||
}
|
||||
}
|
||||
|
||||
// check not before
|
||||
if (idClaims.getNotBeforeTime() != null) {
|
||||
Date now = new Date(System.currentTimeMillis() + (timeSkewAllowance * 1000));
|
||||
if (now.before(idClaims.getNotBeforeTime())){
|
||||
throw new AuthenticationServiceException("Id Token not valid untill: " + idClaims.getNotBeforeTime());
|
||||
}
|
||||
}
|
||||
// check not before
|
||||
if (idClaims.getNotBeforeTime() != null) {
|
||||
Date now = new Date(System.currentTimeMillis() + (timeSkewAllowance * 1000));
|
||||
if (now.before(idClaims.getNotBeforeTime())){
|
||||
throw new AuthenticationServiceException("Id Token not valid untill: " + idClaims.getNotBeforeTime());
|
||||
}
|
||||
}
|
||||
|
||||
// check issued at
|
||||
if (idClaims.getIssueTime() == null) {
|
||||
throw new AuthenticationServiceException("Id Token does not have required issued-at claim");
|
||||
} else {
|
||||
// since it's not null, see if it was issued in the future
|
||||
Date now = new Date(System.currentTimeMillis() + (timeSkewAllowance * 1000));
|
||||
if (now.before(idClaims.getIssueTime())) {
|
||||
throw new AuthenticationServiceException("Id Token was issued in the future: " + idClaims.getIssueTime());
|
||||
}
|
||||
}
|
||||
// check issued at
|
||||
if (idClaims.getIssueTime() == null) {
|
||||
throw new AuthenticationServiceException("Id Token does not have required issued-at claim");
|
||||
} else {
|
||||
// since it's not null, see if it was issued in the future
|
||||
Date now = new Date(System.currentTimeMillis() + (timeSkewAllowance * 1000));
|
||||
if (now.before(idClaims.getIssueTime())) {
|
||||
throw new AuthenticationServiceException("Id Token was issued in the future: " + idClaims.getIssueTime());
|
||||
}
|
||||
}
|
||||
|
||||
// check audience
|
||||
if (idClaims.getAudience() == null) {
|
||||
throw new AuthenticationServiceException("Id token audience is null");
|
||||
} else if (!idClaims.getAudience().contains(clientConfig.getClientId())) {
|
||||
throw new AuthenticationServiceException("Audience does not match, expected " + clientConfig.getClientId() + " got " + idClaims.getAudience());
|
||||
}
|
||||
// check audience
|
||||
if (idClaims.getAudience() == null) {
|
||||
throw new AuthenticationServiceException("Id token audience is null");
|
||||
} else if (!idClaims.getAudience().contains(clientConfig.getClientId())) {
|
||||
throw new AuthenticationServiceException("Audience does not match, expected " + clientConfig.getClientId() + " got " + idClaims.getAudience());
|
||||
}
|
||||
|
||||
// compare the nonce to our stored claim
|
||||
// FIXME: Nimbus claims as strings?
|
||||
String nonce = (String) idClaims.getCustomClaim("nonce");
|
||||
if (StringUtils.isBlank(nonce)) {
|
||||
// compare the nonce to our stored claim
|
||||
// FIXME: Nimbus claims as strings?
|
||||
String nonce = (String) idClaims.getCustomClaim("nonce");
|
||||
if (StringUtils.isBlank(nonce)) {
|
||||
|
||||
logger.error("ID token did not contain a nonce claim.");
|
||||
logger.error("ID token did not contain a nonce claim.");
|
||||
|
||||
throw new AuthenticationServiceException("ID token did not contain a nonce claim.");
|
||||
}
|
||||
throw new AuthenticationServiceException("ID token did not contain a nonce claim.");
|
||||
}
|
||||
|
||||
String storedNonce = getStoredNonce(session);
|
||||
if (!nonce.equals(storedNonce)) {
|
||||
logger.error("Possible replay attack detected! The comparison of the nonce in the returned "
|
||||
+ "ID Token to the session " + NONCE_SESSION_VARIABLE + " failed. Expected " + storedNonce + " got " + nonce + ".");
|
||||
String storedNonce = getStoredNonce(session);
|
||||
if (!nonce.equals(storedNonce)) {
|
||||
logger.error("Possible replay attack detected! The comparison of the nonce in the returned "
|
||||
+ "ID Token to the session " + NONCE_SESSION_VARIABLE + " failed. Expected " + storedNonce + " got " + nonce + ".");
|
||||
|
||||
throw new AuthenticationServiceException(
|
||||
"Possible replay attack detected! The comparison of the nonce in the returned "
|
||||
+ "ID Token to the session " + NONCE_SESSION_VARIABLE + " failed. Expected " + storedNonce + " got " + nonce + ".");
|
||||
}
|
||||
throw new AuthenticationServiceException(
|
||||
"Possible replay attack detected! The comparison of the nonce in the returned "
|
||||
+ "ID Token to the session " + NONCE_SESSION_VARIABLE + " failed. Expected " + storedNonce + " got " + nonce + ".");
|
||||
}
|
||||
|
||||
// pull the subject (user id) out as a claim on the id_token
|
||||
// pull the subject (user id) out as a claim on the id_token
|
||||
|
||||
String userId = idClaims.getSubject();
|
||||
String userId = idClaims.getSubject();
|
||||
|
||||
// construct an OIDCAuthenticationToken and return a Authentication object w/the userId and the idToken
|
||||
// construct an OIDCAuthenticationToken and return a Authentication object w/the userId and the idToken
|
||||
|
||||
OIDCAuthenticationToken token = new OIDCAuthenticationToken(userId, idClaims.getIssuer(), serverConfig, idTokenValue, accessTokenValue, refreshTokenValue);
|
||||
OIDCAuthenticationToken token = new OIDCAuthenticationToken(userId, idClaims.getIssuer(), serverConfig, idTokenValue, accessTokenValue, refreshTokenValue);
|
||||
|
||||
Authentication authentication = this.getAuthenticationManager().authenticate(token);
|
||||
Authentication authentication = this.getAuthenticationManager().authenticate(token);
|
||||
|
||||
return authentication;
|
||||
} catch (ParseException e) {
|
||||
throw new AuthenticationServiceException("Couldn't parse idToken: ", e);
|
||||
}
|
||||
return authentication;
|
||||
} catch (ParseException e) {
|
||||
throw new AuthenticationServiceException("Couldn't parse idToken: ", e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ import com.google.common.collect.Sets;
|
|||
*
|
||||
*/
|
||||
public class OIDCAuthenticationProvider implements
|
||||
AuthenticationProvider, InitializingBean {
|
||||
AuthenticationProvider, InitializingBean {
|
||||
|
||||
private UserInfoFetcher userInfoFetcher = new UserInfoFetcher();
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.google.common.collect.ImmutableMap;
|
|||
*/
|
||||
public class OIDCAuthenticationToken extends AbstractAuthenticationToken {
|
||||
|
||||
private static final long serialVersionUID = 22100073066377804L;
|
||||
private static final long serialVersionUID = 22100073066377804L;
|
||||
|
||||
private final Object principal;
|
||||
private final String idTokenValue; // string representation of the id token
|
||||
|
@ -130,46 +130,46 @@ public class OIDCAuthenticationToken extends AbstractAuthenticationToken {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the idTokenValue
|
||||
*/
|
||||
public String getIdTokenValue() {
|
||||
return idTokenValue;
|
||||
}
|
||||
* @return the idTokenValue
|
||||
*/
|
||||
public String getIdTokenValue() {
|
||||
return idTokenValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the accessTokenValue
|
||||
*/
|
||||
public String getAccessTokenValue() {
|
||||
return accessTokenValue;
|
||||
}
|
||||
* @return the accessTokenValue
|
||||
*/
|
||||
public String getAccessTokenValue() {
|
||||
return accessTokenValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the refreshTokenValue
|
||||
*/
|
||||
public String getRefreshTokenValue() {
|
||||
return refreshTokenValue;
|
||||
}
|
||||
* @return the refreshTokenValue
|
||||
*/
|
||||
public String getRefreshTokenValue() {
|
||||
return refreshTokenValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the serverConfiguration
|
||||
*/
|
||||
public ServerConfiguration getServerConfiguration() {
|
||||
return serverConfiguration;
|
||||
}
|
||||
* @return the serverConfiguration
|
||||
*/
|
||||
public ServerConfiguration getServerConfiguration() {
|
||||
return serverConfiguration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the issuer
|
||||
*/
|
||||
public String getIssuer() {
|
||||
return issuer;
|
||||
}
|
||||
* @return the issuer
|
||||
*/
|
||||
public String getIssuer() {
|
||||
return issuer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userInfo
|
||||
*/
|
||||
public UserInfo getUserInfo() {
|
||||
return userInfo;
|
||||
}
|
||||
* @return the userInfo
|
||||
*/
|
||||
public UserInfo getUserInfo() {
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -34,6 +34,6 @@ public class UserInfoFetcher {
|
|||
|
||||
return userInfo;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,9 +34,9 @@ public class ClientKeyPublisher implements BeanDefinitionRegistryPostProcessor {
|
|||
|
||||
/**
|
||||
* If either the jwkPublishUrl or x509PublishUrl fields are set on this bean, set up a listener on that URL to publish keys.
|
||||
*/
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
*/
|
||||
@Override
|
||||
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
|
||||
if (!Strings.isNullOrEmpty(getJwkPublishUrl())) {
|
||||
|
||||
// add a mapping to this class
|
||||
|
@ -62,20 +62,20 @@ public class ClientKeyPublisher implements BeanDefinitionRegistryPostProcessor {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor#postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)
|
||||
*/
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor#postProcessBeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)
|
||||
*/
|
||||
@Override
|
||||
public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
|
||||
this.registry = registry;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a view to publish all keys in JWK format. Only used if jwkPublishUrl is set.
|
||||
* @return
|
||||
*/
|
||||
* Return a view to publish all keys in JWK format. Only used if jwkPublishUrl is set.
|
||||
* @return
|
||||
*/
|
||||
public ModelAndView publishClientJwk() {
|
||||
|
||||
// map from key id to key
|
||||
|
@ -87,18 +87,18 @@ public class ClientKeyPublisher implements BeanDefinitionRegistryPostProcessor {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the jwkPublishUrl
|
||||
*/
|
||||
public String getJwkPublishUrl() {
|
||||
return jwkPublishUrl;
|
||||
}
|
||||
* @return the jwkPublishUrl
|
||||
*/
|
||||
public String getJwkPublishUrl() {
|
||||
return jwkPublishUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jwkPublishUrl the jwkPublishUrl to set
|
||||
*/
|
||||
public void setJwkPublishUrl(String jwkPublishUrl) {
|
||||
this.jwkPublishUrl = jwkPublishUrl;
|
||||
}
|
||||
* @param jwkPublishUrl the jwkPublishUrl to set
|
||||
*/
|
||||
public void setJwkPublishUrl(String jwkPublishUrl) {
|
||||
this.jwkPublishUrl = jwkPublishUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the signingAndValidationService
|
||||
|
|
|
@ -21,70 +21,70 @@ public class ClientKeyPublisherMapping extends RequestMappingInfoHandlerMapping
|
|||
private String x509PublishUrl;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#isHandler(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
protected boolean isHandler(Class<?> beanType) {
|
||||
return beanType.equals(ClientKeyPublisher.class);
|
||||
}
|
||||
* @see org.springframework.web.servlet.handler.AbstractHandlerMethodMapping#isHandler(java.lang.Class)
|
||||
*/
|
||||
@Override
|
||||
protected boolean isHandler(Class<?> beanType) {
|
||||
return beanType.equals(ClientKeyPublisher.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Map the "jwkKeyPublish" method to our jwkPublishUrl.
|
||||
* Map the "x509KeyPublish" method to our x509PublishUrl.
|
||||
*/
|
||||
@Override
|
||||
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
|
||||
*/
|
||||
@Override
|
||||
protected RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
|
||||
|
||||
if (method.getName().equals("publishClientJwk") && getJwkPublishUrl() != null) {
|
||||
return new RequestMappingInfo(
|
||||
new PatternsRequestCondition(new String[] {getJwkPublishUrl()}, getUrlPathHelper(), getPathMatcher(), false, false),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
} else if (method.getName().equals("publishClientx509") && getX509PublishUrl() != null) {
|
||||
return new RequestMappingInfo(
|
||||
new PatternsRequestCondition(new String[] {getX509PublishUrl()}, getUrlPathHelper(), getPathMatcher(), false, false),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
if (method.getName().equals("publishClientJwk") && getJwkPublishUrl() != null) {
|
||||
return new RequestMappingInfo(
|
||||
new PatternsRequestCondition(new String[] {getJwkPublishUrl()}, getUrlPathHelper(), getPathMatcher(), false, false),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
} else if (method.getName().equals("publishClientx509") && getX509PublishUrl() != null) {
|
||||
return new RequestMappingInfo(
|
||||
new PatternsRequestCondition(new String[] {getX509PublishUrl()}, getUrlPathHelper(), getPathMatcher(), false, false),
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jwkPublishUrl
|
||||
*/
|
||||
public String getJwkPublishUrl() {
|
||||
return jwkPublishUrl;
|
||||
}
|
||||
* @return the jwkPublishUrl
|
||||
*/
|
||||
public String getJwkPublishUrl() {
|
||||
return jwkPublishUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jwkPublishUrl the jwkPublishUrl to set
|
||||
*/
|
||||
public void setJwkPublishUrl(String jwkPublishUrl) {
|
||||
this.jwkPublishUrl = jwkPublishUrl;
|
||||
}
|
||||
* @param jwkPublishUrl the jwkPublishUrl to set
|
||||
*/
|
||||
public void setJwkPublishUrl(String jwkPublishUrl) {
|
||||
this.jwkPublishUrl = jwkPublishUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x509PublishUrl
|
||||
*/
|
||||
public String getX509PublishUrl() {
|
||||
return x509PublishUrl;
|
||||
}
|
||||
* @return the x509PublishUrl
|
||||
*/
|
||||
public String getX509PublishUrl() {
|
||||
return x509PublishUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x509PublishUrl the x509PublishUrl to set
|
||||
*/
|
||||
public void setX509PublishUrl(String x509PublishUrl) {
|
||||
this.x509PublishUrl = x509PublishUrl;
|
||||
}
|
||||
* @param x509PublishUrl the x509PublishUrl to set
|
||||
*/
|
||||
public void setX509PublishUrl(String x509PublishUrl) {
|
||||
this.x509PublishUrl = x509PublishUrl;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,74 +46,74 @@ public class JwkViewResolver implements ViewResolver, Ordered {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the x509
|
||||
*/
|
||||
public View getX509() {
|
||||
return x509;
|
||||
}
|
||||
* @return the x509
|
||||
*/
|
||||
public View getX509() {
|
||||
return x509;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x509 the x509 to set
|
||||
*/
|
||||
public void setX509(View x509) {
|
||||
this.x509 = x509;
|
||||
}
|
||||
* @param x509 the x509 to set
|
||||
*/
|
||||
public void setX509(View x509) {
|
||||
this.x509 = x509;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jwk
|
||||
*/
|
||||
public View getJwk() {
|
||||
return jwk;
|
||||
}
|
||||
* @return the jwk
|
||||
*/
|
||||
public View getJwk() {
|
||||
return jwk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jwk the jwk to set
|
||||
*/
|
||||
public void setJwk(View jwk) {
|
||||
this.jwk = jwk;
|
||||
}
|
||||
* @param jwk the jwk to set
|
||||
*/
|
||||
public void setJwk(View jwk) {
|
||||
this.jwk = jwk;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the order
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
* @return the order
|
||||
*/
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param order the order to set
|
||||
*/
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
* @param order the order to set
|
||||
*/
|
||||
public void setOrder(int order) {
|
||||
this.order = order;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jwkViewName
|
||||
*/
|
||||
public String getJwkViewName() {
|
||||
return jwkViewName;
|
||||
}
|
||||
* @return the jwkViewName
|
||||
*/
|
||||
public String getJwkViewName() {
|
||||
return jwkViewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jwkViewName the jwkViewName to set
|
||||
*/
|
||||
public void setJwkViewName(String jwkViewName) {
|
||||
this.jwkViewName = jwkViewName;
|
||||
}
|
||||
* @param jwkViewName the jwkViewName to set
|
||||
*/
|
||||
public void setJwkViewName(String jwkViewName) {
|
||||
this.jwkViewName = jwkViewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the x509ViewName
|
||||
*/
|
||||
public String getX509ViewName() {
|
||||
return x509ViewName;
|
||||
}
|
||||
* @return the x509ViewName
|
||||
*/
|
||||
public String getX509ViewName() {
|
||||
return x509ViewName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param x509ViewName the x509ViewName to set
|
||||
*/
|
||||
public void setX509ViewName(String x509ViewName) {
|
||||
this.x509ViewName = x509ViewName;
|
||||
}
|
||||
* @param x509ViewName the x509ViewName to set
|
||||
*/
|
||||
public void setX509ViewName(String x509ViewName) {
|
||||
this.x509ViewName = x509ViewName;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,18 +22,18 @@ public class IssuerServiceResponse {
|
|||
* @param loginHint
|
||||
* @param targetLinkUri
|
||||
*/
|
||||
public IssuerServiceResponse(String issuer, String loginHint, String targetLinkUri) {
|
||||
this.issuer = issuer;
|
||||
this.loginHint = loginHint;
|
||||
this.targetLinkUri = targetLinkUri;
|
||||
}
|
||||
public IssuerServiceResponse(String issuer, String loginHint, String targetLinkUri) {
|
||||
this.issuer = issuer;
|
||||
this.loginHint = loginHint;
|
||||
this.targetLinkUri = targetLinkUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param redirectUrl
|
||||
*/
|
||||
public IssuerServiceResponse(String redirectUrl) {
|
||||
this.redirectUrl = redirectUrl;
|
||||
}
|
||||
public IssuerServiceResponse(String redirectUrl) {
|
||||
this.redirectUrl = redirectUrl;
|
||||
}
|
||||
/**
|
||||
* @return the issuer
|
||||
*/
|
||||
|
|
|
@ -20,6 +20,6 @@ public interface AuthRequestUrlBuilder {
|
|||
* @param state
|
||||
* @return
|
||||
*/
|
||||
public String buildAuthRequestUrl(ServerConfiguration serverConfig, ClientDetails clientConfig, String redirectUri, String nonce, String state);
|
||||
public String buildAuthRequestUrl(ServerConfiguration serverConfig, ClientDetails clientConfig, String redirectUri, String nonce, String state);
|
||||
|
||||
}
|
||||
|
|
|
@ -46,10 +46,10 @@ public class PlainAuthRequestUrlBuilder implements AuthRequestUrlBuilder {
|
|||
|
||||
return uriBuilder.build().toString();
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -4,11 +4,6 @@
|
|||
package org.mitre.openid.connect.client.service.impl;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.http.client.utils.URIBuilder;
|
||||
import org.mitre.jwt.signer.service.JwtSigningAndValidationService;
|
||||
|
@ -58,14 +53,14 @@ public class SignedAuthRequestUrlBuilder implements AuthRequestUrlBuilder {
|
|||
signingAndValidationService.signJwt(jwt);
|
||||
|
||||
try {
|
||||
URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri());
|
||||
uriBuilder.addParameter("request", jwt.serialize());
|
||||
URIBuilder uriBuilder = new URIBuilder(serverConfig.getAuthorizationEndpointUri());
|
||||
uriBuilder.addParameter("request", jwt.serialize());
|
||||
|
||||
// build out the URI
|
||||
return uriBuilder.build().toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);
|
||||
}
|
||||
// build out the URI
|
||||
return uriBuilder.build().toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AuthenticationServiceException("Malformed Authorization Endpoint Uri", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -50,12 +50,12 @@ public class StaticClientConfigurationService implements ClientConfigurationServ
|
|||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (clients == null || clients.isEmpty()) {
|
||||
throw new IllegalArgumentException("Clients map cannot be null or empty");
|
||||
}
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (clients == null || clients.isEmpty()) {
|
||||
throw new IllegalArgumentException("Clients map cannot be null or empty");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,12 +45,12 @@ public class StaticServerConfigurationService implements ServerConfigurationServ
|
|||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (servers == null || servers.isEmpty()) {
|
||||
throw new IllegalArgumentException("Servers map cannot be null or empty.");
|
||||
}
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (servers == null || servers.isEmpty()) {
|
||||
throw new IllegalArgumentException("Servers map cannot be null or empty.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,13 +46,13 @@ public class StaticSingleIssuerService implements IssuerService, InitializingBea
|
|||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
|
||||
if (Strings.isNullOrEmpty(issuer)) {
|
||||
throw new IllegalArgumentException("Issuer must not be null or empty.");
|
||||
}
|
||||
if (Strings.isNullOrEmpty(issuer)) {
|
||||
throw new IllegalArgumentException("Issuer must not be null or empty.");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -40,15 +40,15 @@ public class ThirdPartyIssuerService implements IssuerService, InitializingBean
|
|||
try {
|
||||
// otherwise, need to forward to the account chooser
|
||||
String redirectUri = request.getRequestURL().toString();
|
||||
URIBuilder builder = new URIBuilder(accountChooserUrl);
|
||||
URIBuilder builder = new URIBuilder(accountChooserUrl);
|
||||
|
||||
builder.addParameter("redirect_uri", redirectUri);
|
||||
builder.addParameter("redirect_uri", redirectUri);
|
||||
|
||||
return new IssuerServiceResponse(builder.build().toString());
|
||||
return new IssuerServiceResponse(builder.build().toString());
|
||||
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AuthenticationServiceException("Account Chooser URL is not valid", e);
|
||||
}
|
||||
} catch (URISyntaxException e) {
|
||||
throw new AuthenticationServiceException("Account Chooser URL is not valid", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -72,12 +72,12 @@ public class ThirdPartyIssuerService implements IssuerService, InitializingBean
|
|||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (Strings.isNullOrEmpty(this.accountChooserUrl)) {
|
||||
throw new IllegalArgumentException("Account Chooser URL cannot be null or empty");
|
||||
}
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (Strings.isNullOrEmpty(this.accountChooserUrl)) {
|
||||
throw new IllegalArgumentException("Account Chooser URL cannot be null or empty");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
package org.mitre.openid.connect.client;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Unit test for OIDCAuthenticationFilter
|
||||
|
|
|
@ -5,7 +5,6 @@ package org.mitre.jose;
|
|||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
@ -30,8 +29,8 @@ public class JWEAlgorithmEmbed {
|
|||
}
|
||||
|
||||
public JWEAlgorithmEmbed(JWEAlgorithm algorithm) {
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
public static JWEAlgorithmEmbed getForAlgorithmName (String algorithmName) {
|
||||
JWEAlgorithmEmbed ent = new JWEAlgorithmEmbed();
|
||||
|
@ -72,15 +71,15 @@ public class JWEAlgorithmEmbed {
|
|||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JWEAlgorithmEmbed [algorithm=" + algorithm + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JWEAlgorithmEmbed [algorithm=" + algorithm + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the algorithm
|
||||
*/
|
||||
@Transient
|
||||
@Transient
|
||||
public JWEAlgorithm getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import javax.persistence.Transient;
|
|||
|
||||
import com.google.common.base.Strings;
|
||||
import com.nimbusds.jose.EncryptionMethod;
|
||||
import com.nimbusds.jose.JWEAlgorithm;
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
|
@ -27,8 +26,8 @@ public class JWEEncryptionMethodEmbed {
|
|||
}
|
||||
|
||||
public JWEEncryptionMethodEmbed(EncryptionMethod algorithm) {
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
public static JWEEncryptionMethodEmbed getForAlgorithmName (String algorithmName) {
|
||||
JWEEncryptionMethodEmbed ent = new JWEEncryptionMethodEmbed();
|
||||
|
@ -69,15 +68,15 @@ public class JWEEncryptionMethodEmbed {
|
|||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JWEEncryptionMethodEmbed [algorithm=" + algorithm + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JWEEncryptionMethodEmbed [algorithm=" + algorithm + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the algorithm
|
||||
*/
|
||||
@Transient
|
||||
@Transient
|
||||
public EncryptionMethod getAlgorithm() {
|
||||
return algorithm;
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ package org.mitre.jose;
|
|||
|
||||
import javax.persistence.Basic;
|
||||
import javax.persistence.Embeddable;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Transient;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
|
@ -31,8 +29,8 @@ public class JWSAlgorithmEmbed {
|
|||
}
|
||||
|
||||
public JWSAlgorithmEmbed(JWSAlgorithm algorithm) {
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
this.algorithm = algorithm;
|
||||
}
|
||||
|
||||
public static JWSAlgorithmEmbed getForAlgorithmName (String algorithmName) {
|
||||
JWSAlgorithmEmbed ent = new JWSAlgorithmEmbed();
|
||||
|
@ -88,10 +86,10 @@ public class JWSAlgorithmEmbed {
|
|||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JWSAlgorithmEmbed [algorithm=" + algorithm + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "JWSAlgorithmEmbed [algorithm=" + algorithm + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -90,9 +90,9 @@ public class JWKSetKeyStore implements InitializingBean {
|
|||
/**
|
||||
* Get the list of keys in this keystore. This is a passthrough to the underlying JWK Set
|
||||
*/
|
||||
public List<JWK> getKeys() {
|
||||
return jwkSet.getKeys();
|
||||
}
|
||||
public List<JWK> getKeys() {
|
||||
return jwkSet.getKeys();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
package org.mitre.jwt.signer.service;
|
||||
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.PublicKey;
|
||||
import java.util.Map;
|
||||
|
||||
import com.nimbusds.jose.JWSAlgorithm;
|
||||
|
@ -55,7 +54,7 @@ public interface JwtSigningAndValidationService {
|
|||
* Get the default signing algorithm for use when nothing else has been specified.
|
||||
* @return
|
||||
*/
|
||||
public JWSAlgorithm getDefaultSigningAlgorithm();
|
||||
public JWSAlgorithm getDefaultSigningAlgorithm();
|
||||
|
||||
/**
|
||||
* Sign a jwt using the selected algorithm. The algorithm is selected using the String parameter values specified
|
||||
|
|
|
@ -70,10 +70,10 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
|||
* @throws NoSuchAlgorithmException
|
||||
* If there is no appropriate algorithm to tie the keys to.
|
||||
*/
|
||||
public DefaultJwtSigningAndValidationService(Map<String, JWK> keys) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
this.keys = keys;
|
||||
buildSignersAndVerifiers();
|
||||
}
|
||||
public DefaultJwtSigningAndValidationService(Map<String, JWK> keys) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
this.keys = keys;
|
||||
buildSignersAndVerifiers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Build this service based on the given keystore. All keys must have a key
|
||||
|
@ -87,17 +87,17 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
|||
* @throws NoSuchAlgorithmException
|
||||
* If there is no appropriate algorithm to tie the keys to.
|
||||
*/
|
||||
public DefaultJwtSigningAndValidationService(JWKSetKeyStore keyStore) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
// convert all keys in the keystore to a map based on key id
|
||||
for (JWK key : keyStore.getKeys()) {
|
||||
if (!Strings.isNullOrEmpty(key.getKeyID())) {
|
||||
this.keys.put(key.getKeyID(), key);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Tried to load a key from a keystore without a 'kid' field: " + key);
|
||||
}
|
||||
}
|
||||
buildSignersAndVerifiers();
|
||||
}
|
||||
public DefaultJwtSigningAndValidationService(JWKSetKeyStore keyStore) throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
// convert all keys in the keystore to a map based on key id
|
||||
for (JWK key : keyStore.getKeys()) {
|
||||
if (!Strings.isNullOrEmpty(key.getKeyID())) {
|
||||
this.keys.put(key.getKeyID(), key);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Tried to load a key from a keystore without a 'kid' field: " + key);
|
||||
}
|
||||
}
|
||||
buildSignersAndVerifiers();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the defaultSignerKeyId
|
||||
|
@ -117,21 +117,21 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
|||
* @return
|
||||
*/
|
||||
@Override
|
||||
public JWSAlgorithm getDefaultSigningAlgorithm() {
|
||||
return defaultAlgorithm;
|
||||
}
|
||||
public JWSAlgorithm getDefaultSigningAlgorithm() {
|
||||
return defaultAlgorithm;
|
||||
}
|
||||
|
||||
public void setDefaultSigningAlgorithmName(String algName) {
|
||||
defaultAlgorithm = JWSAlgorithm.parse(algName);
|
||||
}
|
||||
public void setDefaultSigningAlgorithmName(String algName) {
|
||||
defaultAlgorithm = JWSAlgorithm.parse(algName);
|
||||
}
|
||||
|
||||
public String getDefaultSigningAlgorithmName() {
|
||||
if (defaultAlgorithm != null) {
|
||||
return defaultAlgorithm.getName();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public String getDefaultSigningAlgorithmName() {
|
||||
if (defaultAlgorithm != null) {
|
||||
return defaultAlgorithm.getName();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
|
@ -156,45 +156,45 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
|||
* @throws InvalidKeySpecException If the keys in the JWKs are not valid
|
||||
* @throws NoSuchAlgorithmException If there is no appropriate algorithm to tie the keys to.
|
||||
*/
|
||||
private void buildSignersAndVerifiers() throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
private void buildSignersAndVerifiers() throws NoSuchAlgorithmException, InvalidKeySpecException {
|
||||
for (Map.Entry<String, JWK> jwkEntry : keys.entrySet()) {
|
||||
|
||||
String id = jwkEntry.getKey();
|
||||
JWK jwk = jwkEntry.getValue();
|
||||
|
||||
if (jwk instanceof RSAKey) {
|
||||
// build RSA signers & verifiers
|
||||
if (jwk instanceof RSAKey) {
|
||||
// build RSA signers & verifiers
|
||||
|
||||
if (jwk.isPrivate()) { // only add the signer if there's a private key
|
||||
RSASSASigner signer = new RSASSASigner(((RSAKey) jwk).toRSAPrivateKey());
|
||||
signers.put(id, signer);
|
||||
}
|
||||
if (jwk.isPrivate()) { // only add the signer if there's a private key
|
||||
RSASSASigner signer = new RSASSASigner(((RSAKey) jwk).toRSAPrivateKey());
|
||||
signers.put(id, signer);
|
||||
}
|
||||
|
||||
RSASSAVerifier verifier = new RSASSAVerifier(((RSAKey) jwk).toRSAPublicKey());
|
||||
verifiers.put(id, verifier);
|
||||
RSASSAVerifier verifier = new RSASSAVerifier(((RSAKey) jwk).toRSAPublicKey());
|
||||
verifiers.put(id, verifier);
|
||||
|
||||
} else if (jwk instanceof ECKey) {
|
||||
// build EC signers & verifiers
|
||||
} else if (jwk instanceof ECKey) {
|
||||
// build EC signers & verifiers
|
||||
|
||||
// TODO: add support for EC keys
|
||||
logger.warn("EC Keys are not yet supported.");
|
||||
// TODO: add support for EC keys
|
||||
logger.warn("EC Keys are not yet supported.");
|
||||
|
||||
} else if (jwk instanceof OctetSequenceKey) {
|
||||
// build HMAC signers & verifiers
|
||||
} else if (jwk instanceof OctetSequenceKey) {
|
||||
// build HMAC signers & verifiers
|
||||
|
||||
if (jwk.isPrivate()) { // technically redundant check because all HMAC keys are private
|
||||
MACSigner signer = new MACSigner(((OctetSequenceKey) jwk).toByteArray());
|
||||
signers.put(id, signer);
|
||||
}
|
||||
if (jwk.isPrivate()) { // technically redundant check because all HMAC keys are private
|
||||
MACSigner signer = new MACSigner(((OctetSequenceKey) jwk).toByteArray());
|
||||
signers.put(id, signer);
|
||||
}
|
||||
|
||||
MACVerifier verifier = new MACVerifier(((OctetSequenceKey) jwk).toByteArray());
|
||||
verifiers.put(id, verifier);
|
||||
MACVerifier verifier = new MACVerifier(((OctetSequenceKey) jwk).toByteArray());
|
||||
verifiers.put(id, verifier);
|
||||
|
||||
} else {
|
||||
logger.warn("Unknown key type: " + jwk);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
logger.warn("Unknown key type: " + jwk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sign a jwt in place using the configured default signer.
|
||||
|
@ -208,11 +208,11 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
|||
JWSSigner signer = signers.get(getDefaultSignerKeyId());
|
||||
|
||||
try {
|
||||
jwt.sign(signer);
|
||||
} catch (JOSEException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
jwt.sign(signer);
|
||||
} catch (JOSEException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -225,9 +225,9 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
|||
return true;
|
||||
}
|
||||
} catch (JOSEException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -238,12 +238,12 @@ public class DefaultJwtSigningAndValidationService implements JwtSigningAndValid
|
|||
|
||||
// pull all keys out of the verifiers if we know how
|
||||
for (String keyId : keys.keySet()) {
|
||||
JWK key = keys.get(keyId);
|
||||
JWK pub = key.toPublicJWK();
|
||||
if (pub != null) {
|
||||
pubKeys.put(keyId, pub);
|
||||
}
|
||||
}
|
||||
JWK key = keys.get(keyId);
|
||||
JWK pub = key.toPublicJWK();
|
||||
if (pub != null) {
|
||||
pubKeys.put(keyId, pub);
|
||||
}
|
||||
}
|
||||
|
||||
return pubKeys;
|
||||
}
|
||||
|
|
|
@ -3,12 +3,6 @@
|
|||
*/
|
||||
package org.mitre.jwt.signer.service.impl;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.KeyFactory;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.RSAPublicKeySpec;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import org.apache.http.client.HttpClient;
|
||||
|
@ -22,12 +16,7 @@ import org.springframework.web.client.RestTemplate;
|
|||
import com.google.common.cache.Cache;
|
||||
import com.google.common.cache.CacheBuilder;
|
||||
import com.google.common.cache.CacheLoader;
|
||||
import com.nimbusds.jose.JWSVerifier;
|
||||
import com.nimbusds.jose.crypto.RSASSAVerifier;
|
||||
import com.nimbusds.jose.jwk.JWK;
|
||||
import com.nimbusds.jose.jwk.JWKSet;
|
||||
import com.nimbusds.jose.jwk.KeyType;
|
||||
import com.nimbusds.jose.jwk.RSAKey;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -53,42 +42,42 @@ public class JWKSetSigningAndValidationServiceCacheService {
|
|||
* @throws ExecutionException
|
||||
* @see com.google.common.cache.Cache#get(java.lang.Object)
|
||||
*/
|
||||
public JwtSigningAndValidationService get(String key) {
|
||||
try {
|
||||
return cache.get(key);
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public JwtSigningAndValidationService get(String key) {
|
||||
try {
|
||||
return cache.get(key);
|
||||
} catch (ExecutionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
private class JWKSetVerifierFetcher extends CacheLoader<String, JwtSigningAndValidationService> {
|
||||
private HttpClient httpClient = new DefaultHttpClient();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private RestTemplate restTemplate = new RestTemplate(httpFactory);
|
||||
* @author jricher
|
||||
*
|
||||
*/
|
||||
private class JWKSetVerifierFetcher extends CacheLoader<String, JwtSigningAndValidationService> {
|
||||
private HttpClient httpClient = new DefaultHttpClient();
|
||||
private HttpComponentsClientHttpRequestFactory httpFactory = new HttpComponentsClientHttpRequestFactory(httpClient);
|
||||
private RestTemplate restTemplate = new RestTemplate(httpFactory);
|
||||
|
||||
/**
|
||||
* Load the JWK Set and build the appropriate signing service.
|
||||
*/
|
||||
@Override
|
||||
public JwtSigningAndValidationService load(String key) throws Exception {
|
||||
/**
|
||||
* Load the JWK Set and build the appropriate signing service.
|
||||
*/
|
||||
@Override
|
||||
public JwtSigningAndValidationService load(String key) throws Exception {
|
||||
|
||||
String jsonString = restTemplate.getForObject(key, String.class);
|
||||
JWKSet jwkSet = JWKSet.parse(jsonString);
|
||||
String jsonString = restTemplate.getForObject(key, String.class);
|
||||
JWKSet jwkSet = JWKSet.parse(jsonString);
|
||||
|
||||
JWKSetKeyStore keyStore = new JWKSetKeyStore(jwkSet);
|
||||
JWKSetKeyStore keyStore = new JWKSetKeyStore(jwkSet);
|
||||
|
||||
JwtSigningAndValidationService service = new DefaultJwtSigningAndValidationService(keyStore);
|
||||
JwtSigningAndValidationService service = new DefaultJwtSigningAndValidationService(keyStore);
|
||||
|
||||
return service;
|
||||
return service;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public class AuthorizationCodeEntity {
|
|||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
private String policyUri;
|
||||
private String jwksUri;
|
||||
|
||||
/** Fields from OIDC Client Registration Specification **/
|
||||
/** Fields from OIDC Client Registration Specification **/
|
||||
private AppType applicationType; // application_type
|
||||
private String sectorIdentifierUri; // sector_identifier_uri
|
||||
private SubjectType subjectType; // subject_type
|
||||
|
@ -162,8 +162,8 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
private static final Map<String, AppType> lookup = new HashMap<String, AppType>();
|
||||
static {
|
||||
for (AppType a : AppType.values()) {
|
||||
lookup.put(a.getValue(), a);
|
||||
}
|
||||
lookup.put(a.getValue(), a);
|
||||
}
|
||||
}
|
||||
|
||||
AppType(String value) {
|
||||
|
@ -179,8 +179,8 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
}
|
||||
}
|
||||
|
||||
public enum SubjectType {
|
||||
PAIRWISE("pairwise"), PUBLIC("public");
|
||||
public enum SubjectType {
|
||||
PAIRWISE("pairwise"), PUBLIC("public");
|
||||
|
||||
private final String value;
|
||||
|
||||
|
@ -188,8 +188,8 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
private static final Map<String, SubjectType> lookup = new HashMap<String, SubjectType>();
|
||||
static {
|
||||
for (SubjectType u : SubjectType.values()) {
|
||||
lookup.put(u.getValue(), u);
|
||||
}
|
||||
lookup.put(u.getValue(), u);
|
||||
}
|
||||
}
|
||||
|
||||
SubjectType(String value) {
|
||||
|
@ -203,7 +203,7 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
public static SubjectType getByValue(String value) {
|
||||
return lookup.get(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a blank ClientDetailsEntity
|
||||
|
@ -230,32 +230,32 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the clientDescription
|
||||
*/
|
||||
* @return the clientDescription
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="client_description")
|
||||
public String getClientDescription() {
|
||||
return clientDescription;
|
||||
}
|
||||
public String getClientDescription() {
|
||||
return clientDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientDescription Human-readable long description of the client (optional)
|
||||
*/
|
||||
public void setClientDescription(String clientDescription) {
|
||||
this.clientDescription = clientDescription;
|
||||
}
|
||||
* @param clientDescription Human-readable long description of the client (optional)
|
||||
*/
|
||||
public void setClientDescription(String clientDescription) {
|
||||
this.clientDescription = clientDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the allowRefresh
|
||||
*/
|
||||
* @return the allowRefresh
|
||||
*/
|
||||
@Transient
|
||||
public boolean isAllowRefresh() {
|
||||
public boolean isAllowRefresh() {
|
||||
if (grantTypes != null) {
|
||||
return getAuthorizedGrantTypes().contains("refresh_token");
|
||||
} else {
|
||||
return false; // if there are no grants, we can't be refreshing them, can we?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name="reuse_refresh_tokens")
|
||||
|
@ -304,142 +304,143 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
|
||||
|
||||
/**
|
||||
* @return the allowIntrospection
|
||||
*/
|
||||
* @return the allowIntrospection
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="allow_introspection")
|
||||
public boolean isAllowIntrospection() {
|
||||
return allowIntrospection;
|
||||
}
|
||||
public boolean isAllowIntrospection() {
|
||||
return allowIntrospection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param allowIntrospection the allowIntrospection to set
|
||||
*/
|
||||
public void setAllowIntrospection(boolean allowIntrospection) {
|
||||
this.allowIntrospection = allowIntrospection;
|
||||
}
|
||||
* @param allowIntrospection the allowIntrospection to set
|
||||
*/
|
||||
public void setAllowIntrospection(boolean allowIntrospection) {
|
||||
this.allowIntrospection = allowIntrospection;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isSecretRequired() {
|
||||
// TODO: this should check the auth method field instead
|
||||
return getClientSecret() != null;
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isSecretRequired() {
|
||||
// TODO: this should check the auth method field instead
|
||||
return getClientSecret() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the scope list is not null or empty, then this client has been scoped.
|
||||
*/
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isScoped() {
|
||||
return getScope() != null && !getScope().isEmpty();
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isScoped() {
|
||||
return getScope() != null && !getScope().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clientId
|
||||
*/
|
||||
* @return the clientId
|
||||
*/
|
||||
@Basic
|
||||
@Override
|
||||
@Column(name="client_id")
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientId The OAuth2 client_id, must be unique to this client
|
||||
*/
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
* @param clientId The OAuth2 client_id, must be unique to this client
|
||||
*/
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clientSecret
|
||||
*/
|
||||
* @return the clientSecret
|
||||
*/
|
||||
@Basic
|
||||
@Override
|
||||
@Column(name="client_secret")
|
||||
public String getClientSecret() {
|
||||
return clientSecret;
|
||||
}
|
||||
return clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientSecret the OAuth2 client_secret (optional)
|
||||
*/
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
* @param clientSecret the OAuth2 client_secret (optional)
|
||||
*/
|
||||
public void setClientSecret(String clientSecret) {
|
||||
this.clientSecret = clientSecret;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scope
|
||||
*/
|
||||
* @return the scope
|
||||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="client_scope",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
)
|
||||
@Override
|
||||
@Column(name="scope")
|
||||
public Set<String> getScope() {
|
||||
return scope;
|
||||
}
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scope the set of scopes allowed to be issued to this client
|
||||
*/
|
||||
public void setScope(Set<String> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
* @param scope the set of scopes allowed to be issued to this client
|
||||
*/
|
||||
public void setScope(Set<String> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the authorizedGrantTypes
|
||||
*/
|
||||
* @return the authorizedGrantTypes
|
||||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="client_grant_type",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
)
|
||||
@Column(name="grant_type")
|
||||
public Set<String> getGrantTypes() {
|
||||
return grantTypes;
|
||||
}
|
||||
return grantTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authorizedGrantTypes the OAuth2 grant types that this client is allowed to use
|
||||
*/
|
||||
public void setGrantTypes(Set<String> grantTypes) {
|
||||
this.grantTypes = grantTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* passthrough for SECOAUTH api
|
||||
*/
|
||||
public Set<String> getAuthorizedGrantTypes() {
|
||||
return getGrantTypes();
|
||||
}
|
||||
* @param authorizedGrantTypes the OAuth2 grant types that this client is allowed to use
|
||||
*/
|
||||
public void setGrantTypes(Set<String> grantTypes) {
|
||||
this.grantTypes = grantTypes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the authorities
|
||||
*/
|
||||
* passthrough for SECOAUTH api
|
||||
*/
|
||||
@Override
|
||||
public Set<String> getAuthorizedGrantTypes() {
|
||||
return getGrantTypes();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the authorities
|
||||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="client_authority",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
)
|
||||
@Override
|
||||
@Column(name="authority")
|
||||
public Set<GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
public Set<GrantedAuthority> getAuthorities() {
|
||||
return authorities;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authorities the Spring Security authorities this client is given
|
||||
*/
|
||||
public void setAuthorities(Set<GrantedAuthority> authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
* @param authorities the Spring Security authorities this client is given
|
||||
*/
|
||||
public void setAuthorities(Set<GrantedAuthority> authorities) {
|
||||
this.authorities = authorities;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Basic
|
||||
|
@ -449,11 +450,11 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param accessTokenTimeout the accessTokenTimeout to set
|
||||
*/
|
||||
public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) {
|
||||
this.accessTokenValiditySeconds = accessTokenValiditySeconds;
|
||||
}
|
||||
* @param accessTokenTimeout the accessTokenTimeout to set
|
||||
*/
|
||||
public void setAccessTokenValiditySeconds(Integer accessTokenValiditySeconds) {
|
||||
this.accessTokenValiditySeconds = accessTokenValiditySeconds;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Basic
|
||||
|
@ -463,60 +464,61 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param refreshTokenTimeout Lifetime of refresh tokens, in seconds (optional - leave null for no timeout)
|
||||
*/
|
||||
public void setRefreshTokenValiditySeconds(Integer refreshTokenValiditySeconds) {
|
||||
this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
|
||||
}
|
||||
* @param refreshTokenTimeout Lifetime of refresh tokens, in seconds (optional - leave null for no timeout)
|
||||
*/
|
||||
public void setRefreshTokenValiditySeconds(Integer refreshTokenValiditySeconds) {
|
||||
this.refreshTokenValiditySeconds = refreshTokenValiditySeconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the registeredRedirectUri
|
||||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
/**
|
||||
* @return the registeredRedirectUri
|
||||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="client_redirect_uri",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
@Column(name="redirect_uri")
|
||||
public Set<String> getRedirectUris() {
|
||||
return redirectUris;
|
||||
}
|
||||
)
|
||||
@Column(name="redirect_uri")
|
||||
public Set<String> getRedirectUris() {
|
||||
return redirectUris;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param registeredRedirectUri the registeredRedirectUri to set
|
||||
*/
|
||||
public void setRedirectUris(Set<String> redirectUris) {
|
||||
this.redirectUris = redirectUris;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pass-through method to fulfill the ClientDetails interface with a bad name
|
||||
*/
|
||||
@Override
|
||||
@Transient
|
||||
public Set<String> getRegisteredRedirectUri() {
|
||||
return getRedirectUris();
|
||||
}
|
||||
* @param registeredRedirectUri the registeredRedirectUri to set
|
||||
*/
|
||||
public void setRedirectUris(Set<String> redirectUris) {
|
||||
this.redirectUris = redirectUris;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resourceIds
|
||||
*/
|
||||
* Pass-through method to fulfill the ClientDetails interface with a bad name
|
||||
*/
|
||||
@Override
|
||||
@Transient
|
||||
public Set<String> getRegisteredRedirectUri() {
|
||||
return getRedirectUris();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the resourceIds
|
||||
*/
|
||||
@Override
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="client_resource",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
)
|
||||
@Column(name="resource_id")
|
||||
public Set<String> getResourceIds() {
|
||||
return resourceIds;
|
||||
}
|
||||
public Set<String> getResourceIds() {
|
||||
return resourceIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resourceIds the resourceIds to set
|
||||
*/
|
||||
public void setResourceIds(Set<String> resourceIds) {
|
||||
this.resourceIds = resourceIds;
|
||||
}
|
||||
* @param resourceIds the resourceIds to set
|
||||
*/
|
||||
public void setResourceIds(Set<String> resourceIds) {
|
||||
this.resourceIds = resourceIds;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -580,7 +582,7 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
@CollectionTable(
|
||||
name="client_contact",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
)
|
||||
@Column(name="contact")
|
||||
public Set<String> getContacts() {
|
||||
return contacts;
|
||||
|
@ -611,36 +613,36 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the clientUrl
|
||||
*/
|
||||
* @return the clientUrl
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="client_uri")
|
||||
public String getClientUri() {
|
||||
return clientUri;
|
||||
}
|
||||
public String getClientUri() {
|
||||
return clientUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientUrl the clientUrl to set
|
||||
*/
|
||||
public void setClientUri(String clientUri) {
|
||||
this.clientUri = clientUri;
|
||||
}
|
||||
* @param clientUrl the clientUrl to set
|
||||
*/
|
||||
public void setClientUri(String clientUri) {
|
||||
this.clientUri = clientUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tosUrl
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="tos_uri")
|
||||
public String getTosUri() {
|
||||
return tosUri;
|
||||
}
|
||||
* @return the tosUrl
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="tos_uri")
|
||||
public String getTosUri() {
|
||||
return tosUri;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param tosUrl the tosUrl to set
|
||||
*/
|
||||
public void setTosUri(String tosUri) {
|
||||
this.tosUri = tosUri;
|
||||
}
|
||||
* @param tosUrl the tosUrl to set
|
||||
*/
|
||||
public void setTosUri(String tosUri) {
|
||||
this.tosUri = tosUri;
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name="jwks_uri")
|
||||
|
@ -773,7 +775,7 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
@CollectionTable(
|
||||
name="client_response_type",
|
||||
joinColumns=@JoinColumn(name="response_type")
|
||||
)
|
||||
)
|
||||
@Column(name="response_type")
|
||||
public Set<String> getResponseTypes() {
|
||||
return responseTypes;
|
||||
|
@ -793,7 +795,7 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
@CollectionTable(
|
||||
name="client_default_acr_value",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
)
|
||||
@Column(name="default_acr_value")
|
||||
public Set<String> getDefaultACRvalues() {
|
||||
return defaultACRvalues;
|
||||
|
@ -845,7 +847,7 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
@CollectionTable(
|
||||
name="client_request_uri",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
)
|
||||
@Column(name="request_uri")
|
||||
public Set<String> getRequestUris() {
|
||||
return requestUris;
|
||||
|
@ -863,15 +865,15 @@ public class ClientDetailsEntity implements ClientDetails {
|
|||
*/
|
||||
@Temporal(TemporalType.TIMESTAMP)
|
||||
@Column(name="created_at")
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
public Date getCreatedAt() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param createdAt the createdAt to set
|
||||
*/
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
public void setCreatedAt(Date createdAt) {
|
||||
this.createdAt = createdAt;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -116,6 +116,7 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
|
|||
/**
|
||||
* Get all additional information to be sent to the serializer. Inserts a copy of the IdToken (in JWT String form).
|
||||
*/
|
||||
@Override
|
||||
@Transient
|
||||
public Map<String, Object> getAdditionalInformation() {
|
||||
Map<String, Object> map = new HashMap<String, Object>(); //super.getAdditionalInformation();
|
||||
|
@ -127,109 +128,115 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
|
|||
|
||||
/**
|
||||
* The authentication in place when this token was created.
|
||||
* @return the authentication
|
||||
*/
|
||||
* @return the authentication
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "auth_holder_id")
|
||||
public AuthenticationHolderEntity getAuthenticationHolder() {
|
||||
return authenticationHolder;
|
||||
}
|
||||
public AuthenticationHolderEntity getAuthenticationHolder() {
|
||||
return authenticationHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authentication the authentication to set
|
||||
*/
|
||||
public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
|
||||
this.authenticationHolder = authenticationHolder;
|
||||
}
|
||||
* @param authentication the authentication to set
|
||||
*/
|
||||
public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
|
||||
this.authenticationHolder = authenticationHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the client
|
||||
*/
|
||||
* @return the client
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "client_id")
|
||||
public ClientDetailsEntity getClient() {
|
||||
return client;
|
||||
}
|
||||
public ClientDetailsEntity getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param client the client to set
|
||||
*/
|
||||
public void setClient(ClientDetailsEntity client) {
|
||||
this.client = client;
|
||||
}
|
||||
* @param client the client to set
|
||||
*/
|
||||
public void setClient(ClientDetailsEntity client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string-encoded value of this access token.
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="token_value")
|
||||
public String getValue() {
|
||||
/**
|
||||
* Get the string-encoded value of this access token.
|
||||
*/
|
||||
@Override
|
||||
@Basic
|
||||
@Column(name="token_value")
|
||||
public String getValue() {
|
||||
return jwtValue.serialize();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "value" of this Access Token
|
||||
*
|
||||
* @param value the JWT string
|
||||
* @throws ParseException if "value" is not a properly formatted JWT string
|
||||
*/
|
||||
public void setValue(String value) throws ParseException {
|
||||
/**
|
||||
* Set the "value" of this Access Token
|
||||
*
|
||||
* @param value the JWT string
|
||||
* @throws ParseException if "value" is not a properly formatted JWT string
|
||||
*/
|
||||
public void setValue(String value) throws ParseException {
|
||||
setJwt(JWTParser.parse(value));
|
||||
}
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
public Date getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
@Override
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
public Date getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
|
||||
public void setExpiration(Date expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
public void setExpiration(Date expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name="token_type")
|
||||
public String getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
@Override
|
||||
@Basic
|
||||
@Column(name="token_type")
|
||||
public String getTokenType() {
|
||||
return tokenType;
|
||||
}
|
||||
|
||||
public void setTokenType(String tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
public void setTokenType(String tokenType) {
|
||||
this.tokenType = tokenType;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="refresh_token_id")
|
||||
public OAuth2RefreshTokenEntity getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
@Override
|
||||
@ManyToOne
|
||||
@JoinColumn(name="refresh_token_id")
|
||||
public OAuth2RefreshTokenEntity getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
|
||||
public void setRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
public void setRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
this.refreshToken = refreshToken;
|
||||
}
|
||||
|
||||
public void setRefreshToken(OAuth2RefreshToken refreshToken) {
|
||||
if (!(refreshToken instanceof OAuth2RefreshTokenEntity)) {
|
||||
// TODO: make a copy constructor instead....
|
||||
throw new IllegalArgumentException("Not a storable refresh token entity!");
|
||||
}
|
||||
// force a pass through to the entity version
|
||||
setRefreshToken((OAuth2RefreshTokenEntity)refreshToken);
|
||||
}
|
||||
public void setRefreshToken(OAuth2RefreshToken refreshToken) {
|
||||
if (!(refreshToken instanceof OAuth2RefreshTokenEntity)) {
|
||||
// TODO: make a copy constructor instead....
|
||||
throw new IllegalArgumentException("Not a storable refresh token entity!");
|
||||
}
|
||||
// force a pass through to the entity version
|
||||
setRefreshToken((OAuth2RefreshTokenEntity)refreshToken);
|
||||
}
|
||||
|
||||
@ElementCollection(fetch=FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
joinColumns=@JoinColumn(name="owner_id"),
|
||||
name="token_scope"
|
||||
)
|
||||
public Set<String> getScope() {
|
||||
return scope;
|
||||
}
|
||||
@Override
|
||||
@ElementCollection(fetch=FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
joinColumns=@JoinColumn(name="owner_id"),
|
||||
name="token_scope"
|
||||
)
|
||||
public Set<String> getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
public void setScope(Set<String> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
public void setScope(Set<String> scope) {
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
@Transient
|
||||
@Override
|
||||
@Transient
|
||||
public boolean isExpired() {
|
||||
return getExpiration() == null ? false : System.currentTimeMillis() > getExpiration().getTime();
|
||||
}
|
||||
|
@ -237,8 +244,8 @@ public class OAuth2AccessTokenEntity implements OAuth2AccessToken {
|
|||
/**
|
||||
* @return the idToken
|
||||
*/
|
||||
@OneToOne(cascade=CascadeType.ALL) // one-to-one mapping for now
|
||||
@JoinColumn(name = "id_token_id")
|
||||
@OneToOne(cascade=CascadeType.ALL) // one-to-one mapping for now
|
||||
@JoinColumn(name = "id_token_id")
|
||||
public OAuth2AccessTokenEntity getIdToken() {
|
||||
return idToken;
|
||||
}
|
||||
|
|
|
@ -39,9 +39,7 @@ import javax.persistence.Transient;
|
|||
import org.springframework.security.oauth2.common.OAuth2RefreshToken;
|
||||
|
||||
import com.nimbusds.jwt.JWT;
|
||||
import com.nimbusds.jwt.JWTClaimsSet;
|
||||
import com.nimbusds.jwt.JWTParser;
|
||||
import com.nimbusds.jwt.PlainJWT;
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
|
@ -96,92 +94,93 @@ public class OAuth2RefreshTokenEntity implements OAuth2RefreshToken {
|
|||
* The authentication in place when the original access token was
|
||||
* created
|
||||
*
|
||||
* @return the authentication
|
||||
*/
|
||||
* @return the authentication
|
||||
*/
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "auth_holder_id")
|
||||
public AuthenticationHolderEntity getAuthenticationHolder() {
|
||||
return authenticationHolder;
|
||||
}
|
||||
public AuthenticationHolderEntity getAuthenticationHolder() {
|
||||
return authenticationHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param authentication the authentication to set
|
||||
*/
|
||||
public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
|
||||
this.authenticationHolder = authenticationHolder;
|
||||
}
|
||||
* @param authentication the authentication to set
|
||||
*/
|
||||
public void setAuthenticationHolder(AuthenticationHolderEntity authenticationHolder) {
|
||||
this.authenticationHolder = authenticationHolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JWT-encoded value of this token
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="token_value")
|
||||
public String getValue() {
|
||||
return jwt.serialize();
|
||||
}
|
||||
@Override
|
||||
@Basic
|
||||
@Column(name="token_value")
|
||||
public String getValue() {
|
||||
return jwt.serialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of this token as a string. Parses the string into a JWT.
|
||||
* @param value
|
||||
* @throws ParseException if the value is not a valid JWT string
|
||||
*/
|
||||
public void setValue(String value) throws ParseException {
|
||||
setJwt(JWTParser.parse(value));
|
||||
}
|
||||
/**
|
||||
* Set the value of this token as a string. Parses the string into a JWT.
|
||||
* @param value
|
||||
* @throws ParseException if the value is not a valid JWT string
|
||||
*/
|
||||
public void setValue(String value) throws ParseException {
|
||||
setJwt(JWTParser.parse(value));
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
public Date getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
public Date getExpiration() {
|
||||
return expiration;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken#setExpiration(java.util.Date)
|
||||
*/
|
||||
* @see org.springframework.security.oauth2.common.ExpiringOAuth2RefreshToken#setExpiration(java.util.Date)
|
||||
*/
|
||||
|
||||
public void setExpiration(Date expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
public void setExpiration(Date expiration) {
|
||||
this.expiration = expiration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Has this token expired?
|
||||
* @return true if it has a timeout set and the timeout has passed
|
||||
*/
|
||||
@Transient
|
||||
/**
|
||||
* Has this token expired?
|
||||
* @return true if it has a timeout set and the timeout has passed
|
||||
*/
|
||||
@Transient
|
||||
public boolean isExpired() {
|
||||
return getExpiration() == null ? false : System.currentTimeMillis() > getExpiration().getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the client
|
||||
*/
|
||||
* @return the client
|
||||
*/
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "client_id")
|
||||
public ClientDetailsEntity getClient() {
|
||||
return client;
|
||||
}
|
||||
public ClientDetailsEntity getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param client the client to set
|
||||
*/
|
||||
public void setClient(ClientDetailsEntity client) {
|
||||
this.client = client;
|
||||
}
|
||||
* @param client the client to set
|
||||
*/
|
||||
public void setClient(ClientDetailsEntity client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the JWT object directly
|
||||
* @return the jwt
|
||||
*/
|
||||
@Transient
|
||||
public JWT getJwt() {
|
||||
return jwt;
|
||||
}
|
||||
/**
|
||||
* Get the JWT object directly
|
||||
* @return the jwt
|
||||
*/
|
||||
@Transient
|
||||
public JWT getJwt() {
|
||||
return jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jwt the jwt to set
|
||||
*/
|
||||
public void setJwt(JWT jwt) {
|
||||
this.jwt = jwt;
|
||||
}
|
||||
/**
|
||||
* @param jwt the jwt to set
|
||||
*/
|
||||
public void setJwt(JWT jwt) {
|
||||
this.jwt = jwt;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -43,9 +43,9 @@ public class SystemScope {
|
|||
* Make a system scope with the given scope value
|
||||
* @param value
|
||||
*/
|
||||
public SystemScope(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
public SystemScope(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
|
@ -136,70 +136,70 @@ public class SystemScope {
|
|||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (allowDynReg ? 1231 : 1237);
|
||||
result = prime * result + (defaultScope ? 1231 : 1237);
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((icon == null) ? 0 : icon.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (allowDynReg ? 1231 : 1237);
|
||||
result = prime * result + (defaultScope ? 1231 : 1237);
|
||||
result = prime * result + ((description == null) ? 0 : description.hashCode());
|
||||
result = prime * result + ((icon == null) ? 0 : icon.hashCode());
|
||||
result = prime * result + ((id == null) ? 0 : id.hashCode());
|
||||
result = prime * result + ((value == null) ? 0 : value.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#equals(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SystemScope other = (SystemScope) obj;
|
||||
if (allowDynReg != other.allowDynReg) {
|
||||
return false;
|
||||
}
|
||||
if (defaultScope != other.defaultScope) {
|
||||
return false;
|
||||
}
|
||||
if (description == null) {
|
||||
if (other.description != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!description.equals(other.description)) {
|
||||
return false;
|
||||
}
|
||||
if (icon == null) {
|
||||
if (other.icon != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!icon.equals(other.icon)) {
|
||||
return false;
|
||||
}
|
||||
if (id == null) {
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
if (value == null) {
|
||||
if (other.value != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!value.equals(other.value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass()) {
|
||||
return false;
|
||||
}
|
||||
SystemScope other = (SystemScope) obj;
|
||||
if (allowDynReg != other.allowDynReg) {
|
||||
return false;
|
||||
}
|
||||
if (defaultScope != other.defaultScope) {
|
||||
return false;
|
||||
}
|
||||
if (description == null) {
|
||||
if (other.description != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!description.equals(other.description)) {
|
||||
return false;
|
||||
}
|
||||
if (icon == null) {
|
||||
if (other.icon != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!icon.equals(other.icon)) {
|
||||
return false;
|
||||
}
|
||||
if (id == null) {
|
||||
if (other.id != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!id.equals(other.id)) {
|
||||
return false;
|
||||
}
|
||||
if (value == null) {
|
||||
if (other.value != null) {
|
||||
return false;
|
||||
}
|
||||
} else if (!value.equals(other.value)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -55,8 +55,8 @@ public interface OAuth2TokenRepository {
|
|||
public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth);
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken);
|
||||
* @return
|
||||
*/
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken);
|
||||
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ public interface ClientDetailsEntityService extends ClientDetailsService {
|
|||
|
||||
public ClientDetailsEntity getClientById(Long id);
|
||||
|
||||
@Override
|
||||
public ClientDetailsEntity loadClientByClientId(String clientId) throws OAuth2Exception;
|
||||
|
||||
public void deleteClient(ClientDetailsEntity client);
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.springframework.security.oauth2.provider.token.ResourceServerTokenSer
|
|||
|
||||
public interface OAuth2TokenEntityService extends AuthorizationServerTokenServices, ResourceServerTokenServices {
|
||||
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity readAccessToken(String accessTokenValue);
|
||||
|
||||
public OAuth2RefreshTokenEntity getRefreshToken(String refreshTokenValue);
|
||||
|
@ -44,14 +45,15 @@ public interface OAuth2TokenEntityService extends AuthorizationServerTokenServic
|
|||
|
||||
public OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken);
|
||||
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getAccessToken(OAuth2Authentication authentication);
|
||||
|
||||
public OAuth2AccessTokenEntity getAccessTokenById(Long id);
|
||||
|
||||
/**
|
||||
* @param incomingToken
|
||||
* @return
|
||||
*/
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken);
|
||||
* @param incomingToken
|
||||
* @return
|
||||
*/
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken);
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.mitre.oauth2.service.impl;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
|
@ -44,32 +43,32 @@ public class DefaultClientUserDetailsService implements UserDetailsService {
|
|||
private ClientDetailsService clientDetailsService;
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException, DataAccessException {
|
||||
public UserDetails loadUserByUsername(String clientId) throws UsernameNotFoundException, DataAccessException {
|
||||
|
||||
ClientDetails client = clientDetailsService.loadClientByClientId(clientId);
|
||||
|
||||
if (client != null) {
|
||||
|
||||
String password = client.getClientSecret();
|
||||
boolean enabled = true;
|
||||
boolean accountNonExpired = true;
|
||||
boolean credentialsNonExpired = true;
|
||||
boolean accountNonLocked = true;
|
||||
Collection<GrantedAuthority> authorities = client.getAuthorities();
|
||||
if (authorities == null || authorities.isEmpty()) {
|
||||
// automatically inject ROLE_CLIENT if none exists ...
|
||||
// TODO: this should probably happen on the client service side instead to keep it in the real data model
|
||||
authorities = new ArrayList<GrantedAuthority>();
|
||||
GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_CLIENT");
|
||||
authorities.add(roleClient);
|
||||
}
|
||||
String password = client.getClientSecret();
|
||||
boolean enabled = true;
|
||||
boolean accountNonExpired = true;
|
||||
boolean credentialsNonExpired = true;
|
||||
boolean accountNonLocked = true;
|
||||
Collection<GrantedAuthority> authorities = client.getAuthorities();
|
||||
if (authorities == null || authorities.isEmpty()) {
|
||||
// automatically inject ROLE_CLIENT if none exists ...
|
||||
// TODO: this should probably happen on the client service side instead to keep it in the real data model
|
||||
authorities = new ArrayList<GrantedAuthority>();
|
||||
GrantedAuthority roleClient = new SimpleGrantedAuthority("ROLE_CLIENT");
|
||||
authorities.add(roleClient);
|
||||
}
|
||||
|
||||
return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
|
||||
return new User(clientId, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked, authorities);
|
||||
} else {
|
||||
throw new UsernameNotFoundException("Client not found: " + clientId);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public ClientDetailsService getClientDetailsService() {
|
||||
return clientDetailsService;
|
||||
|
|
|
@ -125,19 +125,19 @@ public class Address {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ import com.google.common.collect.Sets;
|
|||
public class ApprovedSite {
|
||||
|
||||
// unique id
|
||||
private Long id;
|
||||
private Long id;
|
||||
|
||||
// which user made the approval
|
||||
// which user made the approval
|
||||
private String userId;
|
||||
|
||||
// which OAuth2 client is this tied to
|
||||
|
@ -84,132 +84,132 @@ public class ApprovedSite {
|
|||
*/
|
||||
public ApprovedSite() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userInfo
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="user_id")
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
* @return the userInfo
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="user_id")
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userInfo the userInfo to set
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
* @param userInfo the userInfo to set
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clientId
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="client_id")
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
* @return the clientId
|
||||
*/
|
||||
@Basic
|
||||
@Column(name="client_id")
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientId the clientId to set
|
||||
*/
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
* @param clientId the clientId to set
|
||||
*/
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the creationDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="creation_date")
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
* @return the creationDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="creation_date")
|
||||
public Date getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param creationDate the creationDate to set
|
||||
*/
|
||||
public void setCreationDate(Date creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
* @param creationDate the creationDate to set
|
||||
*/
|
||||
public void setCreationDate(Date creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the accessDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="access_date")
|
||||
public Date getAccessDate() {
|
||||
return accessDate;
|
||||
}
|
||||
* @return the accessDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="access_date")
|
||||
public Date getAccessDate() {
|
||||
return accessDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param accessDate the accessDate to set
|
||||
*/
|
||||
public void setAccessDate(Date accessDate) {
|
||||
this.accessDate = accessDate;
|
||||
}
|
||||
* @param accessDate the accessDate to set
|
||||
*/
|
||||
public void setAccessDate(Date accessDate) {
|
||||
this.accessDate = accessDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the allowedScopes
|
||||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="approved_site_scope",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
@Column(name="scope")
|
||||
public Set<String> getAllowedScopes() {
|
||||
return allowedScopes;
|
||||
}
|
||||
* @return the allowedScopes
|
||||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="approved_site_scope",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
@Column(name="scope")
|
||||
public Set<String> getAllowedScopes() {
|
||||
return allowedScopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param allowedScopes the allowedScopes to set
|
||||
*/
|
||||
public void setAllowedScopes(Set<String> allowedScopes) {
|
||||
this.allowedScopes = allowedScopes;
|
||||
}
|
||||
* @param allowedScopes the allowedScopes to set
|
||||
*/
|
||||
public void setAllowedScopes(Set<String> allowedScopes) {
|
||||
this.allowedScopes = allowedScopes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timeoutDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="timeout_date")
|
||||
public Date getTimeoutDate() {
|
||||
return timeoutDate;
|
||||
}
|
||||
* @return the timeoutDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="timeout_date")
|
||||
public Date getTimeoutDate() {
|
||||
return timeoutDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timeoutDate the timeoutDate to set
|
||||
*/
|
||||
public void setTimeoutDate(Date timeoutDate) {
|
||||
this.timeoutDate = timeoutDate;
|
||||
}
|
||||
* @param timeoutDate the timeoutDate to set
|
||||
*/
|
||||
public void setTimeoutDate(Date timeoutDate) {
|
||||
this.timeoutDate = timeoutDate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this AP entry correspond to a WS?
|
||||
* @return
|
||||
*/
|
||||
@Transient
|
||||
/**
|
||||
* Does this AP entry correspond to a WS?
|
||||
* @return
|
||||
*/
|
||||
@Transient
|
||||
public Boolean getIsWhitelisted() {
|
||||
return (whitelistedSite != null);
|
||||
}
|
||||
|
@ -227,10 +227,10 @@ public class ApprovedSite {
|
|||
|
||||
/**
|
||||
* Has this approval expired?
|
||||
* @return
|
||||
*/
|
||||
* @return
|
||||
*/
|
||||
@Transient
|
||||
public boolean isExpired() {
|
||||
public boolean isExpired() {
|
||||
if (getTimeoutDate() != null) {
|
||||
Date now = new Date();
|
||||
if (now.after(getTimeoutDate())) {
|
||||
|
@ -241,7 +241,7 @@ public class ApprovedSite {
|
|||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
|
||||
@JoinColumn(name="approved_site_id")
|
||||
|
|
|
@ -24,41 +24,41 @@ import javax.persistence.Table;
|
|||
})
|
||||
public class BlacklistedSite {
|
||||
|
||||
// unique id
|
||||
private Long id;
|
||||
// unique id
|
||||
private Long id;
|
||||
|
||||
// URI pattern to black list
|
||||
private String uri;
|
||||
// URI pattern to black list
|
||||
private String uri;
|
||||
|
||||
public BlacklistedSite() {
|
||||
public BlacklistedSite() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Basic
|
||||
@Column(name="uri")
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
@Basic
|
||||
@Column(name="uri")
|
||||
public String getUri() {
|
||||
return uri;
|
||||
}
|
||||
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
public void setUri(String uri) {
|
||||
this.uri = uri;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -356,21 +356,23 @@ public class DefaultUserInfo implements UserInfo {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the birthdate
|
||||
*/
|
||||
* @return the birthdate
|
||||
*/
|
||||
@Override
|
||||
@Basic
|
||||
@Column(name="birthdate")
|
||||
public String getBirthdate() {
|
||||
return birthdate;
|
||||
}
|
||||
public String getBirthdate() {
|
||||
return birthdate;
|
||||
}
|
||||
/**
|
||||
* @param birthdate the birthdate to set
|
||||
*/
|
||||
public void setBirthdate(String birthdate) {
|
||||
this.birthdate = birthdate;
|
||||
}
|
||||
* @param birthdate the birthdate to set
|
||||
*/
|
||||
@Override
|
||||
public void setBirthdate(String birthdate) {
|
||||
this.birthdate = birthdate;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Parse a JsonObject into a UserInfo.
|
||||
* @param o
|
||||
* @return
|
||||
|
|
|
@ -43,44 +43,44 @@ public class Event {
|
|||
private Date timestamp;
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy=GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public EventType getType() {
|
||||
return type;
|
||||
}
|
||||
* @return the type
|
||||
*/
|
||||
public EventType getType() {
|
||||
return type;
|
||||
}
|
||||
/**
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(EventType type) {
|
||||
this.type = type;
|
||||
}
|
||||
* @param type the type to set
|
||||
*/
|
||||
public void setType(EventType type) {
|
||||
this.type = type;
|
||||
}
|
||||
/**
|
||||
* @return the timestamp
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
* @return the timestamp
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
public Date getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
/**
|
||||
* @param timestamp the timestamp to set
|
||||
*/
|
||||
public void setTimestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
* @param timestamp the timestamp to set
|
||||
*/
|
||||
public void setTimestamp(Date timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ public class Nonce {
|
|||
* @return the useDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="use_date")
|
||||
public Date getUseDate() {
|
||||
return useDate;
|
||||
|
@ -103,7 +103,7 @@ public class Nonce {
|
|||
* @return the expireDate
|
||||
*/
|
||||
@Basic
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Temporal(javax.persistence.TemporalType.TIMESTAMP)
|
||||
@Column(name="expire_date")
|
||||
public Date getExpireDate() {
|
||||
return expireDate;
|
||||
|
|
|
@ -47,9 +47,9 @@ import javax.persistence.Table;
|
|||
public class WhitelistedSite {
|
||||
|
||||
// unique id
|
||||
private Long id;
|
||||
private Long id;
|
||||
|
||||
// Reference to the admin user who created this entry
|
||||
// Reference to the admin user who created this entry
|
||||
private String creatorUserId;
|
||||
|
||||
// which OAuth2 client is this tied to
|
||||
|
@ -70,7 +70,7 @@ public class WhitelistedSite {
|
|||
* @return the id
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
@ -103,9 +103,9 @@ public class WhitelistedSite {
|
|||
*/
|
||||
@ElementCollection(fetch = FetchType.EAGER)
|
||||
@CollectionTable(
|
||||
name="whitelisted_site_scope",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
name="whitelisted_site_scope",
|
||||
joinColumns=@JoinColumn(name="owner_id")
|
||||
)
|
||||
@Column(name="scope")
|
||||
public Set<String> getAllowedScopes() {
|
||||
return allowedScopes;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.mitre.openid.connect.repository;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.mitre.openid.connect.model.Nonce;
|
||||
|
||||
/**
|
||||
|
|
|
@ -77,10 +77,10 @@ public interface WhitelistedSiteRepository {
|
|||
|
||||
/**
|
||||
* Persist changes to a whitelistedSite. The ID of oldWhitelistedSite is retained.
|
||||
* @param oldWhitelistedSite
|
||||
* @param whitelistedSite
|
||||
* @return
|
||||
*/
|
||||
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite);
|
||||
* @param oldWhitelistedSite
|
||||
* @param whitelistedSite
|
||||
* @return
|
||||
*/
|
||||
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite);
|
||||
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@ public interface StatsService {
|
|||
/**
|
||||
* Calculate summary statistics
|
||||
* approvalCount: total approved sites
|
||||
* userCount: unique users
|
||||
* clientCount: unique clients
|
||||
*
|
||||
* userCount: unique users
|
||||
* clientCount: unique clients
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Integer> calculateSummaryStats();
|
||||
|
|
|
@ -27,26 +27,26 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
|||
* Time: 2:13 PM
|
||||
*/
|
||||
public class JpaUtil {
|
||||
public static <T> T getSingleResult(List<T> list) {
|
||||
switch(list.size()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return list.get(0);
|
||||
default:
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
}
|
||||
public static <T> T getSingleResult(List<T> list) {
|
||||
switch(list.size()) {
|
||||
case 0:
|
||||
return null;
|
||||
case 1:
|
||||
return list.get(0);
|
||||
default:
|
||||
throw new IncorrectResultSizeDataAccessException(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T, I> T saveOrUpdate(I id, EntityManager entityManager, T entity) {
|
||||
if (id == null) {
|
||||
entityManager.persist(entity);
|
||||
entityManager.flush();
|
||||
return entity;
|
||||
} else {
|
||||
T tmp = entityManager.merge(entity);
|
||||
entityManager.flush();
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
public static <T, I> T saveOrUpdate(I id, EntityManager entityManager, T entity) {
|
||||
if (id == null) {
|
||||
entityManager.persist(entity);
|
||||
entityManager.flush();
|
||||
return entity;
|
||||
} else {
|
||||
T tmp = entityManager.merge(entity);
|
||||
entityManager.flush();
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,13 @@ package org.mitre.oauth2.exception;
|
|||
public class DuplicateClientIdException extends RuntimeException {
|
||||
|
||||
public DuplicateClientIdException(String clientId) {
|
||||
super("Duplicate client id: " + clientId);
|
||||
}
|
||||
super("Duplicate client id: " + clientId);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
|
|||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientDetailsEntity getById(Long id) {
|
||||
return manager.find(ClientDetailsEntity.class, id);
|
||||
}
|
||||
|
@ -82,17 +83,17 @@ public class JpaOAuth2ClientRepository implements OAuth2ClientRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ClientDetailsEntity updateClient(Long id, ClientDetailsEntity client) {
|
||||
public ClientDetailsEntity updateClient(Long id, ClientDetailsEntity client) {
|
||||
// sanity check
|
||||
client.setId(id);
|
||||
|
||||
return JpaUtil.saveOrUpdate(id, manager, client);
|
||||
}
|
||||
return JpaUtil.saveOrUpdate(id, manager, client);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ClientDetailsEntity> getAllClients() {
|
||||
public Collection<ClientDetailsEntity> getAllClients() {
|
||||
TypedQuery<ClientDetailsEntity> query = manager.createNamedQuery("ClientDetailsEntity.findAll", ClientDetailsEntity.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,14 +67,14 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
public void clearAccessTokensForRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
public void clearAccessTokensForRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
TypedQuery<OAuth2AccessTokenEntity> query = manager.createNamedQuery("OAuth2AccessTokenEntity.getByRefreshToken", OAuth2AccessTokenEntity.class);
|
||||
query.setParameter("refreshToken", refreshToken);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = query.getResultList();
|
||||
for (OAuth2AccessTokenEntity accessToken : accessTokens) {
|
||||
removeAccessToken(accessToken);
|
||||
}
|
||||
}
|
||||
List<OAuth2AccessTokenEntity> accessTokens = query.getResultList();
|
||||
for (OAuth2AccessTokenEntity accessToken : accessTokens) {
|
||||
removeAccessToken(accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2RefreshTokenEntity getRefreshTokenByValue(String refreshTokenValue) {
|
||||
|
@ -96,91 +96,91 @@ public class JpaOAuth2TokenRepository implements OAuth2TokenRepository {
|
|||
|
||||
@Override
|
||||
@Transactional
|
||||
public void removeRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
public void removeRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
OAuth2RefreshTokenEntity found = getRefreshTokenByValue(refreshToken.getValue());
|
||||
if (found != null) {
|
||||
manager.remove(found);
|
||||
} else {
|
||||
throw new IllegalArgumentException("Refresh token not found: " + refreshToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void clearTokensForClient(ClientDetailsEntity client) {
|
||||
public void clearTokensForClient(ClientDetailsEntity client) {
|
||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByClient", OAuth2AccessTokenEntity.class);
|
||||
queryA.setParameter("client", client);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
for (OAuth2AccessTokenEntity accessToken : accessTokens) {
|
||||
removeAccessToken(accessToken);
|
||||
}
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
for (OAuth2AccessTokenEntity accessToken : accessTokens) {
|
||||
removeAccessToken(accessToken);
|
||||
}
|
||||
TypedQuery<OAuth2RefreshTokenEntity> queryR = manager.createNamedQuery("OAuth2RefreshTokenEntity.getByClient", OAuth2RefreshTokenEntity.class);
|
||||
queryR.setParameter("client", client);
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
|
||||
for (OAuth2RefreshTokenEntity refreshToken : refreshTokens) {
|
||||
removeRefreshToken(refreshToken);
|
||||
}
|
||||
}
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
|
||||
for (OAuth2RefreshTokenEntity refreshToken : refreshTokens) {
|
||||
removeRefreshToken(refreshToken);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getAccessTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2AccessTokenEntity> getAccessTokensForClient(ClientDetailsEntity client) {
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getAccessTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2AccessTokenEntity> getAccessTokensForClient(ClientDetailsEntity client) {
|
||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByClient", OAuth2AccessTokenEntity.class);
|
||||
queryA.setParameter("client", client);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return accessTokens;
|
||||
}
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return accessTokens;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getRefreshTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client) {
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getRefreshTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client) {
|
||||
TypedQuery<OAuth2RefreshTokenEntity> queryR = manager.createNamedQuery("OAuth2RefreshTokenEntity.getByClient", OAuth2RefreshTokenEntity.class);
|
||||
queryR.setParameter("client", client);
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
|
||||
return refreshTokens;
|
||||
}
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
|
||||
return refreshTokens;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getExpiredAccessTokens()
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2AccessTokenEntity> getExpiredAccessTokens() {
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getExpiredAccessTokens()
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2AccessTokenEntity> getExpiredAccessTokens() {
|
||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getExpired", OAuth2AccessTokenEntity.class);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return accessTokens;
|
||||
}
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return accessTokens;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getExpiredRefreshTokens()
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2RefreshTokenEntity> getExpiredRefreshTokens() {
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getExpiredRefreshTokens()
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2RefreshTokenEntity> getExpiredRefreshTokens() {
|
||||
TypedQuery<OAuth2RefreshTokenEntity> queryR = manager.createNamedQuery("OAuth2RefreshTokenEntity.getExpired", OAuth2RefreshTokenEntity.class);
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
|
||||
return refreshTokens;
|
||||
}
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = queryR.getResultList();
|
||||
return refreshTokens;
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth) {
|
||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByAuthentication", OAuth2AccessTokenEntity.class);
|
||||
queryA.setParameter("authentication", auth);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return JpaUtil.getSingleResult(accessTokens);
|
||||
}
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getByAuthentication(OAuth2Authentication auth) {
|
||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByAuthentication", OAuth2AccessTokenEntity.class);
|
||||
queryA.setParameter("authentication", auth);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return JpaUtil.getSingleResult(accessTokens);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getAccessTokenForIdToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken) {
|
||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByIdToken", OAuth2AccessTokenEntity.class);
|
||||
queryA.setParameter("idToken", idToken);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return JpaUtil.getSingleResult(accessTokens);
|
||||
}
|
||||
* @see org.mitre.oauth2.repository.OAuth2TokenRepository#getAccessTokenForIdToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken) {
|
||||
TypedQuery<OAuth2AccessTokenEntity> queryA = manager.createNamedQuery("OAuth2AccessTokenEntity.getByIdToken", OAuth2AccessTokenEntity.class);
|
||||
queryA.setParameter("idToken", idToken);
|
||||
List<OAuth2AccessTokenEntity> accessTokens = queryA.getResultList();
|
||||
return JpaUtil.getSingleResult(accessTokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@
|
|||
*/
|
||||
package org.mitre.oauth2.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.getSingleResult;
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -15,9 +18,6 @@ import org.mitre.oauth2.repository.SystemScopeRepository;
|
|||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.getSingleResult;
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
/**
|
||||
* @author jricher
|
||||
*
|
||||
|
|
|
@ -76,31 +76,32 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
if (blacklistedSiteService.isBlacklisted(uri)) {
|
||||
throw new IllegalArgumentException("Client URI is blacklisted: " + uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// assign a random clientid if it's empty
|
||||
// NOTE: don't assign a random client secret without asking, since public clients have no secret
|
||||
if (Strings.isNullOrEmpty(client.getClientId())) {
|
||||
client = generateClientId(client);
|
||||
}
|
||||
if (Strings.isNullOrEmpty(client.getClientId())) {
|
||||
client = generateClientId(client);
|
||||
}
|
||||
|
||||
// if the client is flagged to allow for refresh tokens, make sure it's got the right granted scopes
|
||||
if (client.isAllowRefresh()) {
|
||||
client.getScope().add("offline_access");
|
||||
} else {
|
||||
client.getScope().remove("offline_access");
|
||||
}
|
||||
// if the client is flagged to allow for refresh tokens, make sure it's got the right granted scopes
|
||||
if (client.isAllowRefresh()) {
|
||||
client.getScope().add("offline_access");
|
||||
} else {
|
||||
client.getScope().remove("offline_access");
|
||||
}
|
||||
|
||||
// timestamp this to right now
|
||||
client.setCreatedAt(new Date());
|
||||
// timestamp this to right now
|
||||
client.setCreatedAt(new Date());
|
||||
|
||||
return clientRepository.saveClient(client);
|
||||
return clientRepository.saveClient(client);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the client by its internal ID
|
||||
*/
|
||||
@Override
|
||||
public ClientDetailsEntity getClientById(Long id) {
|
||||
ClientDetailsEntity client = clientRepository.getById(id);
|
||||
|
||||
|
@ -129,7 +130,7 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
* Delete a client and all its associated tokens
|
||||
*/
|
||||
@Override
|
||||
public void deleteClient(ClientDetailsEntity client) throws InvalidClientException {
|
||||
public void deleteClient(ClientDetailsEntity client) throws InvalidClientException {
|
||||
|
||||
if (clientRepository.getById(client.getId()) == null) {
|
||||
throw new InvalidClientException("Client with id " + client.getClientId() + " was not found");
|
||||
|
@ -144,7 +145,7 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
// clear out any whitelisted sites for this client
|
||||
WhitelistedSite whitelistedSite = whitelistedSiteService.getByClientId(client.getClientId());
|
||||
if (whitelistedSite != null) {
|
||||
whitelistedSiteService.remove(whitelistedSite);
|
||||
whitelistedSiteService.remove(whitelistedSite);
|
||||
}
|
||||
|
||||
// take care of the client itself
|
||||
|
@ -157,51 +158,51 @@ public class DefaultOAuth2ClientDetailsEntityService implements ClientDetailsEnt
|
|||
* id from oldClient is retained.
|
||||
*/
|
||||
@Override
|
||||
public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException {
|
||||
public ClientDetailsEntity updateClient(ClientDetailsEntity oldClient, ClientDetailsEntity newClient) throws IllegalArgumentException {
|
||||
if (oldClient != null && newClient != null) {
|
||||
|
||||
for (String uri : newClient.getRegisteredRedirectUri()) {
|
||||
if (blacklistedSiteService.isBlacklisted(uri)) {
|
||||
throw new IllegalArgumentException("Client URI is blacklisted: " + uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if the client is flagged to allow for refresh tokens, make sure it's got the right scope
|
||||
if (newClient.isAllowRefresh()) {
|
||||
newClient.getScope().add("offline_access");
|
||||
} else {
|
||||
newClient.getScope().remove("offline_access");
|
||||
}
|
||||
// if the client is flagged to allow for refresh tokens, make sure it's got the right scope
|
||||
if (newClient.isAllowRefresh()) {
|
||||
newClient.getScope().add("offline_access");
|
||||
} else {
|
||||
newClient.getScope().remove("offline_access");
|
||||
}
|
||||
|
||||
return clientRepository.updateClient(oldClient.getId(), newClient);
|
||||
return clientRepository.updateClient(oldClient.getId(), newClient);
|
||||
}
|
||||
throw new IllegalArgumentException("Neither old client or new client can be null!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all clients in the system
|
||||
*/
|
||||
@Override
|
||||
public Collection<ClientDetailsEntity> getAllClients() {
|
||||
public Collection<ClientDetailsEntity> getAllClients() {
|
||||
return clientRepository.getAllClients();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a clientId for the given client and sets it to the client's clientId field. Returns the client that was passed in, now with id set.
|
||||
*/
|
||||
@Override
|
||||
public ClientDetailsEntity generateClientId(ClientDetailsEntity client) {
|
||||
public ClientDetailsEntity generateClientId(ClientDetailsEntity client) {
|
||||
client.setClientId(UUID.randomUUID().toString());
|
||||
return client;
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new clientSecret for the given client and sets it to the client's clientSecret field. Returns the client that was passed in, now with secret set.
|
||||
*/
|
||||
@Override
|
||||
public ClientDetailsEntity generateClientSecret(ClientDetailsEntity client) {
|
||||
public ClientDetailsEntity generateClientSecret(ClientDetailsEntity client) {
|
||||
client.setClientSecret(Base64.encodeBase64URLSafeString(new BigInteger(512, new SecureRandom()).toByteArray()).replace("=", ""));
|
||||
return client;
|
||||
}
|
||||
return client;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
private ApprovedSiteService approvedSiteService;
|
||||
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity createAccessToken(OAuth2Authentication authentication) throws AuthenticationException, InvalidClientException {
|
||||
public OAuth2AccessTokenEntity createAccessToken(OAuth2Authentication authentication) throws AuthenticationException, InvalidClientException {
|
||||
if (authentication != null && authentication.getOAuth2Request() != null) {
|
||||
// look up our client
|
||||
OAuth2Request clientAuth = authentication.getOAuth2Request();
|
||||
|
@ -91,70 +91,70 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
|
||||
OAuth2AccessTokenEntity token = new OAuth2AccessTokenEntity();//accessTokenFactory.createNewAccessToken();
|
||||
|
||||
// attach the client
|
||||
token.setClient(client);
|
||||
// attach the client
|
||||
token.setClient(client);
|
||||
|
||||
// inherit the scope from the auth, but make a new set so it is
|
||||
//not unmodifiable. Unmodifiables don't play nicely with Eclipselink, which
|
||||
//wants to use the clone operation.
|
||||
Set<String> scopes = Sets.newHashSet(clientAuth.getScope());
|
||||
token.setScope(scopes);
|
||||
// inherit the scope from the auth, but make a new set so it is
|
||||
//not unmodifiable. Unmodifiables don't play nicely with Eclipselink, which
|
||||
//wants to use the clone operation.
|
||||
Set<String> scopes = Sets.newHashSet(clientAuth.getScope());
|
||||
token.setScope(scopes);
|
||||
|
||||
// make it expire if necessary
|
||||
if (client.getAccessTokenValiditySeconds() != null && client.getAccessTokenValiditySeconds() > 0) {
|
||||
Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenValiditySeconds() * 1000L));
|
||||
token.setExpiration(expiration);
|
||||
}
|
||||
// make it expire if necessary
|
||||
if (client.getAccessTokenValiditySeconds() != null && client.getAccessTokenValiditySeconds() > 0) {
|
||||
Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenValiditySeconds() * 1000L));
|
||||
token.setExpiration(expiration);
|
||||
}
|
||||
|
||||
// attach the authorization so that we can look it up later
|
||||
AuthenticationHolderEntity authHolder = new AuthenticationHolderEntity();
|
||||
authHolder.setAuthentication(authentication);
|
||||
authHolder = authenticationHolderRepository.save(authHolder);
|
||||
// attach the authorization so that we can look it up later
|
||||
AuthenticationHolderEntity authHolder = new AuthenticationHolderEntity();
|
||||
authHolder.setAuthentication(authentication);
|
||||
authHolder = authenticationHolderRepository.save(authHolder);
|
||||
|
||||
token.setAuthenticationHolder(authHolder);
|
||||
token.setAuthenticationHolder(authHolder);
|
||||
|
||||
// attach a refresh token, if this client is allowed to request them and the user gets the offline scope
|
||||
// TODO: tie this to some kind of scope service
|
||||
if (client.isAllowRefresh() && scopes.contains("offline_access")) {
|
||||
OAuth2RefreshTokenEntity refreshToken = new OAuth2RefreshTokenEntity(); //refreshTokenFactory.createNewRefreshToken();
|
||||
JWTClaimsSet refreshClaims = new JWTClaimsSet();
|
||||
// attach a refresh token, if this client is allowed to request them and the user gets the offline scope
|
||||
// TODO: tie this to some kind of scope service
|
||||
if (client.isAllowRefresh() && scopes.contains("offline_access")) {
|
||||
OAuth2RefreshTokenEntity refreshToken = new OAuth2RefreshTokenEntity(); //refreshTokenFactory.createNewRefreshToken();
|
||||
JWTClaimsSet refreshClaims = new JWTClaimsSet();
|
||||
|
||||
|
||||
// make it expire if necessary
|
||||
if (client.getRefreshTokenValiditySeconds() != null) {
|
||||
Date expiration = new Date(System.currentTimeMillis() + (client.getRefreshTokenValiditySeconds() * 1000L));
|
||||
refreshToken.setExpiration(expiration);
|
||||
refreshClaims.setExpirationTime(expiration);
|
||||
}
|
||||
// make it expire if necessary
|
||||
if (client.getRefreshTokenValiditySeconds() != null) {
|
||||
Date expiration = new Date(System.currentTimeMillis() + (client.getRefreshTokenValiditySeconds() * 1000L));
|
||||
refreshToken.setExpiration(expiration);
|
||||
refreshClaims.setExpirationTime(expiration);
|
||||
}
|
||||
|
||||
// set a random identifier
|
||||
refreshClaims.setJWTID(UUID.randomUUID().toString());
|
||||
// set a random identifier
|
||||
refreshClaims.setJWTID(UUID.randomUUID().toString());
|
||||
|
||||
// TODO: add issuer fields, signature to JWT
|
||||
// TODO: add issuer fields, signature to JWT
|
||||
|
||||
PlainJWT refreshJwt = new PlainJWT(refreshClaims);
|
||||
refreshToken.setJwt(refreshJwt);
|
||||
PlainJWT refreshJwt = new PlainJWT(refreshClaims);
|
||||
refreshToken.setJwt(refreshJwt);
|
||||
|
||||
//Add the authentication
|
||||
refreshToken.setAuthenticationHolder(authHolder);
|
||||
refreshToken.setClient(client);
|
||||
//Add the authentication
|
||||
refreshToken.setAuthenticationHolder(authHolder);
|
||||
refreshToken.setClient(client);
|
||||
|
||||
|
||||
|
||||
// save the token first so that we can set it to a member of the access token (NOTE: is this step necessary?)
|
||||
tokenRepository.saveRefreshToken(refreshToken);
|
||||
// save the token first so that we can set it to a member of the access token (NOTE: is this step necessary?)
|
||||
tokenRepository.saveRefreshToken(refreshToken);
|
||||
|
||||
token.setRefreshToken(refreshToken);
|
||||
}
|
||||
token.setRefreshToken(refreshToken);
|
||||
}
|
||||
|
||||
tokenEnhancer.enhance(token, authentication);
|
||||
tokenEnhancer.enhance(token, authentication);
|
||||
|
||||
tokenRepository.saveAccessToken(token);
|
||||
tokenRepository.saveAccessToken(token);
|
||||
|
||||
//Add approved site reference, if any
|
||||
OAuth2Request originalAuthRequest = authHolder.getAuthentication().getOAuth2Request();
|
||||
//Add approved site reference, if any
|
||||
OAuth2Request originalAuthRequest = authHolder.getAuthentication().getOAuth2Request();
|
||||
|
||||
if (originalAuthRequest.getExtensions() != null && originalAuthRequest.getExtensions().containsKey("approved_site")) {
|
||||
if (originalAuthRequest.getExtensions() != null && originalAuthRequest.getExtensions().containsKey("approved_site")) {
|
||||
|
||||
Long apId = (Long) originalAuthRequest.getExtensions().get("approved_site");
|
||||
ApprovedSite ap = approvedSiteService.getById(apId);
|
||||
|
@ -165,18 +165,18 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
|
||||
}
|
||||
|
||||
if (token.getRefreshToken() != null) {
|
||||
tokenRepository.saveRefreshToken(token.getRefreshToken()); // make sure we save any changes that might have been enhanced
|
||||
}
|
||||
if (token.getRefreshToken() != null) {
|
||||
tokenRepository.saveRefreshToken(token.getRefreshToken()); // make sure we save any changes that might have been enhanced
|
||||
}
|
||||
|
||||
return token;
|
||||
return token;
|
||||
}
|
||||
|
||||
throw new AuthenticationCredentialsNotFoundException("No authentication credentials found");
|
||||
}
|
||||
throw new AuthenticationCredentialsNotFoundException("No authentication credentials found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity refreshAccessToken(String refreshTokenValue, TokenRequest authRequest) throws AuthenticationException {
|
||||
public OAuth2AccessTokenEntity refreshAccessToken(String refreshTokenValue, TokenRequest authRequest) throws AuthenticationException {
|
||||
|
||||
OAuth2RefreshTokenEntity refreshToken = tokenRepository.getRefreshTokenByValue(refreshTokenValue);
|
||||
|
||||
|
@ -226,27 +226,27 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
token.setScope(refreshScopes);
|
||||
}
|
||||
|
||||
token.setClient(client);
|
||||
token.setClient(client);
|
||||
|
||||
if (client.getAccessTokenValiditySeconds() != null) {
|
||||
Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenValiditySeconds() * 1000L));
|
||||
token.setExpiration(expiration);
|
||||
}
|
||||
if (client.getAccessTokenValiditySeconds() != null) {
|
||||
Date expiration = new Date(System.currentTimeMillis() + (client.getAccessTokenValiditySeconds() * 1000L));
|
||||
token.setExpiration(expiration);
|
||||
}
|
||||
|
||||
token.setRefreshToken(refreshToken);
|
||||
token.setRefreshToken(refreshToken);
|
||||
|
||||
token.setAuthenticationHolder(authHolder);
|
||||
token.setAuthenticationHolder(authHolder);
|
||||
|
||||
tokenEnhancer.enhance(token, authHolder.getAuthentication());
|
||||
tokenEnhancer.enhance(token, authHolder.getAuthentication());
|
||||
|
||||
tokenRepository.saveAccessToken(token);
|
||||
tokenRepository.saveAccessToken(token);
|
||||
|
||||
return token;
|
||||
return token;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException {
|
||||
public OAuth2Authentication loadAuthentication(String accessTokenValue) throws AuthenticationException {
|
||||
|
||||
OAuth2AccessTokenEntity accessToken = tokenRepository.getAccessTokenByValue(accessTokenValue);
|
||||
|
||||
|
@ -260,15 +260,15 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
throw new InvalidTokenException("Expired access token: " + accessTokenValue);
|
||||
}
|
||||
|
||||
return accessToken.getAuthenticationHolder().getAuthentication();
|
||||
}
|
||||
return accessToken.getAuthenticationHolder().getAuthentication();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an access token from its token value.
|
||||
*/
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity readAccessToken(String accessTokenValue) throws AuthenticationException {
|
||||
public OAuth2AccessTokenEntity readAccessToken(String accessTokenValue) throws AuthenticationException {
|
||||
OAuth2AccessTokenEntity accessToken = tokenRepository.getAccessTokenByValue(accessTokenValue);
|
||||
if (accessToken == null) {
|
||||
throw new InvalidTokenException("Access token for value " + accessTokenValue + " was not found");
|
||||
|
@ -276,7 +276,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
else {
|
||||
return accessToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an access token by its authentication object.
|
||||
|
@ -293,7 +293,7 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
* Get a refresh token by its token value.
|
||||
*/
|
||||
@Override
|
||||
public OAuth2RefreshTokenEntity getRefreshToken(String refreshTokenValue) throws AuthenticationException {
|
||||
public OAuth2RefreshTokenEntity getRefreshToken(String refreshTokenValue) throws AuthenticationException {
|
||||
OAuth2RefreshTokenEntity refreshToken = tokenRepository.getRefreshTokenByValue(refreshTokenValue);
|
||||
if (refreshToken == null) {
|
||||
throw new InvalidTokenException("Refresh token for value " + refreshTokenValue + " was not found");
|
||||
|
@ -301,61 +301,61 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
else {
|
||||
return refreshToken;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke a refresh token and all access tokens issued to it.
|
||||
*/
|
||||
@Override
|
||||
public void revokeRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
tokenRepository.clearAccessTokensForRefreshToken(refreshToken);
|
||||
tokenRepository.removeRefreshToken(refreshToken);
|
||||
}
|
||||
public void revokeRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
tokenRepository.clearAccessTokensForRefreshToken(refreshToken);
|
||||
tokenRepository.removeRefreshToken(refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* Revoke an access token.
|
||||
*/
|
||||
@Override
|
||||
public void revokeAccessToken(OAuth2AccessTokenEntity accessToken) {
|
||||
public void revokeAccessToken(OAuth2AccessTokenEntity accessToken) {
|
||||
tokenRepository.removeAccessToken(accessToken);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#getAccessTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2AccessTokenEntity> getAccessTokensForClient(ClientDetailsEntity client) {
|
||||
return tokenRepository.getAccessTokensForClient(client);
|
||||
}
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#getAccessTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2AccessTokenEntity> getAccessTokensForClient(ClientDetailsEntity client) {
|
||||
return tokenRepository.getAccessTokensForClient(client);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#getRefreshTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client) {
|
||||
return tokenRepository.getRefreshTokensForClient(client);
|
||||
}
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#getRefreshTokensForClient(org.mitre.oauth2.model.ClientDetailsEntity)
|
||||
*/
|
||||
@Override
|
||||
public List<OAuth2RefreshTokenEntity> getRefreshTokensForClient(ClientDetailsEntity client) {
|
||||
return tokenRepository.getRefreshTokensForClient(client);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Scheduled(fixedRate = 5 * 60 * 1000) // schedule this task every five minutes
|
||||
public void clearExpiredTokens() {
|
||||
logger.info("Cleaning out all expired tokens");
|
||||
@Override
|
||||
@Scheduled(fixedRate = 5 * 60 * 1000) // schedule this task every five minutes
|
||||
public void clearExpiredTokens() {
|
||||
logger.info("Cleaning out all expired tokens");
|
||||
|
||||
List<OAuth2AccessTokenEntity> accessTokens = tokenRepository.getExpiredAccessTokens();
|
||||
logger.info("Found " + accessTokens.size() + " expired access tokens");
|
||||
for (OAuth2AccessTokenEntity oAuth2AccessTokenEntity : accessTokens) {
|
||||
revokeAccessToken(oAuth2AccessTokenEntity);
|
||||
}
|
||||
List<OAuth2AccessTokenEntity> accessTokens = tokenRepository.getExpiredAccessTokens();
|
||||
logger.info("Found " + accessTokens.size() + " expired access tokens");
|
||||
for (OAuth2AccessTokenEntity oAuth2AccessTokenEntity : accessTokens) {
|
||||
revokeAccessToken(oAuth2AccessTokenEntity);
|
||||
}
|
||||
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = tokenRepository.getExpiredRefreshTokens();
|
||||
logger.info("Found " + refreshTokens.size() + " expired refresh tokens");
|
||||
for (OAuth2RefreshTokenEntity oAuth2RefreshTokenEntity : refreshTokens) {
|
||||
revokeRefreshToken(oAuth2RefreshTokenEntity);
|
||||
}
|
||||
}
|
||||
List<OAuth2RefreshTokenEntity> refreshTokens = tokenRepository.getExpiredRefreshTokens();
|
||||
logger.info("Found " + refreshTokens.size() + " expired refresh tokens");
|
||||
for (OAuth2RefreshTokenEntity oAuth2RefreshTokenEntity : refreshTokens) {
|
||||
revokeRefreshToken(oAuth2RefreshTokenEntity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Get a builder object for this class (for tests)
|
||||
* @return
|
||||
*/
|
||||
|
@ -394,20 +394,20 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#saveAccessToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity accessToken) {
|
||||
return tokenRepository.saveAccessToken(accessToken);
|
||||
}
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#saveAccessToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity saveAccessToken(OAuth2AccessTokenEntity accessToken) {
|
||||
return tokenRepository.saveAccessToken(accessToken);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#saveRefreshToken(org.mitre.oauth2.model.OAuth2RefreshTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
return tokenRepository.saveRefreshToken(refreshToken);
|
||||
}
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#saveRefreshToken(org.mitre.oauth2.model.OAuth2RefreshTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2RefreshTokenEntity saveRefreshToken(OAuth2RefreshTokenEntity refreshToken) {
|
||||
return tokenRepository.saveRefreshToken(refreshToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tokenEnhancer
|
||||
|
@ -424,12 +424,12 @@ public class DefaultOAuth2ProviderTokenService implements OAuth2TokenEntityServi
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#getAccessTokenForIdToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken) {
|
||||
return tokenRepository.getAccessTokenForIdToken(idToken);
|
||||
}
|
||||
* @see org.mitre.oauth2.service.OAuth2TokenEntityService#getAccessTokenForIdToken(org.mitre.oauth2.model.OAuth2AccessTokenEntity)
|
||||
*/
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getAccessTokenForIdToken(OAuth2AccessTokenEntity idToken) {
|
||||
return tokenRepository.getAccessTokenForIdToken(idToken);
|
||||
}
|
||||
|
||||
@Override
|
||||
public OAuth2AccessTokenEntity getAccessTokenById(Long id) {
|
||||
|
|
|
@ -32,128 +32,128 @@ public class DefaultSystemScopeService implements SystemScopeService {
|
|||
|
||||
private Predicate<SystemScope> isDefault = new Predicate<SystemScope>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable SystemScope input) {
|
||||
public boolean apply(@Nullable SystemScope input) {
|
||||
return (input != null && input.isDefaultScope());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
private Predicate<SystemScope> isDynReg = new Predicate<SystemScope>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable SystemScope input) {
|
||||
public boolean apply(@Nullable SystemScope input) {
|
||||
return (input != null && input.isAllowDynReg());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Function<String, SystemScope> stringToSystemScope = new Function<String, SystemScope>() {
|
||||
@Override
|
||||
public SystemScope apply(@Nullable String input) {
|
||||
public SystemScope apply(@Nullable String input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
} else {
|
||||
SystemScope s = getByValue(input);
|
||||
if (s != null) {
|
||||
// get the real scope if it's available
|
||||
return s;
|
||||
} else {
|
||||
// make a fake one otherwise
|
||||
return new SystemScope(input);
|
||||
}
|
||||
SystemScope s = getByValue(input);
|
||||
if (s != null) {
|
||||
// get the real scope if it's available
|
||||
return s;
|
||||
} else {
|
||||
// make a fake one otherwise
|
||||
return new SystemScope(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private Function<SystemScope, String> systemScopeToString = new Function<SystemScope, String>() {
|
||||
@Override
|
||||
public String apply(@Nullable SystemScope input) {
|
||||
public String apply(@Nullable SystemScope input) {
|
||||
if (input == null) {
|
||||
return null;
|
||||
} else {
|
||||
return input.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#getAll()
|
||||
*/
|
||||
@Override
|
||||
public Set<SystemScope> getAll() {
|
||||
return repository.getAll();
|
||||
}
|
||||
@Override
|
||||
public Set<SystemScope> getAll() {
|
||||
return repository.getAll();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#getDefaults()
|
||||
*/
|
||||
@Override
|
||||
public Set<SystemScope> getDefaults() {
|
||||
@Override
|
||||
public Set<SystemScope> getDefaults() {
|
||||
return Sets.filter(getAll(), isDefault);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#getDynReg()
|
||||
*/
|
||||
@Override
|
||||
public Set<SystemScope> getDynReg() {
|
||||
return Sets.filter(getAll(), isDynReg);
|
||||
}
|
||||
@Override
|
||||
public Set<SystemScope> getDynReg() {
|
||||
return Sets.filter(getAll(), isDynReg);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#getById(java.lang.Long)
|
||||
*/
|
||||
@Override
|
||||
public SystemScope getById(Long id) {
|
||||
return repository.getById(id);
|
||||
}
|
||||
@Override
|
||||
public SystemScope getById(Long id) {
|
||||
return repository.getById(id);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#getByValue(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public SystemScope getByValue(String value) {
|
||||
return repository.getByValue(value);
|
||||
}
|
||||
@Override
|
||||
public SystemScope getByValue(String value) {
|
||||
return repository.getByValue(value);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#remove(org.mitre.oauth2.model.SystemScope)
|
||||
*/
|
||||
@Override
|
||||
public void remove(SystemScope scope) {
|
||||
repository.remove(scope);
|
||||
@Override
|
||||
public void remove(SystemScope scope) {
|
||||
repository.remove(scope);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#save(org.mitre.oauth2.model.SystemScope)
|
||||
*/
|
||||
@Override
|
||||
public SystemScope save(SystemScope scope) {
|
||||
return repository.save(scope);
|
||||
}
|
||||
@Override
|
||||
public SystemScope save(SystemScope scope) {
|
||||
return repository.save(scope);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#fromStrings(java.util.Set)
|
||||
*/
|
||||
@Override
|
||||
public Set<SystemScope> fromStrings(Set<String> scope) {
|
||||
if (scope == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new LinkedHashSet<SystemScope>(Collections2.filter(Collections2.transform(scope, stringToSystemScope), Predicates.notNull()));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Set<SystemScope> fromStrings(Set<String> scope) {
|
||||
if (scope == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new LinkedHashSet<SystemScope>(Collections2.filter(Collections2.transform(scope, stringToSystemScope), Predicates.notNull()));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.mitre.oauth2.service.SystemScopeService#toStrings(java.util.Set)
|
||||
*/
|
||||
@Override
|
||||
public Set<String> toStrings(Set<SystemScope> scope) {
|
||||
if (scope == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new LinkedHashSet<String>(Collections2.filter(Collections2.transform(scope, systemScopeToString), Predicates.notNull()));
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public Set<String> toStrings(Set<SystemScope> scope) {
|
||||
if (scope == null) {
|
||||
return null;
|
||||
} else {
|
||||
return new LinkedHashSet<String>(Collections2.filter(Collections2.transform(scope, systemScopeToString), Predicates.notNull()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -48,50 +48,50 @@ public class ChainedTokenGranter extends AbstractTokenGranter {
|
|||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.security.oauth2.provider.token.AbstractTokenGranter#getOAuth2Authentication(org.springframework.security.oauth2.provider.AuthorizationRequest)
|
||||
*/
|
||||
@Override
|
||||
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) throws AuthenticationException, InvalidTokenException {
|
||||
// read and load up the existing token
|
||||
String incomingTokenValue = tokenRequest.getRequestParameters().get("token");
|
||||
OAuth2AccessTokenEntity incomingToken = tokenServices.readAccessToken(incomingTokenValue);
|
||||
* @see org.springframework.security.oauth2.provider.token.AbstractTokenGranter#getOAuth2Authentication(org.springframework.security.oauth2.provider.AuthorizationRequest)
|
||||
*/
|
||||
@Override
|
||||
protected OAuth2Authentication getOAuth2Authentication(ClientDetails client, TokenRequest tokenRequest) throws AuthenticationException, InvalidTokenException {
|
||||
// read and load up the existing token
|
||||
String incomingTokenValue = tokenRequest.getRequestParameters().get("token");
|
||||
OAuth2AccessTokenEntity incomingToken = tokenServices.readAccessToken(incomingTokenValue);
|
||||
|
||||
// check for scoping in the request, can't up-scope with a chained request
|
||||
Set<String> approvedScopes = incomingToken.getScope();
|
||||
Set<String> requestedScopes = tokenRequest.getScope();
|
||||
// check for scoping in the request, can't up-scope with a chained request
|
||||
Set<String> approvedScopes = incomingToken.getScope();
|
||||
Set<String> requestedScopes = tokenRequest.getScope();
|
||||
|
||||
if (requestedScopes == null) {
|
||||
requestedScopes = new HashSet<String>();
|
||||
}
|
||||
if (requestedScopes == null) {
|
||||
requestedScopes = new HashSet<String>();
|
||||
}
|
||||
|
||||
// do a check on the requested scopes -- if they exactly match the client scopes, they were probably shadowed by the token granter
|
||||
if (client.getScope().equals(requestedScopes)) {
|
||||
requestedScopes = new HashSet<String>();
|
||||
}
|
||||
// do a check on the requested scopes -- if they exactly match the client scopes, they were probably shadowed by the token granter
|
||||
if (client.getScope().equals(requestedScopes)) {
|
||||
requestedScopes = new HashSet<String>();
|
||||
}
|
||||
|
||||
// if our scopes are a valid subset of what's allowed, we can continue
|
||||
if (approvedScopes.containsAll(requestedScopes)) {
|
||||
// if our scopes are a valid subset of what's allowed, we can continue
|
||||
if (approvedScopes.containsAll(requestedScopes)) {
|
||||
|
||||
if (requestedScopes.isEmpty()) {
|
||||
// if there are no scopes, inherit the original scopes from the token
|
||||
tokenRequest.setScope(approvedScopes);
|
||||
} else {
|
||||
// if scopes were asked for, give only the subset of scopes requested
|
||||
// this allows safe downscoping
|
||||
tokenRequest.setScope(Sets.intersection(requestedScopes, approvedScopes));
|
||||
}
|
||||
if (requestedScopes.isEmpty()) {
|
||||
// if there are no scopes, inherit the original scopes from the token
|
||||
tokenRequest.setScope(approvedScopes);
|
||||
} else {
|
||||
// if scopes were asked for, give only the subset of scopes requested
|
||||
// this allows safe downscoping
|
||||
tokenRequest.setScope(Sets.intersection(requestedScopes, approvedScopes));
|
||||
}
|
||||
|
||||
// NOTE: don't revoke the existing access token
|
||||
// NOTE: don't revoke the existing access token
|
||||
|
||||
// create a new access token
|
||||
OAuth2Authentication authentication = new OAuth2Authentication(getRequestFactory().createOAuth2Request(client, tokenRequest), incomingToken.getAuthenticationHolder().getAuthentication().getUserAuthentication());
|
||||
// create a new access token
|
||||
OAuth2Authentication authentication = new OAuth2Authentication(getRequestFactory().createOAuth2Request(client, tokenRequest), incomingToken.getAuthenticationHolder().getAuthentication().getUserAuthentication());
|
||||
|
||||
return authentication;
|
||||
return authentication;
|
||||
|
||||
} else {
|
||||
throw new InvalidScopeException("Invalid scope requested in chained request", approvedScopes);
|
||||
}
|
||||
} else {
|
||||
throw new InvalidScopeException("Invalid scope requested in chained request", approvedScopes);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -49,63 +49,63 @@ public class JwtAssertionTokenGranter extends AbstractTokenGranter {
|
|||
|
||||
@Autowired
|
||||
public JwtAssertionTokenGranter(OAuth2TokenEntityService tokenServices, ClientDetailsEntityService clientDetailsService, OAuth2RequestFactory requestFactory) {
|
||||
super(tokenServices, clientDetailsService, requestFactory, grantType);
|
||||
this.tokenServices = tokenServices;
|
||||
}
|
||||
super(tokenServices, clientDetailsService, requestFactory, grantType);
|
||||
this.tokenServices = tokenServices;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.security.oauth2.provider.token.AbstractTokenGranter#getOAuth2Authentication(org.springframework.security.oauth2.provider.AuthorizationRequest)
|
||||
*/
|
||||
@Override
|
||||
protected OAuth2AccessToken getAccessToken(ClientDetails client, TokenRequest tokenRequest) throws AuthenticationException, InvalidTokenException {
|
||||
// read and load up the existing token
|
||||
String incomingTokenValue = tokenRequest.getRequestParameters().get("assertion");
|
||||
OAuth2AccessTokenEntity incomingToken = tokenServices.readAccessToken(incomingTokenValue);
|
||||
* @see org.springframework.security.oauth2.provider.token.AbstractTokenGranter#getOAuth2Authentication(org.springframework.security.oauth2.provider.AuthorizationRequest)
|
||||
*/
|
||||
@Override
|
||||
protected OAuth2AccessToken getAccessToken(ClientDetails client, TokenRequest tokenRequest) throws AuthenticationException, InvalidTokenException {
|
||||
// read and load up the existing token
|
||||
String incomingTokenValue = tokenRequest.getRequestParameters().get("assertion");
|
||||
OAuth2AccessTokenEntity incomingToken = tokenServices.readAccessToken(incomingTokenValue);
|
||||
|
||||
if (incomingToken.getScope().contains(OAuth2AccessTokenEntity.ID_TOKEN_SCOPE)) {
|
||||
if (incomingToken.getScope().contains(OAuth2AccessTokenEntity.ID_TOKEN_SCOPE)) {
|
||||
|
||||
if (!client.getClientId().equals(tokenRequest.getClientId())) {
|
||||
throw new InvalidClientException("Not the right client for this token");
|
||||
}
|
||||
if (!client.getClientId().equals(tokenRequest.getClientId())) {
|
||||
throw new InvalidClientException("Not the right client for this token");
|
||||
}
|
||||
|
||||
// it's an ID token, process it accordingly
|
||||
// it's an ID token, process it accordingly
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
// TODO: make this use a more specific idtoken class
|
||||
JWT idToken = JWTParser.parse(incomingTokenValue);
|
||||
// TODO: make this use a more specific idtoken class
|
||||
JWT idToken = JWTParser.parse(incomingTokenValue);
|
||||
|
||||
OAuth2AccessTokenEntity accessToken = tokenServices.getAccessTokenForIdToken(incomingToken);
|
||||
OAuth2AccessTokenEntity accessToken = tokenServices.getAccessTokenForIdToken(incomingToken);
|
||||
|
||||
if (accessToken != null) {
|
||||
if (accessToken != null) {
|
||||
|
||||
//OAuth2AccessTokenEntity newIdToken = tokenServices.get
|
||||
//OAuth2AccessTokenEntity newIdToken = tokenServices.get
|
||||
|
||||
OAuth2AccessTokenEntity newIdTokenEntity = new OAuth2AccessTokenEntity();
|
||||
OAuth2AccessTokenEntity newIdTokenEntity = new OAuth2AccessTokenEntity();
|
||||
|
||||
// copy over all existing claims
|
||||
JWTClaimsSet claims = new JWTClaimsSet(idToken.getJWTClaimsSet());
|
||||
// copy over all existing claims
|
||||
JWTClaimsSet claims = new JWTClaimsSet(idToken.getJWTClaimsSet());
|
||||
|
||||
if (client instanceof ClientDetailsEntity) {
|
||||
if (client instanceof ClientDetailsEntity) {
|
||||
|
||||
ClientDetailsEntity clientEntity = (ClientDetailsEntity) client;
|
||||
ClientDetailsEntity clientEntity = (ClientDetailsEntity) client;
|
||||
|
||||
// update expiration and issued-at claims
|
||||
// update expiration and issued-at claims
|
||||
if (clientEntity.getIdTokenValiditySeconds() != null) {
|
||||
Date expiration = new Date(System.currentTimeMillis() + (clientEntity.getIdTokenValiditySeconds() * 1000L));
|
||||
claims.setExpirationTime(expiration);
|
||||
newIdTokenEntity.setExpiration(expiration);
|
||||
}
|
||||
|
||||
} else {
|
||||
//TODO: What should happen in this case? Is this possible?
|
||||
}
|
||||
} else {
|
||||
//TODO: What should happen in this case? Is this possible?
|
||||
}
|
||||
|
||||
claims.setIssueTime(new Date());
|
||||
|
||||
|
||||
SignedJWT newIdToken = new SignedJWT((JWSHeader) idToken.getHeader(), claims);
|
||||
jwtService.signJwt(newIdToken);
|
||||
jwtService.signJwt(newIdToken);
|
||||
|
||||
newIdTokenEntity.setJwt(newIdToken);
|
||||
newIdTokenEntity.setAuthenticationHolder(incomingToken.getAuthenticationHolder());
|
||||
|
@ -123,20 +123,20 @@ public class JwtAssertionTokenGranter extends AbstractTokenGranter {
|
|||
|
||||
return newIdTokenEntity;
|
||||
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
logger.warn("Couldn't parse id token", e);
|
||||
}
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
logger.warn("Couldn't parse id token", e);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// if we got down here, we didn't actually create any tokens, so return null
|
||||
// if we got down here, we didn't actually create any tokens, so return null
|
||||
|
||||
return null;
|
||||
return null;
|
||||
|
||||
/*
|
||||
* Otherwise, process it like an access token assertion ... which we don't support yet so this is all commented out
|
||||
* /
|
||||
/*
|
||||
* Otherwise, process it like an access token assertion ... which we don't support yet so this is all commented out
|
||||
* /
|
||||
if (jwtService.validateSignature(incomingTokenValue)) {
|
||||
|
||||
Jwt jwt = Jwt.parse(incomingTokenValue);
|
||||
|
@ -175,9 +175,9 @@ public class JwtAssertionTokenGranter extends AbstractTokenGranter {
|
|||
} else {
|
||||
return null; // throw error??
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public class TokenIntrospectionView extends AbstractView {
|
|||
private static Logger logger = LoggerFactory.getLogger(TokenIntrospectionView.class);
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
Gson gson = new GsonBuilder().setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class TokenIntrospectionView extends AbstractView {
|
|||
// serialize other classes without filter (lists and sets and things)
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -84,27 +84,28 @@ public class TokenIntrospectionView extends AbstractView {
|
|||
|
||||
})
|
||||
.registerTypeAdapter(OAuth2AccessTokenEntity.class, new JsonSerializer<OAuth2AccessTokenEntity>() {
|
||||
public JsonElement serialize(OAuth2AccessTokenEntity src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject token = new JsonObject();
|
||||
@Override
|
||||
public JsonElement serialize(OAuth2AccessTokenEntity src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject token = new JsonObject();
|
||||
|
||||
token.addProperty("valid", true);
|
||||
token.addProperty("valid", true);
|
||||
|
||||
JsonArray scopes = new JsonArray();
|
||||
for (String scope : src.getScope()) {
|
||||
scopes.add(new JsonPrimitive(scope));
|
||||
}
|
||||
token.add("scope", scopes);
|
||||
JsonArray scopes = new JsonArray();
|
||||
for (String scope : src.getScope()) {
|
||||
scopes.add(new JsonPrimitive(scope));
|
||||
}
|
||||
token.add("scope", scopes);
|
||||
|
||||
token.add("expires_at", context.serialize(src.getExpiration()));
|
||||
token.add("expires_at", context.serialize(src.getExpiration()));
|
||||
|
||||
//token.addProperty("audience", src.getAuthenticationHolder().getAuthentication().getAuthorizationRequest().getClientId());
|
||||
//token.addProperty("audience", src.getAuthenticationHolder().getAuthentication().getAuthorizationRequest().getClientId());
|
||||
|
||||
token.addProperty("subject", src.getAuthenticationHolder().getAuthentication().getName());
|
||||
token.addProperty("subject", src.getAuthenticationHolder().getAuthentication().getName());
|
||||
|
||||
token.addProperty("client_id", src.getAuthenticationHolder().getAuthentication().getOAuth2Request().getClientId());
|
||||
token.addProperty("client_id", src.getAuthenticationHolder().getAuthentication().getOAuth2Request().getClientId());
|
||||
|
||||
return token;
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
})
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
|
@ -130,6 +131,6 @@ public class TokenIntrospectionView extends AbstractView {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -97,48 +97,48 @@ public class OAuthConfirmationController {
|
|||
|
||||
String redirect_uri = clientAuth.getRequestParameters().get("redirect_uri");
|
||||
|
||||
model.put("redirect_uri", redirect_uri);
|
||||
model.put("redirect_uri", redirect_uri);
|
||||
|
||||
|
||||
/*
|
||||
/*
|
||||
Map<String, Boolean> scopes = new HashMap<String, Boolean>();
|
||||
for (String scope : clientAuth.getScope()) {
|
||||
scopes.put(scope, Boolean.TRUE);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
|
||||
Set<SystemScope> scopes = scopeService.fromStrings(clientAuth.getScope());
|
||||
Set<SystemScope> scopes = scopeService.fromStrings(clientAuth.getScope());
|
||||
|
||||
Set<SystemScope> sortedScopes = new LinkedHashSet<SystemScope>(scopes.size());
|
||||
Set<SystemScope> systemScopes = scopeService.getAll();
|
||||
Set<SystemScope> sortedScopes = new LinkedHashSet<SystemScope>(scopes.size());
|
||||
Set<SystemScope> systemScopes = scopeService.getAll();
|
||||
|
||||
// sort scopes for display
|
||||
for (SystemScope s : systemScopes) {
|
||||
if (scopes.contains(s)) {
|
||||
sortedScopes.add(s);
|
||||
}
|
||||
}
|
||||
// sort scopes for display
|
||||
for (SystemScope s : systemScopes) {
|
||||
if (scopes.contains(s)) {
|
||||
sortedScopes.add(s);
|
||||
}
|
||||
}
|
||||
|
||||
sortedScopes.addAll(Sets.difference(scopes, systemScopes));
|
||||
sortedScopes.addAll(Sets.difference(scopes, systemScopes));
|
||||
|
||||
model.put("scopes", sortedScopes);
|
||||
model.put("scopes", sortedScopes);
|
||||
|
||||
return new ModelAndView("oauth/approve", model);
|
||||
return new ModelAndView("oauth/approve", model);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the clientService
|
||||
*/
|
||||
public ClientDetailsEntityService getClientService() {
|
||||
return clientService;
|
||||
}
|
||||
* @return the clientService
|
||||
*/
|
||||
public ClientDetailsEntityService getClientService() {
|
||||
return clientService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientService the clientService to set
|
||||
*/
|
||||
public void setClientService(ClientDetailsEntityService clientService) {
|
||||
this.clientService = clientService;
|
||||
}
|
||||
* @param clientService the clientService to set
|
||||
*/
|
||||
public void setClientService(ClientDetailsEntityService clientService) {
|
||||
this.clientService = clientService;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -59,20 +59,20 @@ public class RevocationEndpoint {
|
|||
OAuth2RefreshTokenEntity refreshToken = null;
|
||||
OAuth2AccessTokenEntity accessToken = null;
|
||||
try {
|
||||
refreshToken = tokenServices.getRefreshToken(tokenValue);
|
||||
} catch (InvalidTokenException e) {
|
||||
// it's OK if either of these tokens are bad
|
||||
//TODO: Error Handling
|
||||
}
|
||||
refreshToken = tokenServices.getRefreshToken(tokenValue);
|
||||
} catch (InvalidTokenException e) {
|
||||
// it's OK if either of these tokens are bad
|
||||
//TODO: Error Handling
|
||||
}
|
||||
|
||||
try {
|
||||
accessToken = tokenServices.readAccessToken(tokenValue);
|
||||
} catch (InvalidTokenException e) {
|
||||
// it's OK if either of these tokens are bad
|
||||
//TODO: Error Handling
|
||||
} catch (AuthenticationException e) {
|
||||
//TODO: Error Handling
|
||||
}
|
||||
accessToken = tokenServices.readAccessToken(tokenValue);
|
||||
} catch (InvalidTokenException e) {
|
||||
// it's OK if either of these tokens are bad
|
||||
//TODO: Error Handling
|
||||
} catch (AuthenticationException e) {
|
||||
//TODO: Error Handling
|
||||
}
|
||||
|
||||
if (refreshToken == null && accessToken == null) {
|
||||
//TODO: Error Handling
|
||||
|
|
|
@ -5,9 +5,6 @@ package org.mitre.oauth2.web;
|
|||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.EntityExistsException;
|
||||
import javax.persistence.TransactionRequiredException;
|
||||
|
||||
import org.mitre.oauth2.model.SystemScope;
|
||||
import org.mitre.oauth2.service.SystemScopeService;
|
||||
import org.slf4j.Logger;
|
||||
|
|
|
@ -120,21 +120,21 @@ public class ConnectOAuth2RequestFactory extends DefaultOAuth2RequestFactory {
|
|||
* @param inputParams
|
||||
* @return
|
||||
*/
|
||||
private Map<String, String> processRequestObject(Map<String, String> inputParams) {
|
||||
private Map<String, String> processRequestObject(Map<String, String> inputParams) {
|
||||
|
||||
String jwtString = inputParams.get("request");
|
||||
String jwtString = inputParams.get("request");
|
||||
|
||||
// if there's no request object, bail early
|
||||
if (Strings.isNullOrEmpty(jwtString)) {
|
||||
return inputParams;
|
||||
}
|
||||
// if there's no request object, bail early
|
||||
if (Strings.isNullOrEmpty(jwtString)) {
|
||||
return inputParams;
|
||||
}
|
||||
|
||||
// start by copying over what's already in there
|
||||
Map<String, String> parameters = new HashMap<String, String>(inputParams);
|
||||
// start by copying over what's already in there
|
||||
Map<String, String> parameters = new HashMap<String, String>(inputParams);
|
||||
|
||||
// parse the request object
|
||||
try {
|
||||
SignedJWT jwsObject = SignedJWT.parse(jwtString);
|
||||
// parse the request object
|
||||
try {
|
||||
SignedJWT jwsObject = SignedJWT.parse(jwtString);
|
||||
JSONObject claims = jwsObject.getPayload().toJSONObject();
|
||||
|
||||
// TODO: check parameter consistency, move keys to constants
|
||||
|
@ -219,10 +219,10 @@ public class ConnectOAuth2RequestFactory extends DefaultOAuth2RequestFactory {
|
|||
}
|
||||
}
|
||||
|
||||
} catch (ParseException e) {
|
||||
logger.error("ParseException while parsing RequestObject:", e);
|
||||
}
|
||||
} catch (ParseException e) {
|
||||
logger.error("ParseException while parsing RequestObject:", e);
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,11 +25,11 @@ public class JwtBearerAssertionAuthenticationToken extends AbstractAuthenticatio
|
|||
* @param jwt
|
||||
*/
|
||||
public JwtBearerAssertionAuthenticationToken(String clientId, JWT jwt) {
|
||||
super(null);
|
||||
this.clientId = clientId;
|
||||
this.jwt = jwt;
|
||||
setAuthenticated(false);
|
||||
}
|
||||
super(null);
|
||||
this.clientId = clientId;
|
||||
this.jwt = jwt;
|
||||
setAuthenticated(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an authenticated token with the given clientID, jwt, and authorities set
|
||||
|
@ -38,11 +38,11 @@ public class JwtBearerAssertionAuthenticationToken extends AbstractAuthenticatio
|
|||
* @param authorities
|
||||
*/
|
||||
public JwtBearerAssertionAuthenticationToken(String clientId, JWT jwt, Collection<? extends GrantedAuthority> authorities) {
|
||||
super(authorities);
|
||||
this.clientId = clientId;
|
||||
this.jwt = jwt;
|
||||
setAuthenticated(true);
|
||||
}
|
||||
super(authorities);
|
||||
this.clientId = clientId;
|
||||
this.jwt = jwt;
|
||||
setAuthenticated(true);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.security.core.Authentication#getCredentials()
|
||||
|
@ -61,41 +61,41 @@ public class JwtBearerAssertionAuthenticationToken extends AbstractAuthenticatio
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the clientId
|
||||
*/
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
* @return the clientId
|
||||
*/
|
||||
public String getClientId() {
|
||||
return clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientId the clientId to set
|
||||
*/
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
* @param clientId the clientId to set
|
||||
*/
|
||||
public void setClientId(String clientId) {
|
||||
this.clientId = clientId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jwt
|
||||
*/
|
||||
public JWT getJwt() {
|
||||
return jwt;
|
||||
}
|
||||
* @return the jwt
|
||||
*/
|
||||
public JWT getJwt() {
|
||||
return jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jwt the jwt to set
|
||||
*/
|
||||
public void setJwt(JWT jwt) {
|
||||
this.jwt = jwt;
|
||||
}
|
||||
* @param jwt the jwt to set
|
||||
*/
|
||||
public void setJwt(JWT jwt) {
|
||||
this.jwt = jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear out the JWT that this token holds.
|
||||
*/
|
||||
@Override
|
||||
public void eraseCredentials() {
|
||||
super.eraseCredentials();
|
||||
setJwt(null);
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public void eraseCredentials() {
|
||||
super.eraseCredentials();
|
||||
setJwt(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -50,27 +50,27 @@ public class JwtBearerAuthenticationProvider implements AuthenticationProvider {
|
|||
|
||||
/**
|
||||
* Try to validate the client credentials by parsing and validating the JWT.
|
||||
*/
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
*/
|
||||
@Override
|
||||
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
|
||||
|
||||
JwtBearerAssertionAuthenticationToken jwtAuth = (JwtBearerAssertionAuthenticationToken)authentication;
|
||||
JwtBearerAssertionAuthenticationToken jwtAuth = (JwtBearerAssertionAuthenticationToken)authentication;
|
||||
|
||||
|
||||
try {
|
||||
ClientDetailsEntity client = clientService.loadClientByClientId(jwtAuth.getClientId());
|
||||
try {
|
||||
ClientDetailsEntity client = clientService.loadClientByClientId(jwtAuth.getClientId());
|
||||
|
||||
JWT jwt = jwtAuth.getJwt();
|
||||
ReadOnlyJWTClaimsSet jwtClaims = jwt.getJWTClaimsSet();
|
||||
JWT jwt = jwtAuth.getJwt();
|
||||
ReadOnlyJWTClaimsSet jwtClaims = jwt.getJWTClaimsSet();
|
||||
|
||||
// check the signature with nimbus
|
||||
if (jwt instanceof SignedJWT) {
|
||||
SignedJWT jws = (SignedJWT)jwt;
|
||||
JwtSigningAndValidationService validator = validators.get(client.getJwksUri());
|
||||
if (validator == null || !validator.validateSignature(jws)) {
|
||||
throw new AuthenticationServiceException("Invalid signature");
|
||||
}
|
||||
}
|
||||
// check the signature with nimbus
|
||||
if (jwt instanceof SignedJWT) {
|
||||
SignedJWT jws = (SignedJWT)jwt;
|
||||
JwtSigningAndValidationService validator = validators.get(client.getJwksUri());
|
||||
if (validator == null || !validator.validateSignature(jws)) {
|
||||
throw new AuthenticationServiceException("Invalid signature");
|
||||
}
|
||||
}
|
||||
|
||||
// check the issuer
|
||||
if (jwtClaims.getIssuer() == null) {
|
||||
|
@ -114,24 +114,24 @@ public class JwtBearerAuthenticationProvider implements AuthenticationProvider {
|
|||
throw new AuthenticationServiceException("Audience does not match, expected " + config.getIssuer() + " got " + jwtClaims.getAudience());
|
||||
}
|
||||
|
||||
// IFF we managed to get all the way down here, the token is valid
|
||||
// IFF we managed to get all the way down here, the token is valid
|
||||
return new JwtBearerAssertionAuthenticationToken(client.getClientId(), jwt, client.getAuthorities());
|
||||
|
||||
} catch (ClientNotFoundException e) {
|
||||
throw new UsernameNotFoundException("Could not find client: " + jwtAuth.getClientId());
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
throw new AuthenticationServiceException("Invalid JWT format");
|
||||
}
|
||||
}
|
||||
} catch (ClientNotFoundException e) {
|
||||
throw new UsernameNotFoundException("Could not find client: " + jwtAuth.getClientId());
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
throw new AuthenticationServiceException("Invalid JWT format");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* We support {@link JwtBearerAssertionAuthenticationToken}s only.
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(Class<?> authentication) {
|
||||
return (JwtBearerAssertionAuthenticationToken.class.isAssignableFrom(authentication));
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public boolean supports(Class<?> authentication) {
|
||||
return (JwtBearerAssertionAuthenticationToken.class.isAssignableFrom(authentication));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,72 +28,72 @@ import com.nimbusds.jwt.JWTParser;
|
|||
public class JwtBearerClientAssertionTokenEndpointFilter extends ClientCredentialsTokenEndpointFilter {
|
||||
|
||||
public JwtBearerClientAssertionTokenEndpointFilter() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public JwtBearerClientAssertionTokenEndpointFilter(String path) {
|
||||
super(path);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
super(path);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
/**
|
||||
* Pull the assertion out of the request and send it up to the auth manager for processing.
|
||||
*/
|
||||
@Override
|
||||
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
|
||||
*/
|
||||
@Override
|
||||
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException, IOException, ServletException {
|
||||
|
||||
// check for appropriate parameters
|
||||
String assertionType = request.getParameter("client_assertion_type");
|
||||
String assertion = request.getParameter("client_assertion");
|
||||
// check for appropriate parameters
|
||||
String assertionType = request.getParameter("client_assertion_type");
|
||||
String assertion = request.getParameter("client_assertion");
|
||||
|
||||
try {
|
||||
JWT jwt = JWTParser.parse(assertion);
|
||||
try {
|
||||
JWT jwt = JWTParser.parse(assertion);
|
||||
|
||||
String clientId = jwt.getJWTClaimsSet().getSubject();
|
||||
String clientId = jwt.getJWTClaimsSet().getSubject();
|
||||
|
||||
Authentication authRequest = new JwtBearerAssertionAuthenticationToken(clientId, jwt);
|
||||
Authentication authRequest = new JwtBearerAssertionAuthenticationToken(clientId, jwt);
|
||||
|
||||
return this.getAuthenticationManager().authenticate(authRequest);
|
||||
} catch (ParseException e) {
|
||||
throw new BadCredentialsException("Invalid JWT credential: " + assertion);
|
||||
}
|
||||
}
|
||||
return this.getAuthenticationManager().authenticate(authRequest);
|
||||
} catch (ParseException e) {
|
||||
throw new BadCredentialsException("Invalid JWT credential: " + assertion);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the "client_assertion_type" and "client_assertion" parameters are present and contain the right values.
|
||||
*/
|
||||
@Override
|
||||
protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) {
|
||||
// check for appropriate parameters
|
||||
String assertionType = request.getParameter("client_assertion_type");
|
||||
String assertion = request.getParameter("client_assertion");
|
||||
*/
|
||||
@Override
|
||||
protected boolean requiresAuthentication(HttpServletRequest request, HttpServletResponse response) {
|
||||
// check for appropriate parameters
|
||||
String assertionType = request.getParameter("client_assertion_type");
|
||||
String assertion = request.getParameter("client_assertion");
|
||||
|
||||
if (Strings.isNullOrEmpty(assertionType) || Strings.isNullOrEmpty(assertion)) {
|
||||
return false;
|
||||
} else if (!assertionType.equals("urn:ietf:params:oauth:client-assertion-type:jwt-bearer")) {
|
||||
return false;
|
||||
}
|
||||
if (Strings.isNullOrEmpty(assertionType) || Strings.isNullOrEmpty(assertion)) {
|
||||
return false;
|
||||
} else if (!assertionType.equals("urn:ietf:params:oauth:client-assertion-type:jwt-bearer")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Can't call to superclass here b/c client creds would break for lack of client_id
|
||||
// return super.requiresAuthentication(request, response);
|
||||
// Can't call to superclass here b/c client creds would break for lack of client_id
|
||||
// return super.requiresAuthentication(request, response);
|
||||
|
||||
String uri = request.getRequestURI();
|
||||
int pathParamIndex = uri.indexOf(';');
|
||||
String uri = request.getRequestURI();
|
||||
int pathParamIndex = uri.indexOf(';');
|
||||
|
||||
if (pathParamIndex > 0) {
|
||||
// strip everything after the first semi-colon
|
||||
uri = uri.substring(0, pathParamIndex);
|
||||
}
|
||||
if (pathParamIndex > 0) {
|
||||
// strip everything after the first semi-colon
|
||||
uri = uri.substring(0, pathParamIndex);
|
||||
}
|
||||
|
||||
if ("".equals(request.getContextPath())) {
|
||||
return uri.endsWith(getFilterProcessesUrl());
|
||||
}
|
||||
if ("".equals(request.getContextPath())) {
|
||||
return uri.endsWith(getFilterProcessesUrl());
|
||||
}
|
||||
|
||||
return uri.endsWith(request.getContextPath() + getFilterProcessesUrl());
|
||||
return uri.endsWith(request.getContextPath() + getFilterProcessesUrl());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -5,23 +5,23 @@ public class UserNotFoundException extends RuntimeException {
|
|||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public UserNotFoundException() {
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
super();
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public UserNotFoundException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
super(message, cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public UserNotFoundException(String message) {
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
super(message);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
public UserNotFoundException(Throwable cause) {
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
super(cause);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import javax.persistence.TypedQuery;
|
|||
|
||||
import org.mitre.openid.connect.model.ApprovedSite;
|
||||
import org.mitre.openid.connect.repository.ApprovedSiteRepository;
|
||||
import org.mitre.util.jpa.JpaUtil;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
@ -83,22 +82,22 @@ public class JpaApprovedSiteRepository implements ApprovedSiteRepository {
|
|||
return query.getResultList();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ApprovedSite> getByUserId(String userId) {
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ApprovedSite> getByUserId(String userId) {
|
||||
TypedQuery<ApprovedSite> query = manager.createNamedQuery("ApprovedSite.getByUserId", ApprovedSite.class);
|
||||
query.setParameter("userId", userId);
|
||||
|
||||
return query.getResultList();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ApprovedSite> getByClientId(String clientId) {
|
||||
@Override
|
||||
@Transactional
|
||||
public Collection<ApprovedSite> getByClientId(String clientId) {
|
||||
TypedQuery<ApprovedSite> query = manager.createNamedQuery("ApprovedSite.getByClientId", ApprovedSite.class);
|
||||
query.setParameter("clientId", clientId);
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class JpaEventRepository implements EventRepository {
|
|||
query = query.setParameter("start", start, TemporalType.DATE);
|
||||
query = query.setParameter("end", end, TemporalType.DATE);
|
||||
query = query.setFirstResult(startChunk);
|
||||
query = query.setMaxResults(chunkSize);
|
||||
query = query.setMaxResults(chunkSize);
|
||||
|
||||
return query.getResultList();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import javax.persistence.EntityManager;
|
|||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.TypedQuery;
|
||||
|
||||
import org.mitre.openid.connect.model.ApprovedSite;
|
||||
import org.mitre.openid.connect.model.Nonce;
|
||||
import org.mitre.openid.connect.repository.NonceRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
|
|
@ -15,8 +15,8 @@
|
|||
******************************************************************************/
|
||||
package org.mitre.openid.connect.repository.impl;
|
||||
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
import static org.mitre.util.jpa.JpaUtil.getSingleResult;
|
||||
import static org.mitre.util.jpa.JpaUtil.saveOrUpdate;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
|
@ -40,10 +40,10 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
public class JpaUserInfoRepository implements UserInfoRepository {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager manager;
|
||||
private EntityManager manager;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@Transactional
|
||||
public UserInfo getBySubject(String sub) {
|
||||
TypedQuery<DefaultUserInfo> query = manager.createNamedQuery("DefaultUserInfo.getBySubject", DefaultUserInfo.class);
|
||||
query.setParameter("sub", sub);
|
||||
|
@ -84,12 +84,12 @@ public class JpaUserInfoRepository implements UserInfoRepository {
|
|||
* Get a single UserInfo object by its username
|
||||
*/
|
||||
@Override
|
||||
public UserInfo getByUsername(String username) {
|
||||
public UserInfo getByUsername(String username) {
|
||||
TypedQuery<DefaultUserInfo> query = manager.createNamedQuery("DefaultUserInfo.getByUsername", DefaultUserInfo.class);
|
||||
query.setParameter("username", username);
|
||||
|
||||
return getSingleResult(query.getResultList());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,11 +53,11 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for use in test harnesses.
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
/**
|
||||
* Constructor for use in test harnesses.
|
||||
*
|
||||
* @param repository
|
||||
*/
|
||||
public DefaultApprovedSiteService(ApprovedSiteRepository approvedSiteRepository) {
|
||||
this.approvedSiteRepository = approvedSiteRepository;
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
|
|||
@Override
|
||||
@Transactional
|
||||
public ApprovedSite createApprovedSite(String clientId, String userId, Date timeoutDate, Set<String> allowedScopes,
|
||||
WhitelistedSite whitelistedSite) {
|
||||
WhitelistedSite whitelistedSite) {
|
||||
|
||||
ApprovedSite as = approvedSiteRepository.save(new ApprovedSite());
|
||||
|
||||
|
@ -123,34 +123,34 @@ public class DefaultApprovedSiteService implements ApprovedSiteService {
|
|||
}
|
||||
|
||||
/**
|
||||
* @param userId
|
||||
* @return
|
||||
* @see org.mitre.openid.connect.repository.ApprovedSiteRepository#getByUserId(java.lang.String)
|
||||
*/
|
||||
* @param userId
|
||||
* @return
|
||||
* @see org.mitre.openid.connect.repository.ApprovedSiteRepository#getByUserId(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Collection<ApprovedSite> getByUserId(String userId) {
|
||||
return approvedSiteRepository.getByUserId(userId);
|
||||
}
|
||||
public Collection<ApprovedSite> getByUserId(String userId) {
|
||||
return approvedSiteRepository.getByUserId(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clientId
|
||||
* @return
|
||||
* @see org.mitre.openid.connect.repository.ApprovedSiteRepository#getByClientId(java.lang.String)
|
||||
*/
|
||||
* @param clientId
|
||||
* @return
|
||||
* @see org.mitre.openid.connect.repository.ApprovedSiteRepository#getByClientId(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Collection<ApprovedSite> getByClientId(String clientId) {
|
||||
return approvedSiteRepository.getByClientId(clientId);
|
||||
}
|
||||
public Collection<ApprovedSite> getByClientId(String clientId) {
|
||||
return approvedSiteRepository.getByClientId(clientId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void clearApprovedSitesForClient(ClientDetails client) {
|
||||
Collection<ApprovedSite> approvedSites = approvedSiteRepository.getByClientId(client.getClientId());
|
||||
Collection<ApprovedSite> approvedSites = approvedSiteRepository.getByClientId(client.getClientId());
|
||||
if (approvedSites != null) {
|
||||
for (ApprovedSite approvedSite : approvedSites) {
|
||||
approvedSiteRepository.remove(approvedSite);
|
||||
}
|
||||
approvedSiteRepository.remove(approvedSite);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -80,10 +80,10 @@ public class DefaultBlacklistedSiteService implements BlacklistedSiteService {
|
|||
// TODO: rewrite this to do regex matching and use the Guava predicates collection
|
||||
|
||||
for (BlacklistedSite blacklistedSite : sites) {
|
||||
if (Strings.nullToEmpty(blacklistedSite.getUri()).equals(uri)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (Strings.nullToEmpty(blacklistedSite.getUri()).equals(uri)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ public class DefaultNonceService implements NonceService, InitializingBean {
|
|||
/**
|
||||
* Make sure that the nonce storage duration was set
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if (nonceStorageDuration == null) {
|
||||
logger.error("Nonce storage duration must be set!");
|
||||
|
|
|
@ -26,24 +26,24 @@ public class DefaultStatsService implements StatsService {
|
|||
private ApprovedSiteService approvedSiteService;
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> calculateSummaryStats() {
|
||||
// get all approved sites
|
||||
Collection<ApprovedSite> allSites = approvedSiteService.getAll();
|
||||
public Map<String, Integer> calculateSummaryStats() {
|
||||
// get all approved sites
|
||||
Collection<ApprovedSite> allSites = approvedSiteService.getAll();
|
||||
|
||||
// process to find number of unique users and sites
|
||||
Set<String> userIds = new HashSet<String>();
|
||||
Set<String> clientIds = new HashSet<String>();
|
||||
for (ApprovedSite approvedSite : allSites) {
|
||||
userIds.add(approvedSite.getUserId());
|
||||
clientIds.add(approvedSite.getClientId());
|
||||
}
|
||||
// process to find number of unique users and sites
|
||||
Set<String> userIds = new HashSet<String>();
|
||||
Set<String> clientIds = new HashSet<String>();
|
||||
for (ApprovedSite approvedSite : allSites) {
|
||||
userIds.add(approvedSite.getUserId());
|
||||
clientIds.add(approvedSite.getClientId());
|
||||
}
|
||||
|
||||
Map<String, Integer> e = new HashMap<String, Integer>();
|
||||
Map<String, Integer> e = new HashMap<String, Integer>();
|
||||
|
||||
e.put("approvalCount", allSites.size());
|
||||
e.put("userCount", userIds.size());
|
||||
e.put("clientCount", clientIds.size());
|
||||
return e;
|
||||
}
|
||||
e.put("approvalCount", allSites.size());
|
||||
e.put("userCount", userIds.size());
|
||||
e.put("clientCount", clientIds.size());
|
||||
return e;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -72,17 +72,17 @@ public class DefaultUserInfoService implements UserInfoService {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the userInfoRepository
|
||||
*/
|
||||
public UserInfoRepository getUserInfoRepository() {
|
||||
return userInfoRepository;
|
||||
}
|
||||
* @return the userInfoRepository
|
||||
*/
|
||||
public UserInfoRepository getUserInfoRepository() {
|
||||
return userInfoRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param userInfoRepository the userInfoRepository to set
|
||||
*/
|
||||
public void setUserInfoRepository(UserInfoRepository userInfoRepository) {
|
||||
this.userInfoRepository = userInfoRepository;
|
||||
}
|
||||
* @param userInfoRepository the userInfoRepository to set
|
||||
*/
|
||||
public void setUserInfoRepository(UserInfoRepository userInfoRepository) {
|
||||
this.userInfoRepository = userInfoRepository;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,10 +26,10 @@ public class DefaultUserInfoUserDetailsService implements UserDetailsService {
|
|||
@Autowired
|
||||
UserInfoRepository repository;
|
||||
|
||||
public static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
|
||||
public static final GrantedAuthority ROLE_ADMIN = new SimpleGrantedAuthority("ROLE_ADMIN");
|
||||
public static final GrantedAuthority ROLE_USER = new SimpleGrantedAuthority("ROLE_USER");
|
||||
public static final GrantedAuthority ROLE_ADMIN = new SimpleGrantedAuthority("ROLE_ADMIN");
|
||||
|
||||
private List<String> admins = new ArrayList<String>();
|
||||
private List<String> admins = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
|
||||
|
@ -40,14 +40,14 @@ public class DefaultUserInfoUserDetailsService implements UserDetailsService {
|
|||
// TODO: make passwords configurable? part of object?
|
||||
String password = "password";
|
||||
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(ROLE_USER);
|
||||
List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
|
||||
authorities.add(ROLE_USER);
|
||||
|
||||
if (admins != null && admins.contains(username)) {
|
||||
authorities.add(ROLE_ADMIN);
|
||||
}
|
||||
if (admins != null && admins.contains(username)) {
|
||||
authorities.add(ROLE_ADMIN);
|
||||
}
|
||||
|
||||
// TODO: this should really be our own UserDetails wrapper class, shouldn't it?
|
||||
// TODO: this should really be our own UserDetails wrapper class, shouldn't it?
|
||||
User user = new User(userInfo.getSub(), password, authorities);
|
||||
return user;
|
||||
} else {
|
||||
|
@ -56,17 +56,17 @@ public class DefaultUserInfoUserDetailsService implements UserDetailsService {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the admins
|
||||
*/
|
||||
public List<String> getAdmins() {
|
||||
return admins;
|
||||
}
|
||||
* @return the admins
|
||||
*/
|
||||
public List<String> getAdmins() {
|
||||
return admins;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param admins the admins to set
|
||||
*/
|
||||
public void setAdmins(List<String> admins) {
|
||||
this.admins = admins;
|
||||
}
|
||||
* @param admins the admins to set
|
||||
*/
|
||||
public void setAdmins(List<String> admins) {
|
||||
this.admins = admins;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -86,12 +86,12 @@ public class DefaultWhitelistedSiteService implements WhitelistedSiteService {
|
|||
return repository.getByCreator(creatorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite) {
|
||||
if (oldWhitelistedSite == null || whitelistedSite == null) {
|
||||
throw new IllegalArgumentException("Neither the old or new sites may be null");
|
||||
}
|
||||
return repository.update(oldWhitelistedSite, whitelistedSite);
|
||||
}
|
||||
@Override
|
||||
public WhitelistedSite update(WhitelistedSite oldWhitelistedSite, WhitelistedSite whitelistedSite) {
|
||||
if (oldWhitelistedSite == null || whitelistedSite == null) {
|
||||
throw new IllegalArgumentException("Neither the old or new sites may be null");
|
||||
}
|
||||
return repository.update(oldWhitelistedSite, whitelistedSite);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -83,9 +83,9 @@ public class ConnectTokenEnhancer implements TokenEnhancer {
|
|||
|
||||
SignedJWT signed = new SignedJWT(new JWSHeader(jwtService.getDefaultSigningAlgorithm()), claims);
|
||||
|
||||
jwtService.signJwt(signed);
|
||||
jwtService.signJwt(signed);
|
||||
|
||||
token.setJwt(signed);
|
||||
token.setJwt(signed);
|
||||
|
||||
/**
|
||||
* Authorization request scope MUST include "openid" in OIDC, but access token request
|
||||
|
|
|
@ -122,7 +122,7 @@ public class TofuUserApprovalHandler implements UserApprovalHandler {
|
|||
alreadyApproved = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!alreadyApproved) {
|
||||
WhitelistedSite ws = whitelistedSiteService.getByClientId(clientId);
|
||||
|
@ -141,7 +141,7 @@ public class TofuUserApprovalHandler implements UserApprovalHandler {
|
|||
|
||||
|
||||
@Override
|
||||
public AuthorizationRequest updateAfterApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
|
||||
public AuthorizationRequest updateAfterApproval(AuthorizationRequest authorizationRequest, Authentication userAuthentication) {
|
||||
|
||||
String userId = userAuthentication.getName();
|
||||
String clientId = authorizationRequest.getClientId();
|
||||
|
@ -198,7 +198,7 @@ public class TofuUserApprovalHandler implements UserApprovalHandler {
|
|||
}
|
||||
|
||||
return authorizationRequest;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the requested scope set is a proper subset of the allowed scopes.
|
||||
|
|
|
@ -17,11 +17,9 @@ import org.mitre.jose.JWSAlgorithmEmbed;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
|
@ -43,71 +41,72 @@ public abstract class AbstractClientEntityView extends AbstractView {
|
|||
private static Logger logger = LoggerFactory.getLogger(ClientEntityViewForAdmins.class);
|
||||
|
||||
private Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(getExclusionStrategy())
|
||||
.registerTypeAdapter(JWSAlgorithmEmbed.class, new JsonSerializer<JWSAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JsonElement serialize(JWSAlgorithmEmbed src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src != null) {
|
||||
return new JsonPrimitive(src.getAlgorithmName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEAlgorithmEmbed.class, new JsonSerializer<JWEAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JsonElement serialize(JWEAlgorithmEmbed src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src != null) {
|
||||
return new JsonPrimitive(src.getAlgorithmName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEEncryptionMethodEmbed.class, new JsonSerializer<JWEEncryptionMethodEmbed>() {
|
||||
@Override
|
||||
public JsonElement serialize(JWEEncryptionMethodEmbed src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src != null) {
|
||||
return new JsonPrimitive(src.getAlgorithmName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
.setExclusionStrategies(getExclusionStrategy())
|
||||
.registerTypeAdapter(JWSAlgorithmEmbed.class, new JsonSerializer<JWSAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JsonElement serialize(JWSAlgorithmEmbed src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src != null) {
|
||||
return new JsonPrimitive(src.getAlgorithmName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEAlgorithmEmbed.class, new JsonSerializer<JWEAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JsonElement serialize(JWEAlgorithmEmbed src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src != null) {
|
||||
return new JsonPrimitive(src.getAlgorithmName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEEncryptionMethodEmbed.class, new JsonSerializer<JWEEncryptionMethodEmbed>() {
|
||||
@Override
|
||||
public JsonElement serialize(JWEEncryptionMethodEmbed src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
if (src != null) {
|
||||
return new JsonPrimitive(src.getAlgorithmName());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
protected abstract ExclusionStrategy getExclusionStrategy();
|
||||
protected abstract ExclusionStrategy getExclusionStrategy();
|
||||
|
||||
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
response.setContentType("application/json");
|
||||
response.setContentType("application/json");
|
||||
|
||||
|
||||
HttpStatus code = (HttpStatus) model.get("code");
|
||||
if (code == null) {
|
||||
code = HttpStatus.OK; // default to 200
|
||||
}
|
||||
HttpStatus code = (HttpStatus) model.get("code");
|
||||
if (code == null) {
|
||||
code = HttpStatus.OK; // default to 200
|
||||
}
|
||||
|
||||
response.setStatus(code.value());
|
||||
response.setStatus(code.value());
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
gson.toJson(obj, out);
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
gson.toJson(obj, out);
|
||||
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
|
||||
logger.error("IOException in JsonEntityView.java: ", e);
|
||||
logger.error("IOException in JsonEntityView.java: ", e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,34 +3,14 @@
|
|||
*/
|
||||
package org.mitre.openid.connect.view;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.mitre.jose.JWEAlgorithmEmbed;
|
||||
import org.mitre.jose.JWEEncryptionMethodEmbed;
|
||||
import org.mitre.jose.JWSAlgorithmEmbed;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -48,25 +28,28 @@ public class ClientEntityViewForAdmins extends AbstractClientEntityView {
|
|||
/**
|
||||
* @return
|
||||
*/
|
||||
protected ExclusionStrategy getExclusionStrategy() {
|
||||
return new ExclusionStrategy() {
|
||||
@Override
|
||||
protected ExclusionStrategy getExclusionStrategy() {
|
||||
return new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
if (blacklistedFields.contains(f.getName())) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
if (blacklistedFields.contains(f.getName())) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,34 +3,14 @@
|
|||
*/
|
||||
package org.mitre.openid.connect.view;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.mitre.jose.JWEAlgorithmEmbed;
|
||||
import org.mitre.jose.JWEEncryptionMethodEmbed;
|
||||
import org.mitre.jose.JWSAlgorithmEmbed;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.BeanPropertyBindingResult;
|
||||
import org.springframework.web.servlet.view.AbstractView;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.gson.ExclusionStrategy;
|
||||
import com.google.gson.FieldAttributes;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -49,28 +29,30 @@ public class ClientEntityViewForUsers extends AbstractClientEntityView {
|
|||
/* (non-Javadoc)
|
||||
* @see org.mitre.openid.connect.view.AbstractClientEntityView#getExclusionStrategy()
|
||||
*/
|
||||
@Override
|
||||
protected ExclusionStrategy getExclusionStrategy() {
|
||||
return new ExclusionStrategy() {
|
||||
@Override
|
||||
protected ExclusionStrategy getExclusionStrategy() {
|
||||
return new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
// whitelist the handful of fields that are good
|
||||
if (whitelistedFields.contains(f.getName())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
// whitelist the handful of fields that are good
|
||||
if (whitelistedFields.contains(f.getName())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -106,15 +106,15 @@ public class ClientInformationResponseView extends AbstractView {
|
|||
o.add("request_uris", getAsArray(c.getRequestUris()));
|
||||
|
||||
try {
|
||||
Writer out = response.getWriter();
|
||||
gson.toJson(o, out);
|
||||
} catch (JsonIOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
Writer out = response.getWriter();
|
||||
gson.toJson(o, out);
|
||||
} catch (JsonIOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ public class JSONUserInfoView extends AbstractView {
|
|||
/* (non-Javadoc)
|
||||
* @see org.springframework.web.servlet.view.AbstractView#renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
UserInfo userInfo = (UserInfo) model.get("userInfo");
|
||||
|
@ -62,22 +63,24 @@ public class JSONUserInfoView extends AbstractView {
|
|||
Set<String> scope = (Set<String>) model.get("scope");
|
||||
|
||||
Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}).create();
|
||||
}).create();
|
||||
|
||||
response.setContentType("application/json");
|
||||
|
||||
|
@ -90,23 +93,23 @@ public class JSONUserInfoView extends AbstractView {
|
|||
if (model.get("requestObject") != null) {
|
||||
|
||||
try {
|
||||
String jwtString = (String)model.get("requestObject");
|
||||
JWT requestObject = JWTParser.parse(jwtString);
|
||||
String jwtString = (String)model.get("requestObject");
|
||||
JWT requestObject = JWTParser.parse(jwtString);
|
||||
|
||||
// FIXME: move to GSON for easier processing
|
||||
JsonObject obj = (JsonObject) new JsonParser().parse(requestObject.getJWTClaimsSet().toJSONObject().toJSONString());
|
||||
// FIXME: move to GSON for easier processing
|
||||
JsonObject obj = (JsonObject) new JsonParser().parse(requestObject.getJWTClaimsSet().toJSONObject().toJSONString());
|
||||
|
||||
gson.toJson(toJsonFromRequestObj(userInfo, scope, obj), out);
|
||||
} catch (JsonSyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (JsonIOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
gson.toJson(toJsonFromRequestObj(userInfo, scope, obj), out);
|
||||
} catch (JsonSyntaxException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (JsonIOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
|
|
|
@ -38,35 +38,38 @@ public class JsonApprovedSiteView extends AbstractView {
|
|||
private static Logger logger = LoggerFactory.getLogger(JsonApprovedSiteView.class);
|
||||
|
||||
private Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
})
|
||||
.registerTypeAdapter(OAuth2AccessTokenEntity.class, new JsonSerializer<OAuth2AccessTokenEntity>() {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(OAuth2AccessTokenEntity src,
|
||||
Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getId());
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
})
|
||||
.registerTypeAdapter(OAuth2AccessTokenEntity.class, new JsonSerializer<OAuth2AccessTokenEntity>() {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(OAuth2AccessTokenEntity src,
|
||||
Type typeOfSrc, JsonSerializationContext context) {
|
||||
return new JsonPrimitive(src.getId());
|
||||
}
|
||||
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
response.setContentType("application/json");
|
||||
|
@ -83,7 +86,7 @@ public class JsonApprovedSiteView extends AbstractView {
|
|||
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
gson.toJson(obj, out);
|
||||
gson.toJson(obj, out);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
|
@ -91,6 +94,6 @@ public class JsonApprovedSiteView extends AbstractView {
|
|||
logger.error("IOException in JsonEntityView.java: ", e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,26 +32,29 @@ public class JsonEntityView extends AbstractView {
|
|||
private static Logger logger = LoggerFactory.getLogger(JsonEntityView.class);
|
||||
|
||||
private Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
response.setContentType("application/json");
|
||||
|
@ -68,7 +71,7 @@ public class JsonEntityView extends AbstractView {
|
|||
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
gson.toJson(obj, out);
|
||||
gson.toJson(obj, out);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
|
@ -76,6 +79,6 @@ public class JsonEntityView extends AbstractView {
|
|||
logger.error("IOException in JsonEntityView.java: ", e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,26 +30,29 @@ public class JsonErrorView extends AbstractView {
|
|||
private static Logger logger = LoggerFactory.getLogger(JsonEntityView.class);
|
||||
|
||||
private Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
})
|
||||
.serializeNulls()
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
response.setContentType("application/json");
|
||||
|
@ -69,7 +72,7 @@ public class JsonErrorView extends AbstractView {
|
|||
String errorMessage = (String) model.get("errorMessage");
|
||||
JsonObject obj = new JsonObject();
|
||||
obj.addProperty("error_message", errorMessage);
|
||||
gson.toJson(obj, out);
|
||||
gson.toJson(obj, out);
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
|
@ -77,6 +80,6 @@ public class JsonErrorView extends AbstractView {
|
|||
logger.error("IOException in JsonErrorView.java: ", e);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ public class POCOUserInfoView extends AbstractView {
|
|||
/* (non-Javadoc)
|
||||
* @see org.springframework.web.servlet.view.AbstractView#renderMergedOutputModel(java.util.Map, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
|
||||
*/
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
UserInfo userInfo = (UserInfo) model.get("userInfo");
|
||||
|
@ -52,22 +53,24 @@ public class POCOUserInfoView extends AbstractView {
|
|||
Set<String> scope = (Set<String>) model.get("scope");
|
||||
|
||||
Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}).create();
|
||||
}).create();
|
||||
|
||||
response.setContentType("application/json");
|
||||
|
||||
|
|
|
@ -28,42 +28,44 @@ public class StatsSummary extends AbstractView {
|
|||
|
||||
@Override
|
||||
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request, HttpServletResponse response) {
|
||||
Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
Gson gson = new GsonBuilder()
|
||||
.setExclusionStrategies(new ExclusionStrategy() {
|
||||
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
@Override
|
||||
public boolean shouldSkipField(FieldAttributes f) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean shouldSkipClass(Class<?> clazz) {
|
||||
// skip the JPA binding wrapper
|
||||
if (clazz.equals(BeanPropertyBindingResult.class)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}).create();
|
||||
}).create();
|
||||
|
||||
response.setContentType("application/json");
|
||||
response.setContentType("application/json");
|
||||
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
if (obj == null) {
|
||||
obj = model;
|
||||
}
|
||||
Writer out = response.getWriter();
|
||||
Object obj = model.get("entity");
|
||||
if (obj == null) {
|
||||
obj = model;
|
||||
}
|
||||
|
||||
gson.toJson(obj, out);
|
||||
gson.toJson(obj, out);
|
||||
|
||||
} catch (IOException e) {
|
||||
} catch (IOException e) {
|
||||
|
||||
logger.error("IOException in JSONClientView.java: ", e);
|
||||
logger.error("IOException in JSONClientView.java: ", e);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -58,111 +58,111 @@ import com.google.gson.JsonSyntaxException;
|
|||
@PreAuthorize("hasRole('ROLE_USER')")
|
||||
public class ClientAPI {
|
||||
|
||||
@Autowired
|
||||
private ClientDetailsEntityService clientService;
|
||||
@Autowired
|
||||
private ClientDetailsEntityService clientService;
|
||||
private JsonParser parser = new JsonParser();
|
||||
|
||||
private Gson gson = new GsonBuilder()
|
||||
.serializeNulls()
|
||||
.registerTypeAdapter(JWSAlgorithmEmbed.class, new JsonDeserializer<JWSAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JWSAlgorithmEmbed deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return JWSAlgorithmEmbed.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEAlgorithmEmbed.class, new JsonDeserializer<JWEAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JWEAlgorithmEmbed deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return JWEAlgorithmEmbed.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEEncryptionMethodEmbed.class, new JsonDeserializer<JWEEncryptionMethodEmbed>() {
|
||||
@Override
|
||||
public JWEEncryptionMethodEmbed deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return JWEEncryptionMethodEmbed.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
.serializeNulls()
|
||||
.registerTypeAdapter(JWSAlgorithmEmbed.class, new JsonDeserializer<JWSAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JWSAlgorithmEmbed deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return JWSAlgorithmEmbed.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEAlgorithmEmbed.class, new JsonDeserializer<JWEAlgorithmEmbed>() {
|
||||
@Override
|
||||
public JWEAlgorithmEmbed deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return JWEAlgorithmEmbed.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.registerTypeAdapter(JWEEncryptionMethodEmbed.class, new JsonDeserializer<JWEEncryptionMethodEmbed>() {
|
||||
@Override
|
||||
public JWEEncryptionMethodEmbed deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
if (json.isJsonPrimitive()) {
|
||||
return JWEEncryptionMethodEmbed.getForAlgorithmName(json.getAsString());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
})
|
||||
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
|
||||
.create();
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ClientAPI.class);
|
||||
|
||||
/**
|
||||
* Get a list of all clients
|
||||
* @param modelAndView
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
|
||||
public String apiGetAllClients(Model model, Authentication auth) {
|
||||
/**
|
||||
* Get a list of all clients
|
||||
* @param modelAndView
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(method = RequestMethod.GET, produces = "application/json")
|
||||
public String apiGetAllClients(Model model, Authentication auth) {
|
||||
|
||||
Collection<ClientDetailsEntity> clients = clientService.getAllClients();
|
||||
model.addAttribute("entity", clients);
|
||||
Collection<ClientDetailsEntity> clients = clientService.getAllClients();
|
||||
model.addAttribute("entity", clients);
|
||||
|
||||
if (isAdmin(auth)) {
|
||||
return "clientEntityViewAdmins";
|
||||
} else {
|
||||
return "clientEntityViewUsers";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new client
|
||||
* @param json
|
||||
* @param m
|
||||
* @param principal
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||
public String apiAddClient(@RequestBody String jsonString, Model m, Authentication auth) {
|
||||
/**
|
||||
* Create a new client
|
||||
* @param json
|
||||
* @param m
|
||||
* @param principal
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json")
|
||||
public String apiAddClient(@RequestBody String jsonString, Model m, Authentication auth) {
|
||||
|
||||
JsonObject json = null;
|
||||
ClientDetailsEntity client = null;
|
||||
JsonObject json = null;
|
||||
ClientDetailsEntity client = null;
|
||||
|
||||
try {
|
||||
json = parser.parse(jsonString).getAsJsonObject();
|
||||
client = gson.fromJson(json, ClientDetailsEntity.class);
|
||||
}
|
||||
catch (JsonSyntaxException e) {
|
||||
logger.error("apiAddClient failed due to JsonSyntaxException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not save new client. The server encountered a JSON syntax exception. Contact a system administrator for assistance.");
|
||||
try {
|
||||
json = parser.parse(jsonString).getAsJsonObject();
|
||||
client = gson.fromJson(json, ClientDetailsEntity.class);
|
||||
}
|
||||
catch (JsonSyntaxException e) {
|
||||
logger.error("apiAddClient failed due to JsonSyntaxException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not save new client. The server encountered a JSON syntax exception. Contact a system administrator for assistance.");
|
||||
return "jsonErrorView";
|
||||
} catch (IllegalStateException e) {
|
||||
logger.error("apiAddClient failed due to IllegalStateException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not save new client. The server encountered an IllegalStateException. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
|
||||
} catch (IllegalStateException e) {
|
||||
logger.error("apiAddClient failed due to IllegalStateException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not save new client. The server encountered an IllegalStateException. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
|
||||
return "jsonErrorView";
|
||||
}
|
||||
|
||||
// if they leave the client secret empty, force it to be generated
|
||||
if (Strings.isNullOrEmpty(client.getClientId())) {
|
||||
client = clientService.generateClientId(client);
|
||||
}
|
||||
// if they leave the client secret empty, force it to be generated
|
||||
if (Strings.isNullOrEmpty(client.getClientId())) {
|
||||
client = clientService.generateClientId(client);
|
||||
}
|
||||
|
||||
// if they've asked for us to generate a client secret, do so here
|
||||
if (json.has("generateClientSecret") && json.get("generateClientSecret").getAsBoolean()) {
|
||||
client = clientService.generateClientSecret(client);
|
||||
}
|
||||
// if they've asked for us to generate a client secret, do so here
|
||||
if (json.has("generateClientSecret") && json.get("generateClientSecret").getAsBoolean()) {
|
||||
client = clientService.generateClientSecret(client);
|
||||
}
|
||||
|
||||
// set owners as current logged in user
|
||||
//client.setOwner(principal.getName());
|
||||
//TODO: owner has been replaced by a list of contacts, which should be styled as email addresses.
|
||||
client.setDynamicallyRegistered(false);
|
||||
// set owners as current logged in user
|
||||
//client.setOwner(principal.getName());
|
||||
//TODO: owner has been replaced by a list of contacts, which should be styled as email addresses.
|
||||
client.setDynamicallyRegistered(false);
|
||||
|
||||
ClientDetailsEntity newClient = clientService.saveNewClient(client);
|
||||
ClientDetailsEntity newClient = clientService.saveNewClient(client);
|
||||
m.addAttribute("entity", newClient);
|
||||
|
||||
if (isAdmin(auth)) {
|
||||
|
@ -170,64 +170,64 @@ public class ClientAPI {
|
|||
} else {
|
||||
return "clientEntityViewUsers";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing client
|
||||
* @param id
|
||||
* @param jsonString
|
||||
* @param m
|
||||
* @param principal
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@RequestMapping(value="/{id}", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json")
|
||||
public String apiUpdateClient(@PathVariable("id") Long id, @RequestBody String jsonString, Model m, Authentication auth) {
|
||||
/**
|
||||
* Update an existing client
|
||||
* @param id
|
||||
* @param jsonString
|
||||
* @param m
|
||||
* @param principal
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@RequestMapping(value="/{id}", method = RequestMethod.PUT, consumes = "application/json", produces = "application/json")
|
||||
public String apiUpdateClient(@PathVariable("id") Long id, @RequestBody String jsonString, Model m, Authentication auth) {
|
||||
|
||||
JsonObject json = null;
|
||||
ClientDetailsEntity client = null;
|
||||
JsonObject json = null;
|
||||
ClientDetailsEntity client = null;
|
||||
|
||||
try {
|
||||
// parse the client passed in (from JSON) and fetch the old client from the store
|
||||
json = parser.parse(jsonString).getAsJsonObject();
|
||||
client = gson.fromJson(json, ClientDetailsEntity.class);
|
||||
}
|
||||
catch (JsonSyntaxException e) {
|
||||
logger.error("apiUpdateClient failed due to JsonSyntaxException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not update client. The server encountered a JSON syntax exception. Contact a system administrator for assistance.");
|
||||
try {
|
||||
// parse the client passed in (from JSON) and fetch the old client from the store
|
||||
json = parser.parse(jsonString).getAsJsonObject();
|
||||
client = gson.fromJson(json, ClientDetailsEntity.class);
|
||||
}
|
||||
catch (JsonSyntaxException e) {
|
||||
logger.error("apiUpdateClient failed due to JsonSyntaxException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not update client. The server encountered a JSON syntax exception. Contact a system administrator for assistance.");
|
||||
return "jsonErrorView";
|
||||
} catch (IllegalStateException e) {
|
||||
logger.error("apiUpdateClient failed due to IllegalStateException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not update client. The server encountered an IllegalStateException. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
|
||||
} catch (IllegalStateException e) {
|
||||
logger.error("apiUpdateClient failed due to IllegalStateException: " , e);
|
||||
m.addAttribute("code", HttpStatus.BAD_REQUEST);
|
||||
m.addAttribute("errorMessage", "Could not update client. The server encountered an IllegalStateException. Refresh and try again - if the problem persists, contact a system administrator for assistance.");
|
||||
return "jsonErrorView";
|
||||
}
|
||||
|
||||
ClientDetailsEntity oldClient = clientService.getClientById(id);
|
||||
ClientDetailsEntity oldClient = clientService.getClientById(id);
|
||||
|
||||
if (oldClient == null) {
|
||||
logger.error("apiUpdateClient failed; client with id " + id + " could not be found.");
|
||||
m.addAttribute("code", HttpStatus.NOT_FOUND);
|
||||
m.addAttribute("errorMessage", "Could not update client. The requested client with id " + id + "could not be found.");
|
||||
if (oldClient == null) {
|
||||
logger.error("apiUpdateClient failed; client with id " + id + " could not be found.");
|
||||
m.addAttribute("code", HttpStatus.NOT_FOUND);
|
||||
m.addAttribute("errorMessage", "Could not update client. The requested client with id " + id + "could not be found.");
|
||||
return "jsonErrorView";
|
||||
}
|
||||
}
|
||||
|
||||
// if they leave the client secret empty, force it to be generated
|
||||
if (Strings.isNullOrEmpty(client.getClientId())) {
|
||||
client = clientService.generateClientId(client);
|
||||
}
|
||||
// if they leave the client secret empty, force it to be generated
|
||||
if (Strings.isNullOrEmpty(client.getClientId())) {
|
||||
client = clientService.generateClientId(client);
|
||||
}
|
||||
|
||||
// if they've asked for us to generate a client secret, do so here
|
||||
if (json.has("generateClientSecret") && json.get("generateClientSecret").getAsBoolean()) {
|
||||
client = clientService.generateClientSecret(client);
|
||||
}
|
||||
// if they've asked for us to generate a client secret, do so here
|
||||
if (json.has("generateClientSecret") && json.get("generateClientSecret").getAsBoolean()) {
|
||||
client = clientService.generateClientSecret(client);
|
||||
}
|
||||
|
||||
// set owners as current logged in user
|
||||
// client.setOwner(principal.getName());
|
||||
//TODO: owner has been replaced by a list of contacts, which should be styled as email addresses.
|
||||
// set owners as current logged in user
|
||||
// client.setOwner(principal.getName());
|
||||
//TODO: owner has been replaced by a list of contacts, which should be styled as email addresses.
|
||||
|
||||
ClientDetailsEntity newClient = clientService.updateClient(oldClient, client);
|
||||
ClientDetailsEntity newClient = clientService.updateClient(oldClient, client);
|
||||
m.addAttribute("entity", newClient);
|
||||
|
||||
if (isAdmin(auth)) {
|
||||
|
@ -235,19 +235,19 @@ public class ClientAPI {
|
|||
} else {
|
||||
return "clientEntityViewUsers";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a client
|
||||
* @param id
|
||||
* @param modelAndView
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
|
||||
public String apiDeleteClient(@PathVariable("id") Long id, ModelAndView modelAndView) {
|
||||
/**
|
||||
* Delete a client
|
||||
* @param id
|
||||
* @param modelAndView
|
||||
* @return
|
||||
*/
|
||||
@PreAuthorize("hasRole('ROLE_ADMIN')")
|
||||
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
|
||||
public String apiDeleteClient(@PathVariable("id") Long id, ModelAndView modelAndView) {
|
||||
|
||||
ClientDetailsEntity client = clientService.getClientById(id);
|
||||
ClientDetailsEntity client = clientService.getClientById(id);
|
||||
|
||||
if (client == null) {
|
||||
logger.error("apiDeleteClient failed; client with id " + id + " could not be found.");
|
||||
|
@ -260,47 +260,47 @@ public class ClientAPI {
|
|||
}
|
||||
|
||||
return "httpCodeView";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get an individual client
|
||||
* @param id
|
||||
* @param modelAndView
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/{id}", method=RequestMethod.GET, produces = "application/json")
|
||||
public String apiShowClient(@PathVariable("id") Long id, Model model, Authentication auth) {
|
||||
/**
|
||||
* Get an individual client
|
||||
* @param id
|
||||
* @param modelAndView
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/{id}", method=RequestMethod.GET, produces = "application/json")
|
||||
public String apiShowClient(@PathVariable("id") Long id, Model model, Authentication auth) {
|
||||
|
||||
ClientDetailsEntity client = clientService.getClientById(id);
|
||||
ClientDetailsEntity client = clientService.getClientById(id);
|
||||
|
||||
if (client == null) {
|
||||
logger.error("apiShowClient failed; client with id " + id + " could not be found.");
|
||||
model.addAttribute("code", HttpStatus.NOT_FOUND);
|
||||
model.addAttribute("errorMessage", "The requested client with id " + id + "could not be found.");
|
||||
if (client == null) {
|
||||
logger.error("apiShowClient failed; client with id " + id + " could not be found.");
|
||||
model.addAttribute("code", HttpStatus.NOT_FOUND);
|
||||
model.addAttribute("errorMessage", "The requested client with id " + id + "could not be found.");
|
||||
return "jsonErrorView";
|
||||
}
|
||||
}
|
||||
|
||||
model.addAttribute("entity", client);
|
||||
model.addAttribute("entity", client);
|
||||
|
||||
if (isAdmin(auth)) {
|
||||
if (isAdmin(auth)) {
|
||||
return "clientEntityViewAdmins";
|
||||
} else {
|
||||
return "clientEntityViewUsers";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the given auth object has ROLE_ADMIN assigned to it or not
|
||||
* @param auth
|
||||
* @return
|
||||
*/
|
||||
private boolean isAdmin(Authentication auth) {
|
||||
for (GrantedAuthority grantedAuthority : auth.getAuthorities()) {
|
||||
if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Check to see if the given auth object has ROLE_ADMIN assigned to it or not
|
||||
* @param auth
|
||||
* @return
|
||||
*/
|
||||
private boolean isAdmin(Authentication auth) {
|
||||
for (GrantedAuthority grantedAuthority : auth.getAuthorities()) {
|
||||
if (grantedAuthority.getAuthority().equals("ROLE_ADMIN")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -314,7 +314,7 @@ public class ClientDynamicRegistrationEndpoint {
|
|||
* @param jsonString
|
||||
* @return the entity if successful, null otherwise
|
||||
*/
|
||||
private ClientDetailsEntity parse(String jsonString) {
|
||||
private ClientDetailsEntity parse(String jsonString) {
|
||||
JsonElement jsonEl = parser.parse(jsonString);
|
||||
if (jsonEl.isJsonObject()) {
|
||||
|
||||
|
@ -393,89 +393,89 @@ public class ClientDynamicRegistrationEndpoint {
|
|||
|
||||
return c;
|
||||
} else {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the given given member as a set of strings, null if it doesn't exist
|
||||
*/
|
||||
private Set<String> getAsStringSet(JsonObject o, String member) throws JsonSyntaxException {
|
||||
if (o.has(member)) {
|
||||
return gson.fromJson(o.get(member), new TypeToken<Set<String>>(){}.getType());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private Set<String> getAsStringSet(JsonObject o, String member) throws JsonSyntaxException {
|
||||
if (o.has(member)) {
|
||||
return gson.fromJson(o.get(member), new TypeToken<Set<String>>(){}.getType());
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the given member as a string, null if it doesn't exist
|
||||
*/
|
||||
private String getAsString(JsonObject o, String member) {
|
||||
if (o.has(member)) {
|
||||
JsonElement e = o.get(member);
|
||||
if (e != null && e.isJsonPrimitive()) {
|
||||
return e.getAsString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the given member as a JWS Algorithm, null if it doesn't exist
|
||||
*/
|
||||
private JWSAlgorithmEmbed getAsJwsAlgorithm(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return JWSAlgorithmEmbed.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the given member as a JWE Algorithm, null if it doesn't exist
|
||||
*/
|
||||
private JWEAlgorithmEmbed getAsJweAlgorithm(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return JWEAlgorithmEmbed.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value of the given member as a JWE Encryption Method, null if it doesn't exist
|
||||
*/
|
||||
private JWEEncryptionMethodEmbed getAsJweEncryptionMethod(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return JWEEncryptionMethodEmbed.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param client
|
||||
* @return
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
private OAuth2AccessTokenEntity createRegistrationAccessToken(ClientDetailsEntity client) throws AuthenticationException {
|
||||
* Gets the value of the given member as a string, null if it doesn't exist
|
||||
*/
|
||||
private String getAsString(JsonObject o, String member) {
|
||||
if (o.has(member)) {
|
||||
JsonElement e = o.get(member);
|
||||
if (e != null && e.isJsonPrimitive()) {
|
||||
return e.getAsString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> authorizationParameters = Maps.newHashMap();
|
||||
authorizationParameters.put("client_id", client.getClientId());
|
||||
authorizationParameters.put("scope", OAuth2AccessTokenEntity.REGISTRATION_TOKEN_SCOPE);
|
||||
OAuth2Request storedRequest = new OAuth2Request(authorizationParameters, client.getClientId(),
|
||||
Sets.newHashSet(new SimpleGrantedAuthority("ROLE_CLIENT")), true,
|
||||
Sets.newHashSet(OAuth2AccessTokenEntity.REGISTRATION_TOKEN_SCOPE), null, null, null);
|
||||
/**
|
||||
* Gets the value of the given member as a JWS Algorithm, null if it doesn't exist
|
||||
*/
|
||||
private JWSAlgorithmEmbed getAsJwsAlgorithm(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return JWSAlgorithmEmbed.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the given member as a JWE Algorithm, null if it doesn't exist
|
||||
*/
|
||||
private JWEAlgorithmEmbed getAsJweAlgorithm(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return JWEAlgorithmEmbed.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the value of the given member as a JWE Encryption Method, null if it doesn't exist
|
||||
*/
|
||||
private JWEEncryptionMethodEmbed getAsJweEncryptionMethod(JsonObject o, String member) {
|
||||
String s = getAsString(o, member);
|
||||
if (s != null) {
|
||||
return JWEEncryptionMethodEmbed.getForAlgorithmName(s);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param client
|
||||
* @return
|
||||
* @throws AuthenticationException
|
||||
*/
|
||||
private OAuth2AccessTokenEntity createRegistrationAccessToken(ClientDetailsEntity client) throws AuthenticationException {
|
||||
|
||||
Map<String, String> authorizationParameters = Maps.newHashMap();
|
||||
authorizationParameters.put("client_id", client.getClientId());
|
||||
authorizationParameters.put("scope", OAuth2AccessTokenEntity.REGISTRATION_TOKEN_SCOPE);
|
||||
OAuth2Request storedRequest = new OAuth2Request(authorizationParameters, client.getClientId(),
|
||||
Sets.newHashSet(new SimpleGrantedAuthority("ROLE_CLIENT")), true,
|
||||
Sets.newHashSet(OAuth2AccessTokenEntity.REGISTRATION_TOKEN_SCOPE), null, null, null);
|
||||
OAuth2Authentication authentication = new OAuth2Authentication(storedRequest, null);
|
||||
OAuth2AccessTokenEntity registrationAccessToken = (OAuth2AccessTokenEntity) tokenService.createAccessToken(authentication);
|
||||
return registrationAccessToken;
|
||||
}
|
||||
return registrationAccessToken;
|
||||
}
|
||||
|
||||
}
|
|
@ -45,17 +45,17 @@ public class JsonWebKeyEndpoint {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the jwtService
|
||||
*/
|
||||
public JwtSigningAndValidationService getJwtService() {
|
||||
return jwtService;
|
||||
}
|
||||
* @return the jwtService
|
||||
*/
|
||||
public JwtSigningAndValidationService getJwtService() {
|
||||
return jwtService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param jwtService the jwtService to set
|
||||
*/
|
||||
public void setJwtService(JwtSigningAndValidationService jwtService) {
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
* @param jwtService the jwtService to set
|
||||
*/
|
||||
public void setJwtService(JwtSigningAndValidationService jwtService) {
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ package org.mitre.openid.connect.web;
|
|||
|
||||
import java.util.Map;
|
||||
|
||||
import org.mitre.openid.connect.config.ConfigurationPropertiesBean;
|
||||
import org.mitre.openid.connect.service.StatsService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
|
@ -35,41 +34,41 @@ public class ManagerController {
|
|||
@Autowired
|
||||
private StatsService statsService;
|
||||
|
||||
@RequestMapping({"", "home", "index"})
|
||||
public String showHomePage(ModelMap m) {
|
||||
@RequestMapping({"", "home", "index"})
|
||||
public String showHomePage(ModelMap m) {
|
||||
|
||||
Map<String, Integer> summary = statsService.calculateSummaryStats();
|
||||
Map<String, Integer> summary = statsService.calculateSummaryStats();
|
||||
|
||||
m.put("statsSummary", summary);
|
||||
return "home";
|
||||
}
|
||||
m.put("statsSummary", summary);
|
||||
return "home";
|
||||
}
|
||||
|
||||
@RequestMapping({"about", "about/"})
|
||||
public String showAboutPage(ModelMap m) {
|
||||
@RequestMapping({"about", "about/"})
|
||||
public String showAboutPage(ModelMap m) {
|
||||
|
||||
return "about";
|
||||
}
|
||||
return "about";
|
||||
}
|
||||
|
||||
@RequestMapping({"stats", "stats/"})
|
||||
public String showStatsPage(ModelMap m) {
|
||||
@RequestMapping({"stats", "stats/"})
|
||||
public String showStatsPage(ModelMap m) {
|
||||
|
||||
Map<String, Integer> summary = statsService.calculateSummaryStats();
|
||||
Map<String, Integer> summary = statsService.calculateSummaryStats();
|
||||
|
||||
m.put("statsSummary", summary);
|
||||
return "stats";
|
||||
}
|
||||
m.put("statsSummary", summary);
|
||||
return "stats";
|
||||
}
|
||||
|
||||
@RequestMapping({"contact", "contact/"})
|
||||
public String showContactPage(ModelMap m) {
|
||||
@RequestMapping({"contact", "contact/"})
|
||||
public String showContactPage(ModelMap m) {
|
||||
|
||||
return "contact";
|
||||
}
|
||||
return "contact";
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('ROLE_USER')") // TODO: this probably shouldn't be here
|
||||
@RequestMapping("manage/**")
|
||||
public String showClientManager(ModelMap m) {
|
||||
return "manage";
|
||||
}
|
||||
@PreAuthorize("hasRole('ROLE_USER')") // TODO: this probably shouldn't be here
|
||||
@RequestMapping("manage/**")
|
||||
public String showClientManager(ModelMap m) {
|
||||
return "manage";
|
||||
}
|
||||
|
||||
public StatsService getStatsService() {
|
||||
return statsService;
|
||||
|
|
|
@ -23,11 +23,11 @@ public class ServerConfigInterceptor extends HandlerInterceptorAdapter {
|
|||
@Autowired
|
||||
private ConfigurationPropertiesBean config;
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
if (modelAndView != null) { // skip checking at all if we have no model and view to hand the config to
|
||||
modelAndView.addObject("config", config);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
if (modelAndView != null) { // skip checking at all if we have no model and view to hand the config to
|
||||
modelAndView.addObject("config", config);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class UserInfoEndpoint {
|
|||
private Map<String, String> schemaToViewNameMap = ImmutableMap.of(
|
||||
openIdSchema, jsonUserInfoViewName,
|
||||
pocoSchema, pocoUserInfoViewName
|
||||
);
|
||||
);
|
||||
|
||||
// Valid schemas and associated views
|
||||
private static final String openIdSchema = "openid";
|
||||
|
@ -96,11 +96,11 @@ public class UserInfoEndpoint {
|
|||
}
|
||||
|
||||
if (p instanceof OAuth2Authentication) {
|
||||
OAuth2Authentication authentication = (OAuth2Authentication)p;
|
||||
OAuth2Authentication authentication = (OAuth2Authentication)p;
|
||||
|
||||
model.addAttribute("scope", authentication.getOAuth2Request().getScope());
|
||||
model.addAttribute("requestObject", authentication.getOAuth2Request().getRequestParameters().get("request"));
|
||||
}
|
||||
model.addAttribute("scope", authentication.getOAuth2Request().getScope());
|
||||
model.addAttribute("requestObject", authentication.getOAuth2Request().getRequestParameters().get("request"));
|
||||
}
|
||||
|
||||
model.addAttribute("userInfo", userInfo);
|
||||
|
||||
|
@ -109,17 +109,17 @@ public class UserInfoEndpoint {
|
|||
}
|
||||
|
||||
/**
|
||||
* @return the schemaToViewNameMap (defaults to an immutable map)
|
||||
*/
|
||||
public Map<String, String> getSchemaToViewNameMap() {
|
||||
return schemaToViewNameMap;
|
||||
}
|
||||
* @return the schemaToViewNameMap (defaults to an immutable map)
|
||||
*/
|
||||
public Map<String, String> getSchemaToViewNameMap() {
|
||||
return schemaToViewNameMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param schemaToViewNameMap the schemaToViewNameMap to set
|
||||
*/
|
||||
public void setSchemaToViewNameMap(Map<String, String> schemaToViewNameMap) {
|
||||
this.schemaToViewNameMap = schemaToViewNameMap;
|
||||
}
|
||||
* @param schemaToViewNameMap the schemaToViewNameMap to set
|
||||
*/
|
||||
public void setSchemaToViewNameMap(Map<String, String> schemaToViewNameMap) {
|
||||
this.schemaToViewNameMap = schemaToViewNameMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.mitre.openid.connect.model.UserInfo;
|
||||
import org.mitre.openid.connect.repository.UserInfoRepository;
|
||||
import org.mitre.openid.connect.service.UserInfoService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
@ -26,26 +25,26 @@ public class UserInfoInterceptor extends HandlerInterceptorAdapter {
|
|||
@Autowired
|
||||
private UserInfoService userInfoService;
|
||||
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
@Override
|
||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
|
||||
|
||||
if (modelAndView != null) { // skip checking at all if we have no model and view to hand the user to
|
||||
// get our principal from the security context
|
||||
Principal p = request.getUserPrincipal();
|
||||
if (modelAndView != null) { // skip checking at all if we have no model and view to hand the user to
|
||||
// get our principal from the security context
|
||||
Principal p = request.getUserPrincipal();
|
||||
|
||||
if (p != null && p.getName() != null) { // don't bother checking if we don't have a principal
|
||||
if (p != null && p.getName() != null) { // don't bother checking if we don't have a principal
|
||||
|
||||
// try to look up a user based on it
|
||||
UserInfo user = userInfoService.getBySubject(p.getName());
|
||||
// try to look up a user based on it
|
||||
UserInfo user = userInfoService.getBySubject(p.getName());
|
||||
|
||||
// if we have one, inject it so views can use it
|
||||
if (user != null) {
|
||||
modelAndView.addObject("userInfo", user);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if we have one, inject it so views can use it
|
||||
if (user != null) {
|
||||
modelAndView.addObject("userInfo", user);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
<h2>About</h2>
|
||||
<p>This OpenID Connect service is built from the MITREid Connect
|
||||
Open Source project started by The MITRE Corporation.</p>
|
||||
<p>
|
||||
This OpenID Connect service is built from the MITREid Connect Open Source project started by The MITRE Corporation.
|
||||
</p>
|
||||
<p>
|
||||
More information about the project can be found on our GitHub page: <a href="http://github.com/mitreid-connect/">MTIREid Connect on GitHub</a>
|
||||
There, you can submit bug reports, give feedback, or even contribute code patches for additional features you'd like to see.
|
||||
More information about the project can be found on our GitHub page: <a
|
||||
href="http://github.com/mitreid-connect/">MTIREid Connect on
|
||||
GitHub</a> There, you can submit bug reports, give feedback, or even
|
||||
contribute code patches for additional features you'd like to see.
|
||||
</p>
|
|
@ -1,12 +1,13 @@
|
|||
<%@ tag language="java" pageEncoding="UTF-8"%>
|
||||
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
|
||||
<%@ taglib prefix="security"
|
||||
uri="http://www.springframework.org/security/tags"%>
|
||||
<security:authorize access="hasRole('ROLE_ADMIN')">
|
||||
<li class="nav-header">Administrative</li>
|
||||
<li><a href="manage/#admin/clients">Manage Clients</a></li>
|
||||
<li><a href="manage/#admin/whitelists">Whitelisted Clients</a></li>
|
||||
<li><a href="manage/#admin/blacklist">Blacklisted Clients</a></li>
|
||||
<li><a href="manage/#admin/scope">System Scopes</a></li>
|
||||
<li class="divider"></li>
|
||||
<li class="nav-header">Administrative</li>
|
||||
<li><a href="manage/#admin/clients">Manage Clients</a></li>
|
||||
<li><a href="manage/#admin/whitelists">Whitelisted Clients</a></li>
|
||||
<li><a href="manage/#admin/blacklist">Blacklisted Clients</a></li>
|
||||
<li><a href="manage/#admin/scope">System Scopes</a></li>
|
||||
<li class="divider"></li>
|
||||
</security:authorize>
|
||||
<li class="nav-header">Personal</li>
|
||||
<li><a href="manage/#user/approved">Manage Sites</a></li>
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
<%@attribute name="crumb" required="false" %>
|
||||
<%@attribute name="crumb" required="false"%>
|
||||
<div id="breadcrumbs"></div>
|
|
@ -1,6 +1,9 @@
|
|||
<h2>Contact</h2>
|
||||
<p>
|
||||
For general assistance, email Bob at <a href="mailto:email@address.com?Subject=OIDC%20Server%20Assistance">email@address.com</a>.
|
||||
To offer feedback, email Sue at <a href="mailto:email@address.com?Subject=OIDC%20Server%20Feedback">email@address.com</a>.
|
||||
To report a system failure or bug report, email Joe at <a href="mailto:email@address.com?Subject=OIDC%20Server%20Failure">email@address.com</a>.
|
||||
For general assistance, email Bob at <a
|
||||
href="mailto:email@address.com?Subject=OIDC%20Server%20Assistance">email@address.com</a>.
|
||||
To offer feedback, email Sue at <a
|
||||
href="mailto:email@address.com?Subject=OIDC%20Server%20Feedback">email@address.com</a>.
|
||||
To report a system failure or bug report, email Joe at <a
|
||||
href="mailto:email@address.com?Subject=OIDC%20Server%20Failure">email@address.com</a>.
|
||||
</p>
|
||||
|
|
|
@ -1 +1,3 @@
|
|||
Powered by <a href="https://github.com/mitreid-connect/">MITREid Connect</a> © 2013 The MITRE Corporation.
|
||||
Powered by
|
||||
<a href="https://github.com/mitreid-connect/">MITREid Connect</a>
|
||||
© 2013 The MITRE Corporation.
|
||||
|
|
|
@ -1,28 +1,33 @@
|
|||
<%@attribute name="js" required="false" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@ taglib prefix="o" tagdir="/WEB-INF/tags" %>
|
||||
<%@attribute name="js" required="false"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<%@ taglib prefix="o" tagdir="/WEB-INF/tags"%>
|
||||
<div id="push"></div>
|
||||
</div> <!-- end #wrap -->
|
||||
</div>
|
||||
<!-- end #wrap -->
|
||||
<div id="footer">
|
||||
<div class="container">
|
||||
<p class="muted credit"><o:copyright /></p>
|
||||
</div>
|
||||
<div class="container">
|
||||
<p class="muted credit">
|
||||
<o:copyright />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- Le javascript
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
<script type="text/javascript" src="resources/bootstrap2/js/bootstrap.js"></script>
|
||||
<script type="text/javascript"
|
||||
src="resources/bootstrap2/js/bootstrap.js"></script>
|
||||
<script type="text/javascript" src="resources/js/lib/underscore.js"></script>
|
||||
<script type="text/javascript" src="resources/js/lib/backbone.js"></script>
|
||||
<script type="text/javascript" src="resources/js/lib/purl.js"></script>
|
||||
<script type="text/javascript" src="resources/js/lib/bootstrapx-clickover.js"></script>
|
||||
<script type="text/javascript"
|
||||
src="resources/js/lib/bootstrapx-clickover.js"></script>
|
||||
<c:if test="${js != null && js != ''}">
|
||||
<script type="text/javascript" src="resources/js/client.js"></script>
|
||||
<script type="text/javascript" src="resources/js/grant.js"></script>
|
||||
<script type="text/javascript" src="resources/js/scope.js"></script>
|
||||
<script type="text/javascript" src="resources/js/whitelist.js"></script>
|
||||
<script type="text/javascript" src="resources/js/admin.js"></script>
|
||||
<script type="text/javascript" src="resources/js/client.js"></script>
|
||||
<script type="text/javascript" src="resources/js/grant.js"></script>
|
||||
<script type="text/javascript" src="resources/js/scope.js"></script>
|
||||
<script type="text/javascript" src="resources/js/whitelist.js"></script>
|
||||
<script type="text/javascript" src="resources/js/admin.js"></script>
|
||||
</c:if>
|
||||
</body>
|
||||
</html>
|
|
@ -1,119 +1,123 @@
|
|||
<%@attribute name="title" required="false" %>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
||||
<%@attribute name="title" required="false"%>
|
||||
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
||||
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
|
||||
<c:set var="url">${pageContext.request.requestURL}</c:set>
|
||||
<base href="${fn:substring(url, 0, fn:length(url) - fn:length(pageContext.request.requestURI))}${pageContext.request.contextPath}/" />
|
||||
<c:set var="url">${pageContext.request.requestURL}</c:set>
|
||||
<base
|
||||
href="${fn:substring(url, 0, fn:length(url) - fn:length(pageContext.request.requestURI))}${pageContext.request.contextPath}/" />
|
||||
|
||||
<meta charset="utf-8">
|
||||
<title>OpenID Connect - ${title}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
<meta charset="utf-8">
|
||||
<title>OpenID Connect - ${title}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="">
|
||||
<meta name="author" content="">
|
||||
|
||||
<!-- Le styles -->
|
||||
<link href="resources/bootstrap2/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style type="text/css">
|
||||
<!-- Le styles -->
|
||||
<link href="resources/bootstrap2/css/bootstrap.min.css" rel="stylesheet">
|
||||
<style type="text/css">
|
||||
html,body {
|
||||
height: 100%;
|
||||
/* The html and body elements cannot have any padding or margin. */
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
/* The html and body elements cannot have any padding or margin. */
|
||||
}
|
||||
.sidebar-nav {
|
||||
padding: 9px 0;
|
||||
}
|
||||
|
||||
.sidebar-nav {
|
||||
padding: 9px 0;
|
||||
}
|
||||
h1,label {
|
||||
text-shadow: 1px 1px 1px #FFFFFF;
|
||||
}
|
||||
|
||||
h1,label {
|
||||
text-shadow: 1px 1px 1px #FFFFFF;
|
||||
}
|
||||
.brand {
|
||||
padding-left: 35px !important;
|
||||
}
|
||||
|
||||
.brand {
|
||||
padding-left: 35px !important;
|
||||
}
|
||||
/* Wrapper for page content to push down footer */
|
||||
#wrap {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
/* Negative indent footer by it's height */
|
||||
margin: 0 auto -60px;
|
||||
}
|
||||
|
||||
/* Wrapper for page content to push down footer */
|
||||
#wrap {
|
||||
min-height: 100%;
|
||||
height: auto !important;
|
||||
height: 100%;
|
||||
/* Negative indent footer by it's height */
|
||||
margin: 0 auto -60px;
|
||||
}
|
||||
/* Set the fixed height of the footer here */
|
||||
#push,#footer {
|
||||
min-height: 60px;
|
||||
}
|
||||
|
||||
/* Set the fixed height of the footer here */
|
||||
#push,
|
||||
#footer {
|
||||
min-height: 60px;
|
||||
}
|
||||
#footer {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
#footer {
|
||||
background-color: #f5f5f5;
|
||||
}
|
||||
|
||||
.main {
|
||||
padding-top: 60px;
|
||||
}
|
||||
.main {
|
||||
padding-top: 60px;
|
||||
}
|
||||
|
||||
.credit {
|
||||
margin: 20px 0;
|
||||
}
|
||||
.credit {
|
||||
margin: 20px 0;
|
||||
}
|
||||
|
||||
.inputError {
|
||||
border: 1px solid #b94a48 !important;
|
||||
}
|
||||
.inputError {
|
||||
border: 1px solid #b94a48 !important;
|
||||
}
|
||||
|
||||
a.brand {
|
||||
background: url('${config.logoImageUrl}') no-repeat scroll 7px 7px transparent;
|
||||
}
|
||||
</style>
|
||||
<link href="resources/bootstrap2/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<style type="text/css">
|
||||
@media (min-width: 768px) and (max-width: 979px) {
|
||||
.main {
|
||||
padding-top: 0px;
|
||||
}
|
||||
a.brand {
|
||||
background: url('${config.logoImageUrl}') no-repeat scroll 7px 7px
|
||||
transparent;
|
||||
}
|
||||
</style>
|
||||
<link href="resources/bootstrap2/css/bootstrap-responsive.css"
|
||||
rel="stylesheet">
|
||||
<style type="text/css">
|
||||
@media ( min-width : 768px) and (max-width: 979px) {
|
||||
.main {
|
||||
padding-top: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@media ( max-width : 767px) {
|
||||
#footer {
|
||||
margin-left: -20px;
|
||||
margin-right: -20px;
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
@media (max-width: 767px) {
|
||||
#footer {
|
||||
margin-left: -20px;
|
||||
margin-right: -20px;
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<!-- Le fav and touch icons -->
|
||||
<link rel="shortcut icon" href="../bootstrap2/ico/favicon.ico">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="../bootstrap2/ico/apple-touch-icon-114-precomposed.png">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="../bootstrap2/ico/apple-touch-icon-72-precomposed.png">
|
||||
<link rel="apple-touch-icon-precomposed" href="../bootstrap2/ico/apple-touch-icon-57-precomposed.png">
|
||||
<!-- Le fav and touch icons -->
|
||||
<link rel="shortcut icon" href="../bootstrap2/ico/favicon.ico">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="114x114"
|
||||
href="../bootstrap2/ico/apple-touch-icon-114-precomposed.png">
|
||||
<link rel="apple-touch-icon-precomposed" sizes="72x72"
|
||||
href="../bootstrap2/ico/apple-touch-icon-72-precomposed.png">
|
||||
<link rel="apple-touch-icon-precomposed"
|
||||
href="../bootstrap2/ico/apple-touch-icon-57-precomposed.png">
|
||||
|
||||
<!-- Load jQuery up here so that we can use in-page functions -->
|
||||
<script type="text/javascript" src="resources/js/lib/jquery.js"></script>
|
||||
<!-- Load jQuery up here so that we can use in-page functions -->
|
||||
<script type="text/javascript" src="resources/js/lib/jquery.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
<div id="modalAlert" class="modal hide fade">
|
||||
<div class="alert alert-error">
|
||||
<strong>Warning!</strong>
|
||||
<div class="modal-body"></div>
|
||||
<div id="modalAlert" class="modal hide fade">
|
||||
<div class="alert alert-error">
|
||||
<strong>Warning!</strong>
|
||||
<div class="modal-body"></div>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button class="btn primary" type="button"
|
||||
onclick="$('#modalAlert').modal('hide');">OK</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer"><button class="btn primary" type="button" onclick="$('#modalAlert').modal('hide');">OK</button></div>
|
||||
</div>
|
||||
|
||||
<div id="wrap">
|
||||
<div id="wrap">
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue