@ -7,12 +7,11 @@ import static de.srsoftware.tools.Strings.uuid;
@@ -7,12 +7,11 @@ import static de.srsoftware.tools.Strings.uuid;
import static de.srsoftware.umbrella.core.ConnectionProvider.connect ;
import static de.srsoftware.umbrella.core.Constants.* ;
import static de.srsoftware.umbrella.core.Constants.CODE ;
import static de.srsoftware.umbrella.core.Paths.LIST ;
import static de.srsoftware.umbrella.core.Paths.LOGOUT ;
import static de.srsoftware.umbrella.core.Constants.TOKEN ;
import static de.srsoftware.umbrella.core.Paths.* ;
import static de.srsoftware.umbrella.core.ResponseCode.* ;
import static de.srsoftware.umbrella.core.ResponseCode.HTTP_SERVER_ERROR ;
import static de.srsoftware.umbrella.core.Util.open ;
import static de.srsoftware.umbrella.core.Util.request ;
import static de.srsoftware.umbrella.core.Util.* ;
import static de.srsoftware.umbrella.core.exceptions.UmbrellaException.* ;
import static de.srsoftware.umbrella.user.Constants.* ;
import static de.srsoftware.umbrella.user.Paths.* ;
@ -257,6 +256,7 @@ public class UserModule extends BaseHandler implements UserService {
@@ -257,6 +256,7 @@ public class UserModule extends BaseHandler implements UserService {
case OIDC - > postOIDC ( ex , path ) ;
case IMPERSONATE - > impersonate ( ex , targetId ) ;
case LOGIN - > postLogin ( ex ) ;
case SEARCH - > postSearch ( ex ) ;
case RESET_PW - > postResetPassword ( ex ) ;
case null , default - > super . doPost ( path , ex ) ;
} ;
@ -449,6 +449,17 @@ public class UserModule extends BaseHandler implements UserService {
@@ -449,6 +449,17 @@ public class UserModule extends BaseHandler implements UserService {
}
}
private boolean patchService ( HttpExchange ex , String serviceName , UmbrellaUser requestingUser ) throws IOException , UmbrellaException {
if ( ! ( requestingUser instanceof DbUser user & & user . permissions ( ) . contains ( MANAGE_LOGIN_SERVICES ) ) ) throw forbidden ( "You are not allowed to manage that service!" ) ;
var json = json ( ex ) ;
if ( ! json . has ( NAME ) | | ! ( json . get ( NAME ) instanceof String name ) | | name . isBlank ( ) ) throw missingFieldException ( NAME ) ;
if ( ! json . has ( URL ) | | ! ( json . get ( URL ) instanceof String url ) | | url . isBlank ( ) ) throw missingFieldException ( URL ) ;
if ( ! json . has ( CLIENT_ID ) | | ! ( json . get ( CLIENT_ID ) instanceof String clientId ) | | clientId . isBlank ( ) ) throw missingFieldException ( CLIENT_ID ) ;
if ( ! json . has ( CLIENT_SECRET ) | | ! ( json . get ( CLIENT_SECRET ) instanceof String secret ) | | secret . isBlank ( ) ) throw missingFieldException ( CLIENT_SECRET ) ;
var service = logins . save ( new LoginService ( name , url , clientId , secret , DEFAULT_FIELD ) ) ;
return sendContent ( ex , service . toMap ( ) ) ;
}
@Override
public PostBox postBox ( ) {
return messages ;
@ -496,17 +507,6 @@ public class UserModule extends BaseHandler implements UserService {
@@ -496,17 +507,6 @@ public class UserModule extends BaseHandler implements UserService {
return ok ( ex ) ;
}
private boolean patchService ( HttpExchange ex , String serviceName , UmbrellaUser requestingUser ) throws IOException , UmbrellaException {
if ( ! ( requestingUser instanceof DbUser user & & user . permissions ( ) . contains ( MANAGE_LOGIN_SERVICES ) ) ) throw forbidden ( "You are not allowed to manage that service!" ) ;
var json = json ( ex ) ;
if ( ! json . has ( NAME ) | | ! ( json . get ( NAME ) instanceof String name ) | | name . isBlank ( ) ) throw missingFieldException ( NAME ) ;
if ( ! json . has ( URL ) | | ! ( json . get ( URL ) instanceof String url ) | | url . isBlank ( ) ) throw missingFieldException ( URL ) ;
if ( ! json . has ( CLIENT_ID ) | | ! ( json . get ( CLIENT_ID ) instanceof String clientId ) | | clientId . isBlank ( ) ) throw missingFieldException ( CLIENT_ID ) ;
if ( ! json . has ( CLIENT_SECRET ) | | ! ( json . get ( CLIENT_SECRET ) instanceof String secret ) | | secret . isBlank ( ) ) throw missingFieldException ( CLIENT_SECRET ) ;
var service = logins . save ( new LoginService ( name , url , clientId , secret , DEFAULT_FIELD ) ) ;
return sendContent ( ex , service . toMap ( ) ) ;
}
private boolean postLogin ( HttpExchange ex ) throws IOException {
var json = json ( ex ) ;
if ( ! ( json . has ( USERNAME ) & & json . get ( USERNAME ) instanceof String username ) ) return sendContent ( ex , HTTP_UNPROCESSABLE , "Username missing" ) ;
@ -522,7 +522,12 @@ public class UserModule extends BaseHandler implements UserService {
@@ -522,7 +522,12 @@ public class UserModule extends BaseHandler implements UserService {
}
}
private boolean postSearch ( HttpExchange ex ) throws IOException {
var requestingUser = loadUser ( ex ) ;
if ( ! ( requestingUser . isPresent ( ) & & requestingUser . get ( ) instanceof DbUser dbUser ) ) return unauthorized ( ex ) ;
var key = body ( ex ) ;
return sendContent ( ex , mapValues ( users . search ( key ) ) ) ;
}
static int score ( String password ) {
if ( password = = null ) return 0 ;